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

Lua NPC Guide understanding more than one word

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Good afternoon people, I'm using a script from an NPC Guide that works fine, but it only understands one word of hunt. I would like to put both singular and plural, eg ["Runes"], ["Rune]", ["Runas"], etc. I tried that way but it didn't work, could you help me?

Lua:
-- City Guide, adding mapmarks to locations by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    ["Runes"] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    ["Djins"] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    ["Carniphilas"] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    ["Elephants"] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    ["Trolls"] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    ["Cyclops"] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
     local function addCptl(first, rest)
          return first:upper()..rest:lower()
    end
 
    local x = config[msg:gsub("(%a)([%w_']*)", addCptl)]
 
    if(x and talkState[talkUser] ~= 2) then
        selfSay('Do you want me to add a mapmark where you can '..x.text..' '..msg..'?', cid)
        xmsg = msg
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        x = config[xmsg:gsub("(%a)([%w_']*)", addCptl)]
        selfSay('Here you are.', cid)
        doPlayerAddMapMark(cid, x.mark,x.type,x.name)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'information')) then
        selfSay('About which location do you want more information?', cid)
        talkState[talkUser] = 2
    elseif(talkState[talkUser] == 2) then
        if(x) then
            if(x.info) then
                selfSay('' .. x.info, cid)
            else
                selfSay('Sorry, I can\'t give you any useful information about this location.', cid)
            end
        else
            selfSay('I don\'t know about this place, look in the {list} which locations I know.', cid)
        end
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'mapmark')) then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'list')) then
        selfSay('Here is my list, tell me where you want to go or you can also ask me for {information} about a location.', cid)
        local text = 'Locations\n'
        for i, x in pairs(config) do
            text = text .. '\n' .. i .. ''
        end
        doShowTextDialog(cid, 1949, '' .. text)
        talkState[talkUser] = 0
    else
        local messages = {'Sorry, I have no idea what you mean with '..msg..'.', 'What?', 'What do you mean?', 'Hmm?', 'Tell me a location, you can look in the {list} which locations I know.'}
        selfSay(messages[math.random(#messages)], cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Yeah @Xikini, i forgot to put but im using TFS 0.3.6. Works in parts, got one error when NPC will mark in map:

View attachment 62231
sending you a dm lol
Post automatically merged:

Nvm, I see the issue.

This should work.
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local configIndex = {}
 
function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)...
Haven't tested, so not sure if it works like that, but try this

Lua:
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
 
local config = {
    ["rune"] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    ["djin"] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    ["carniphila"] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    ["elephant"] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    ["troll"] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    ["cyclop"] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	local x = nil
	for word, param in pairs(config) do
		if msgcontains(msg, word) then
			x = config[word]
			break
		end
	end
 
    if(x and talkState[talkUser] ~= 2) then
        selfSay('Do you want me to add a mapmark where you can '..x.text..' '..msg..'?', cid)
        xmsg = msg
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        x = config[xmsg:gsub("(%a)([%w_']*)", addCptl)]
        selfSay('Here you are.', cid)
        doPlayerAddMapMark(cid, x.mark,x.type,x.name)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'information')) then
        selfSay('About which location do you want more information?', cid)
        talkState[talkUser] = 2
    elseif(talkState[talkUser] == 2) then
        if(x) then
            if(x.info) then
                selfSay('' .. x.info, cid)
            else
                selfSay('Sorry, I can\'t give you any useful information about this location.', cid)
            end
        else
            selfSay('I don\'t know about this place, look in the {list} which locations I know.', cid)
        end
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'mapmark')) then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'list')) then
        selfSay('Here is my list, tell me where you want to go or you can also ask me for {information} about a location.', cid)
        local text = 'Locations\n'
        for i, x in pairs(config) do
            text = text .. '\n' .. i .. ''
        end
        doShowTextDialog(cid, 1949, '' .. text)
        talkState[talkUser] = 0
    else
        local messages = {'Sorry, I have no idea what you mean with '..msg..'.', 'What?', 'What do you mean?', 'Hmm?', 'Tell me a location, you can look in the {list} which locations I know.'}
        selfSay(messages[math.random(#messages)], cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Haven't tested, so not sure if it works like that, but try this

Lua:
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
 
local config = {
    ["rune"] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},  
    ["djin"] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    ["carniphila"] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    ["elephant"] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    ["troll"] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    ["cyclop"] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    local x = nil
    for word, param in pairs(config) do
        if msgcontains(msg, word) then
            x = config[word]
            break
        end
    end
 
    if(x and talkState[talkUser] ~= 2) then
        selfSay('Do you want me to add a mapmark where you can '..x.text..' '..msg..'?', cid)
        xmsg = msg
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        x = config[xmsg:gsub("(%a)([%w_']*)", addCptl)]
        selfSay('Here you are.', cid)
        doPlayerAddMapMark(cid, x.mark,x.type,x.name)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'information')) then
        selfSay('About which location do you want more information?', cid)
        talkState[talkUser] = 2
    elseif(talkState[talkUser] == 2) then
        if(x) then
            if(x.info) then
                selfSay('' .. x.info, cid)
            else
                selfSay('Sorry, I can\'t give you any useful information about this location.', cid)
            end
        else
            selfSay('I don\'t know about this place, look in the {list} which locations I know.', cid)
        end
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'mapmark')) then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'list')) then
        selfSay('Here is my list, tell me where you want to go or you can also ask me for {information} about a location.', cid)
        local text = 'Locations\n'
        for i, x in pairs(config) do
            text = text .. '\n' .. i .. ''
        end
        doShowTextDialog(cid, 1949, '' .. text)
        talkState[talkUser] = 0
    else
        local messages = {'Sorry, I have no idea what you mean with '..msg..'.', 'What?', 'What do you mean?', 'Hmm?', 'Tell me a location, you can look in the {list} which locations I know.'}
        selfSay(messages[math.random(#messages)], cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Got loop

1631992504227.png
 
Good afternoon people, I'm using a script from an NPC Guide that works fine, but it only understands one word of hunt. I would like to put both singular and plural, eg ["Runes"], ["Rune]", ["Runas"], etc. I tried that way but it didn't work, could you help me?

Lua:
-- City Guide, adding mapmarks to locations by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    ["Runes"] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."}, 
    ["Djins"] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    ["Carniphilas"] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    ["Elephants"] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    ["Trolls"] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    ["Cyclops"] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
     local function addCptl(first, rest)
          return first:upper()..rest:lower()
    end
 
    local x = config[msg:gsub("(%a)([%w_']*)", addCptl)]
 
    if(x and talkState[talkUser] ~= 2) then
        selfSay('Do you want me to add a mapmark where you can '..x.text..' '..msg..'?', cid)
        xmsg = msg
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        x = config[xmsg:gsub("(%a)([%w_']*)", addCptl)]
        selfSay('Here you are.', cid)
        doPlayerAddMapMark(cid, x.mark,x.type,x.name)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'information')) then
        selfSay('About which location do you want more information?', cid)
        talkState[talkUser] = 2
    elseif(talkState[talkUser] == 2) then
        if(x) then
            if(x.info) then
                selfSay('' .. x.info, cid)
            else
                selfSay('Sorry, I can\'t give you any useful information about this location.', cid)
            end
        else
            selfSay('I don\'t know about this place, look in the {list} which locations I know.', cid)
        end
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'mapmark')) then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'list')) then
        selfSay('Here is my list, tell me where you want to go or you can also ask me for {information} about a location.', cid)
        local text = 'Locations\n'
        for i, x in pairs(config) do
            text = text .. '\n' .. i .. ''
        end
        doShowTextDialog(cid, 1949, '' .. text)
        talkState[talkUser] = 0
    else
        local messages = {'Sorry, I have no idea what you mean with '..msg..'.', 'What?', 'What do you mean?', 'Hmm?', 'Tell me a location, you can look in the {list} which locations I know.'}
        selfSay(messages[math.random(#messages)], cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if table.contains(v, xMsg) then
            index = config[v]
            break
        end
    end
    
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
        
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
        
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
        
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
        
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},  
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if table.contains(v, xMsg) then
            index = config[v]
            break
        end
    end
   
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
       
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
       
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
       
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
       
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Got error when i said "list" to npc:

1632164313120.png
 
You probably saw my post immediately, before I edited it to fix that issue.

Can you copy and try again?
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if table.contains(v, xMsg) then
            index = config[v]
            break
        end
    end
    
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
        
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
        
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
        
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
        
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Still getting the same error

1632164994499.png
 
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},  
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if table.contains(v, xMsg) then
            index = config[v]
            break
        end
    end
   
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
       
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
       
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
       
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
       
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Still getting the same error

View attachment 62230
Oh, this is my fault.

You're probably running some older tfs, like 0.4 or something.

we have to use isInArray instead of table.contains

Try this
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if isInArray(v, xMsg) then
            index = config[v]
            break
        end
    end
    
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
        
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
        
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
        
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
        
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Yeah @Xikini, i forgot to put but im using TFS 0.3.6. Works in parts, got one error when NPC will mark in map:

View attachment 62231
sending you a dm lol
Post automatically merged:

Nvm, I see the issue.

This should work.
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local configIndex = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},   
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if isInArray(v, xMsg) then
            index = config[v]
            break
        end
    end
    
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
        configIndex[cid] = index
        
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        index = configIndex[cid]
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
        
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
        
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
        
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
        
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Solution
sending you a dm lol
Post automatically merged:

