• 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!

Solved NPC Responds to all Words with "hi"

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,317
Solutions
35
Reaction score
435
Hello,

I'm using Rev 5916 TFS 0.3.7 and I'm having a problem with npcs responding to all words which contain "hi".

If you are nearby and you say "thing", "him", etc the NPC will greet you.

Does anyone know where I can fix that?
 
Last edited:
well that is the way the NPC work when you us msgcontains(msg,"hi").

You can possibly do a
If(msg == "hi")
but then if someone said something like "Hi NPCName" it wouldn't recognize.
 
There is no where in the NPC.lua file listed:
if msgcontains(msg, 'Hi') then
So there must be some place in the NPC libraries where this can be edited for all NPCs. I just don't know which/where that function would be.
 
Im not sure if this is what you mean but this is in.
Data/Npcs/Lib "npcsystem.lua"
Click Spoiler - Comment or like if this helped thanks.
Code:
-- Greeting and unGreeting keywords. For more information look at the top of modules.lua
FOCUS_GREETWORDS = {'hi', 'hello', 'hey'}
FOCUS_FAREWELLWORDS = {'bye', 'farewell', 'cya'}
Code:
-- Advanced NPC System (Created by Jiddo),
-- Modified by Talaturen.

if(NpcSystem == nil) then
    -- Loads the underlying classes of the npcsystem.
    dofile(getDataDir() .. 'npc/lib/npcsystem/keywordhandler.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/queue.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/npchandler.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/modules.lua')

    -- Global npc constants:

    -- Keyword nestling behavior. For more information look at the top of keywordhandler.lua
    KEYWORD_BEHAVIOR = BEHAVIOR_NORMAL_EXTENDED

    -- Greeting and unGreeting keywords. For more information look at the top of modules.lua
    FOCUS_GREETWORDS = {'hi', 'hello', 'hey'}
    FOCUS_FAREWELLWORDS = {'bye', 'farewell', 'cya'}

    -- The word for requesting trade window. For more information look at the top of modules.lua
    SHOP_TRADEREQUEST = {'offer', 'trade'}

    -- The word for accepting/declining an offer. CAN ONLY CONTAIN ONE FIELD! For more information look at the top of modules.lua
    SHOP_YESWORD = {'yes'}
    SHOP_NOWORD = {'no'}

    -- Pattern used to get the amount of an item a player wants to buy/sell.
    PATTERN_COUNT = '%d+'

    -- Talkdelay behavior. For more information, look at the top of npchandler.lua.
    NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK

    -- Conversation behavior. For more information, look at the top of npchandler.lua.
    NPCHANDLER_CONVBEHAVIOR = CONVERSATION_PRIVATE

    -- Constant strings defining the keywords to replace in the default messages.
    --    For more information, look at the top of npchandler.lua...
    TAG_PLAYERNAME = '|PLAYERNAME|'
    TAG_ITEMCOUNT = '|ITEMCOUNT|'
    TAG_TOTALCOST = '|TOTALCOST|'
    TAG_ITEMNAME = '|ITEMNAME|'
    TAG_QUEUESIZE = '|QUEUESIZE|'

    NpcSystem = {}

    -- Gets an npcparameter with the specified key. Returns nil if no such parameter is found.
    function NpcSystem.getParameter(key)
        local ret = getNpcParameter(tostring(key))
        if((type(ret) == 'number' and ret == 0) or ret == nil) then
            return nil
        else
            return ret
        end
    end

    -- Parses all known parameters for the npc. Also parses parseable modules.
    function NpcSystem.parseParameters(npcHandler)
        local ret = NpcSystem.getParameter('idletime')
        if(ret ~= nil) then
            npcHandler.idleTime = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('talkradius')
        if(ret ~= nil) then
            npcHandler.talkRadius = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('message_greet')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_GREET, ret)
        end
        local ret = NpcSystem.getParameter('message_farewell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_FAREWELL, ret)
        end
        local ret = NpcSystem.getParameter('message_decline')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_DECLINE, ret)
        end
        local ret = NpcSystem.getParameter('message_needmorespace')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDMORESPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_needspace')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDSPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_sendtrade')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SENDTRADE, ret)
        end
        local ret = NpcSystem.getParameter('message_noshop')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NOSHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_oncloseshop')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONCLOSESHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_onbuy')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONBUY, ret)
        end
        local ret = NpcSystem.getParameter('message_onsell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONSELL, ret)
        end
        local ret = NpcSystem.getParameter('message_missingmoney')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_MISSINGMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_needmoney')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_missingitem')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_MISSINGITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_needitem')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_idletimeout')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_IDLETIMEOUT, ret)
        end
        local ret = NpcSystem.getParameter('message_walkaway')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_WALKAWAY, ret)
        end
        local ret = NpcSystem.getParameter('message_alreadyfocused')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ALREADYFOCUSED, ret)
        end
        local ret = NpcSystem.getParameter('message_placedinqueue')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, ret)
        end
        local ret = NpcSystem.getParameter('message_buy')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_BUY, ret)
        end
        local ret = NpcSystem.getParameter('message_sell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SELL, ret)
        end
        local ret = NpcSystem.getParameter('message_bought')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_BOUGHT, ret)
        end
        local ret = NpcSystem.getParameter('message_sold')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SOLD, ret)
        end

        -- Parse modules.
        for parameter, module in pairs(Modules.parseableModules) do
            local ret = NpcSystem.getParameter(parameter)
            if(ret ~= nil) then
                local number = tonumber(ret)
                if(number ~= nil and number ~= 0) then
                    npcHandler:addModule(module:new())
                end
            end
        end
    end
