• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua I need support with NPC's

therrax

Member
Joined
Jul 12, 2012
Messages
262
Solutions
1
Reaction score
11
Hello again :p
How to remove a yellow reply?
(NPC answer ONLY in NPC's channel)
Look:

untitled11.jpg
 
Last edited:
Change selfSay(...) to npcHandler:say(...).
If that dosen't work post then / send them to me via a pm and ill take a look, npcs aren't my best side tbh.
 
Look:
NPC
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Lola" script="furniture.lua" walkinterval="2000" floorchange="0">
    <health now="150" max="150"/>
    <look type="269" head="114" body="76" legs="77" feet="114" addons="3" corpse="2212"/>
    <interaction range="2" idletime="30"/>
    <parameters>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I sell chairs, tables, plants, containers, pillows, tapestries and more. Everything for 500 gold pieces, just {trade}."/>
        <parameter key="shop_buyable" value="wooden chair,3901,500;sofa chair,3902,500;red cushioned chair,3903,500;green cushioned chair,3904,500;tusk chair,3905,500;ivory chair,3906,500;water-pipe,3907,500;coal basin,3908,500;big table,3909,500;square table,3910,500;round table,3911,500;small table,3912,500;stone table,3913,500;tusk table,3914,500;chest,3915,500;barrel,3916,500;harp,3917,500;bird cage,3918,500;bamboo table,3919,500;bamboo drawer,3920,500;drawer,3921,500;exotic flower,3922,500;potted flower,3923,500;flower bowl,3924,500;chest,3925,500;piano,3926,500;globe,3927,500;rocking chair,3928,500;indoor plant,3929,500;crate,3930,500;christmas tree,3931,500;dresser,3932,500;pendelum clock,3933,500;locker,3934,500;trough,3935,500;time table,3936,500;table lamp,3937,500;bookcase,3938,500;box,5086,500;box2,5087,500;barrel2,5088,500;big flowerpot,6114,500;large amphora,6115,500;tree stump,6372,500;mirror,6373,500;large trunk,7503,500;goldfish bowl,7700,500;tree stump2,7960,500;cuckoo clock,7961,500;telescope,7962,500;furnace,8692,500;blue tapestry,1872,500;green tapestry,1860,500;orange tapestry,1866,500;pink tapestry,1857,500;red tapestry,1869,500;white tapestry,1880,500;yellow tapestry,1863,500;small purple pillow,1678,500;small green pillow,1679,500;small red pillow,1680,500;small blue pillow,1681,500;small orange pillow,1683,500;small turquiose pillow,1684,500;small white pillow,1685,500;heart pillow,1685,500;blue pillow,1686,500;red pillow,1687,500;green pillow,1688,500;yellow pillow,1689,500;round blue pillow,1690,500;round red pillow,1691,500;round purple pillow,1692,500;round turquiose pillow,1693,500;oval mirror,1845,750;round mirror,1848,750;edged mirror,1851,750;green bed,7904,1000;red bed,7905,1000;yellow bed,7906,1000;bed removal,7907,1000;wooden stake,5941,10000;" />
    </parameters>
</npc>
furniture.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)             end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)             end
function onCreatureSay(cid, type, msg)             npcHandler:onCreatureSay(cid, type, msg)         end
function onThink()                     npcHandler:onThink()                     end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'chairs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell wooden, sofa, red cushioned, green cushioned, tusk and ivory chairs.'})
keywordHandler:addKeyword({'tables'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell big, square, round, small, stone, tusk, bamboo tables.'})
keywordHandler:addKeyword({'plants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell pink and green flowers, also christmas trees.'})
keywordHandler:addKeyword({'furniture'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell large trunks, boxes, drawers, dressers, lockers and troughs.'})
keywordHandler:addKeyword({'more'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell coal basins, birdcages, harps, pianos, globes, clocks and lamps.'})
keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell blue, green, orange, pink, red, white and yellow tapestries.'})
keywordHandler:addKeyword({'small'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell small purple, small green, small red, small blue, small orange, small turquiose and small white pillows.'})
keywordHandler:addKeyword({'round'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell round blue, round red, round purple and round turquiose pillows.'})
keywordHandler:addKeyword({'square'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell blue, red, green and yellow pillows.'})
keywordHandler:addKeyword({'pillows'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell heart, small, sqare and round pillows.'})
keywordHandler:addKeyword({'beds'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {green}, {red} and {yellow} {beds} for {5000}gp. I can sell you too standard bed (to remove modification)'})

npcHandler:addModule(FocusModule:new())
 
Code:
<parameter key="message_greet"
but how to correct this?
any suggestions please?! :/
That's my NPC.LUA :
Code:
- Include the Advanced NPC System
dofile(getDataDir() .. 'npc/lib/npcsystem/npcsystem.lua')

function selfIdle()
    following = false
    attacking = false

    selfAttackCreature(0)
    target = 0
end

function selfSayChannel(cid, message)
    return selfSay(message, cid, false)
end

function selfMoveToCreature(id)
    if(not id or id == 0) then
        return
    end

    local t = getCreaturePosition(id)
    if(not t.x or t.x == nil) then
        return
    end

    selfMoveTo(t.x, t.y, t.z)
    return
end

function getNpcDistanceToCreature(id)
    if(not id or id == 0) then
        selfIdle()
        return nil
    end

    local c = getCreaturePosition(id)
    if(not c.x or c.x == 0) then
        return nil
    end

    local s = getCreaturePosition(getNpcId())
    if(not s.x or s.x == 0 or s.z ~= c.z) then
        return nil
    end

    return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end

function doMessageCheck(message, keyword)
    if(type(keyword) == "table") then
        return table.isStrIn(keyword, message)
    end

    local a, b = message:lower():find(keyword:lower())
    if(a ~= nil and b ~= nil) then
        return true
    end

    return false
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false

    local item = 0
    if(isItemStackable(itemid)) then
        item = doCreateItemEx(itemid, amount)
        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            return 0, 0
        end

        return amount, 0
    end

    local a = 0
    if(inBackpacks) then
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end

            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end

        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end

        a = i
    end

    return a, 0
end

function doRemoveItemIdFromPos (id, n, position)
    local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
    if(thing.itemid == id) then
        doRemoveItem(thing.uid, n)
        return true
    end

    return false
end

function getNpcName()
    return getCreatureName(getNpcId())
end

function getNpcPos()
    return getCreaturePosition(getNpcId())
end

function selfGetPosition()
    local t = getNpcPos()
    return t.x, t.y, t.z
end

msgcontains = doMessageCheck
moveToPosition = selfMoveTo
moveToCreature = selfMoveToCreature
selfMoveToPosition = selfMoveTo
selfGotoIdle = selfIdle
isPlayerPremiumCallback = isPremium
doPosRemoveItem = doRemoveItemIdFromPos
doNpcBuyItem = doPlayerRemoveItem
doNpcSetCreatureFocus = selfFocus
getNpcCid = getNpcId
getDistanceTo = getNpcDistanceTo
getDistanceToCreature = getNpcDistanceToCreature
 
@therrax I saw your pm with the link to this thread. So I guess you want an answare from me.
I tested the npc on a 0.2.14 server and it worked fine. I can't see any problem with the script or xml. Not sure what's happening. Maybe WibbenZ is right and the server version has a bug in its source code.
 
I got this problem but the NPC replies in both color text, just started today, dont know why
After I start conversation it only replies in blue in the NPC window
 

Attachments

I don't code my npc's that way but like this:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local TopicState = {}
-- OTServ event handling functions start
function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
function onPlayerEndTrade(cid)  npcHandler:onPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid)  npcHandler:onPlayerCloseChannel(cid) end
function onThink()  npcHandler:onThink() end
-- OTServ event handling functions end
function creatureSayCallback(cid, type, msg)
 if (msgcontains(msg, "oi") or msgcontains(msg, "hi"))  and (not npcHandler:isFocused(cid)) then
 npcHandler:say("Satisfação e riqueza em um só lugar", cid)
 npcHandler:addFocus(cid)
 TopicState[cid] = 0
 elseif(not npcHandler:isFocused(cid)) then
 return false
 elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
 npcHandler:say("Tchau gostosao, você ficara para sempre na minha mente.", cid, TRUE)
 npcHandler:releaseFocus(cid)
 end
 return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Eu sei que você quer....")

if (msgcontains(msg, "whatever") then
npcHandler:say("whatever", cid)

This way they will speak in the NPC channel. Hope that helps.
 
Well they werent doing this before, then all of a sudden all NPC do it. Even on the standard hi greeting both colors. TFS 0.4 by the way
I tried the npcHandler:say and it didnt respond, ill try again and report back
 

Similar threads

Back
Top