Nvm, I see the issue.

This should work.
Lua:
-- City Guide, adding mapmarks to locations by Limos, altered by Xikini to include the option of multiple config trigger words
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local configIndex = {}
 
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
 
local config = {
    [{"Runes", "Rune", "Runas"}] = {mark = {x = 94, y = 54, z = 7}, type = MAPMARK_SKULL, name = "Dark Rodo's Runes Shop", text = "find", info = "Dark Rodo sells runes, wands, rods and fluids."},  
    [{"Djins"}] = {mark = {x = 600, y = 59, z = 7}, type = MAPMARK_BAG, name = "Djins", text = "hunt in Desert City"},
    [{"Carniphilas"}] = {mark = {x = 800, y = 218, z = 7}, type = MAPMARK_REDNORTH, name = "Carniphilas", text = "hunt in Isengard"},
    [{"Elephants"}] = {mark = {x = 243, y = 125, z = 7}, type = MAPMARK_REDNORTH, name = "Elephants", text = "hunt in Saramansa Desert"},
    [{"Trolls"}] = {mark = {x = 142, y = 76, z = 7}, type = MAPMARK_TICK, name = "Trolls", text = "hunt"},
    [{"Cyclops"}] = {mark = {x = 126, y = 81, z = 7}, type = MAPMARK_REDNORTH, name = "Cyclops", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    local xMsg = msg:gsub("^%l", string.upper)
    local index
    for v, k in pairs(config) do
        if isInArray(v, xMsg) then
            index = config[v]
            break
        end
    end
   
    if index and talkState[talkUser] ~= 2 then
        selfSay("Do you want me to add a mapmark where you can " .. index.text .. " " .. msg .. "?", cid)
        talkState[talkUser] = 1
        configIndex[cid] = index
       
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        selfSay("Here you are.", cid)
        index = configIndex[cid]
        doPlayerAddMapMark(cid, index.mark, index.type, index.name)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Ok then.", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "information") then
        selfSay("About which location do you want more information?", cid)
        talkState[talkUser] = 2
       
    elseif talkState[talkUser] == 2 then
        if index then
            if index.info then
                selfSay(index.info, cid)
            else
                selfSay("Sorry, I can't give you any useful information about this location.", cid)
            end
        else
            selfSay("I don't know about this place, look in the {list} which locations I know.", cid)
        end
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "mapmark") then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
       
    elseif msgcontains(msg, "list") then
        selfSay("Here is my list, tell me where you want to go or you can also ask me for {information} about a location.", cid)
        local text = "Locations\n"
        for v, k in pairs(config) do
            text = text .. "\n" .. v[1]
        end
        doShowTextDialog(cid, 1949, text)
        talkState[talkUser] = 0
       
    else
        local messages = {"Sorry, I have no idea what you mean with " .. msg .. ".", "What?", "What do you mean?", "Hmm?", "Tell me a location, you can look in the {list} which locations I know."}
        selfSay(messages[math.random(#messages)], cid)
       
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Just see now, thanks Xiki, all worked. <3
 
Back
Top