end
 
Last edited:
Post one of your npcs scripts please. I had the impression the NPCs in 3.7 used the same idea as 3.6
Here is Benjamin.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
local Topic = {}
local voices = {
    'Welcome to the post office!',
    'If you need help with letters or parcels, just ask me. I can explain everything.',
    'Hey, send a letter to your friend now and then. Keep in touch, you know.'
}

local lastSound = 0
function onThink()
    if lastSound < os.time() then
        lastSound = (os.time() + 10)
        if math.random(100) < 20 then
            npcHandler:say(voices[math.random(#voices)], TALKTYPE_SAY)
        end
    end
    npcHandler:onThink()
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if msgcontains(msg, "measurements") then
        if getPlayerStorageValue(cid, Storage.postman.Mission07) >= 1 and getPlayerStorageValue(cid, Storage.postman.Mailman04) ~= 1 then
            npcHandler:say("Oh they don't change that much since in the old days as... <tells a boring and confusing story about a cake, a parcel, himself and two squirrels, at least he tells you his measurements in the end> ", cid)
            setPlayerStorageValue(cid, Storage.postman.Mission07, getPlayerStorageValue(cid, Storage.postman.Mission07) + 1)
            setPlayerStorageValue(cid, Storage.postman.Mailman04, 1)
            Topic[cid] = 0
        else
            npcHandler:say("I already gave you my measurements. If you are interesting in buying a letter to write it down please say {trade}.", cid)
            Topic[cid] = 0
        end
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Hello. How may I help you |PLAYERNAME|? Ask me for a {trade} if you want to buy something. I can also explain the {mail} system.")
npcHandler:setMessage(MESSAGE_FAREWELL, "It was a pleasure to help you, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Im not sure if this is what you mean but this is in.
Data/Npcs/Lib "npcsystem.lua"
Click Spoiler - Comment or like if this helped thanks.
Code:
-- Advanced NPC System (Created by Jiddo),
-- Modified by Talaturen.

if(NpcSystem == nil) then
    -- Loads the underlying classes of the npcsystem.
    dofile(getDataDir() .. 'npc/lib/npcsystem/keywordhandler.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/queue.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/npchandler.lua')
    dofile(getDataDir() .. 'npc/lib/npcsystem/modules.lua')

    -- Global npc constants:

    -- Keyword nestling behavior. For more information look at the top of keywordhandler.lua
    KEYWORD_BEHAVIOR = BEHAVIOR_NORMAL_EXTENDED

    -- Greeting and unGreeting keywords. For more information look at the top of modules.lua
    FOCUS_GREETWORDS = {'hi', 'hello', 'hey'}
    FOCUS_FAREWELLWORDS = {'bye', 'farewell', 'cya'}

    -- The word for requesting trade window. For more information look at the top of modules.lua
    SHOP_TRADEREQUEST = {'offer', 'trade'}

    -- The word for accepting/declining an offer. CAN ONLY CONTAIN ONE FIELD! For more information look at the top of modules.lua
    SHOP_YESWORD = {'yes'}
    SHOP_NOWORD = {'no'}

    -- Pattern used to get the amount of an item a player wants to buy/sell.
    PATTERN_COUNT = '%d+'

    -- Talkdelay behavior. For more information, look at the top of npchandler.lua.
    NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK

    -- Conversation behavior. For more information, look at the top of npchandler.lua.
    NPCHANDLER_CONVBEHAVIOR = CONVERSATION_PRIVATE

    -- Constant strings defining the keywords to replace in the default messages.
    --    For more information, look at the top of npchandler.lua...
    TAG_PLAYERNAME = '|PLAYERNAME|'
    TAG_ITEMCOUNT = '|ITEMCOUNT|'
    TAG_TOTALCOST = '|TOTALCOST|'
    TAG_ITEMNAME = '|ITEMNAME|'
    TAG_QUEUESIZE = '|QUEUESIZE|'

    NpcSystem = {}

    -- Gets an npcparameter with the specified key. Returns nil if no such parameter is found.
    function NpcSystem.getParameter(key)
        local ret = getNpcParameter(tostring(key))
        if((type(ret) == 'number' and ret == 0) or ret == nil) then
            return nil
        else
            return ret
        end
    end

    -- Parses all known parameters for the npc. Also parses parseable modules.
    function NpcSystem.parseParameters(npcHandler)
        local ret = NpcSystem.getParameter('idletime')
        if(ret ~= nil) then
            npcHandler.idleTime = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('talkradius')
        if(ret ~= nil) then
            npcHandler.talkRadius = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('message_greet')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_GREET, ret)
        end
        local ret = NpcSystem.getParameter('message_farewell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_FAREWELL, ret)
        end
        local ret = NpcSystem.getParameter('message_decline')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_DECLINE, ret)
        end
        local ret = NpcSystem.getParameter('message_needmorespace')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDMORESPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_needspace')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDSPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_sendtrade')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SENDTRADE, ret)
        end
        local ret = NpcSystem.getParameter('message_noshop')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NOSHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_oncloseshop')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONCLOSESHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_onbuy')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONBUY, ret)
        end
        local ret = NpcSystem.getParameter('message_onsell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ONSELL, ret)
        end
        local ret = NpcSystem.getParameter('message_missingmoney')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_MISSINGMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_needmoney')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_missingitem')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_MISSINGITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_needitem')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_NEEDITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_idletimeout')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_IDLETIMEOUT, ret)
        end
        local ret = NpcSystem.getParameter('message_walkaway')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_WALKAWAY, ret)
        end
        local ret = NpcSystem.getParameter('message_alreadyfocused')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_ALREADYFOCUSED, ret)
        end
        local ret = NpcSystem.getParameter('message_placedinqueue')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, ret)
        end
        local ret = NpcSystem.getParameter('message_buy')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_BUY, ret)
        end
        local ret = NpcSystem.getParameter('message_sell')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SELL, ret)
        end
        local ret = NpcSystem.getParameter('message_bought')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_BOUGHT, ret)
        end
        local ret = NpcSystem.getParameter('message_sold')
        if(ret ~= nil) then
            npcHandler:setMessage(MESSAGE_SOLD, ret)
        end

        -- Parse modules.
        for parameter, module in pairs(Modules.parseableModules) do
            local ret = NpcSystem.getParameter(parameter)
            if(ret ~= nil) then
                local number = tonumber(ret)
                if(number ~= nil and number ~= 0) then
                    npcHandler:addModule(module:new())
                end
            end
        end
    end
end

Hi, it doesn't really help me much without explanation but thanks for posting.

Where would I edit to stop it from responding to words like "thing" and only respond to "hi"?
Removing "hi" and only keeping "hello" would cause confusion among the players since most people normally say hi.
 
Back
Top