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

TFS 1.1 NPC Dialogue

Tibia Rox

Member
Joined
Feb 4, 2009
Messages
1,181
Reaction score
9
Location
U.S.A
My NPC that I have for an arena isn't responding to certain keywords the way I want him to. Basically, When you say "boss arena" to him, he will ask if you want to join. If you say "yes", he sets your storage value at 3501, 1. I'm trying to make it so that when you already have storage value 3501 and say "boss arena", he responds differently than he did the first time. When I go to him and say "boss arena" with storage value 3501, he still asks if I want to join.

Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, 'boss arena') then if getPlayerStorageValue(cid) >= 3501 then
        npc:say('Welcome back to the boss arena. Would you like to see what {challenges} are avalible, or are you here to {report} about your success in the arena?s', cid)

    elseif(msgcontains(msg, 'boss arena')) then if getPlayerStorageValue(cid) ~= 3501 then
        npcHandler:say('The boss arena is a place where strong and mighty warriors gather to test their skills in a fight against some of the toughest creatures in this world. Many have tried, many have failed. Do you think you have what it takes?', cid)
        talkState = 1
        elseif(msgcontains(msg, 'yes') and talkState == 1) then
            npcHandler:say('I am pleased to hear this. You are very brave. There are different types of {challenges}, each challenge has its own difficulty. Please tell me which challenge you would like to take on.', cid)
            setPlayerStorageValue(cid, 3501, 1)
            talkState = 2
            elseif(msgcontains(msg, 'challenges') and talkState == 2) then
                npcHandler:say('Currently, the only challenge avalible is the {White Pale}.', cid)
                talkState = 3
                elseif(msgcontains(msg, 'white pale') or msgcontains(msg, 'White Pale') and talkState == 3) then
                    npcHandler:say('The White Pale is the easiest monster in the arena. It costs 5 boss tokens to spawn. Would you like to enter the arena?', cid)
                    talkState = 4
                    elseif(msgcontains(msg, 'yes') and talkState == 4) then
                        if(getPlayerItemCount(cid, 24115) >= 5) then
                        doPlayerRemoveItem(cid, 24115, 5)
                        setPlayerStorageValue(cid, 3501, 2)
                        npcHandler:say('Good luck. Flip the lever when you are ready.', cid)
                        else npcHandler:say('You must have 5 {boss tokens} to enter the arena.', cid)
                        talkState = 0
                        end
                    end
                end
            end

    if(msgcontains(msg, 'report')) then
        if(getPlayerStorageValue(cid, 3501) == 3) then
            npcHandler:say('Wow, you did it! Congratulations. Here is a small reward for your hard work.', cid)
            doPlayerAddItem(cid, 2160, 5)
            setPlayerStorageValue(cid, 3501, 4)
            talkState = 6
        end
    end

    if(msgcontains(msg, 'boss tokens') or msgcontains(msg, 'boss token')) then
        npcHandler:say('Boss tokens are used to gain access to the {boss arena}, in which you can fight unique bosses and get very rare loot. Boss tokens are dropped by every single creature in the game with varying loot chances. You can also get boss tokens by doing missions for NPC\'s and from many different quests..', cid)
    end

    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Try changing the first if and the sendond elseif
Code:
if msgcontains(msg, 'boss arena') and if getPlayerStorageValue(cid, 3501) >= 1 then

elseif(msgcontains(msg, 'boss arena')) and if getPlayerStorageValue(cid, 3501) ~= 1 then
 
I tried to do what you said, and now I'm getting this weird error:
https://gyazo.com/f1e5908494f99621655457801e6ff94f

Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, 'boss arena') then if getPlayerStorageValue(cid, 3501) >= 1 then
        npc:say('Welcome back to the boss arena. Would you like to see what {challenges} are avalible, or are you here to {report} about your success in the arena?s', cid)
        talkState = 1
    elseif(msgcontains(msg, 'boss arena')) then if getPlayerStorageValue(cid, 3501) ~= 1 then
        npcHandler:say('The boss arena is a place where strong and mighty warriors gather to test their skills in a fight against some of the toughest creatures in this world. Many have tried, many have failed. Do you think you have what it takes?', cid)
        talkState = 1
        elseif(msgcontains(msg, 'yes') and talkState == 1) then
            npcHandler:say('I am pleased to hear this. You are very brave. There are different types of {challenges}, each challenge has its own difficulty. Please tell me which challenge you would like to take on.', cid)
            setPlayerStorageValue(cid, 3501, 1)
            talkState = 2
            elseif(msgcontains(msg, 'challenges') and talkState == 2) then
                npcHandler:say('Currently, the only challenge avalible is the {White Pale}.', cid)
                talkState = 3
                elseif(msgcontains(msg, 'white pale') or msgcontains(msg, 'White Pale') and talkState == 3) then
                    npcHandler:say('The White Pale is the easiest monster in the arena. It costs 5 boss tokens to spawn. Would you like to enter the arena?', cid)
                    talkState = 4
                    elseif(msgcontains(msg, 'yes') and talkState == 4) then
                        if(getPlayerItemCount(cid, 24115) >= 5) then
                        doPlayerRemoveItem(cid, 24115, 5)
                        setPlayerStorageValue(cid, 3501, 2)
                        npcHandler:say('Good luck. Flip the lever when you are ready.', cid)
                        else npcHandler:say('You must have 5 {boss tokens} to enter the arena.', cid)
                        talkState = 0
                        end
                    end
                end
            end

    if(msgcontains(msg, 'report')) then
        if(getPlayerStorageValue(cid, 3501) == 3) then
            npcHandler:say('Wow, you did it! Congratulations. Here is a small reward for your hard work.', cid)
            doPlayerAddItem(cid, 2160, 5)
            setPlayerStorageValue(cid, 3501, 4)
            talkState = 6
        end
    end

    if(msgcontains(msg, 'boss tokens') or msgcontains(msg, 'boss token')) then
        npcHandler:say('Boss tokens are used to gain access to the {boss arena}, in which you can fight unique bosses and get very rare loot. Boss tokens are dropped by every single creature in the game with varying loot chances. You can also get boss tokens by doing missions for NPC\'s and from many different quests..', cid)
    end

    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Ok I thought I had it fixed, but now the NPC is only responding to the first 'boss arena' key word. Im pretty sure theres a problem with my end tags, but I'm not sure exactly what it is.

Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, 'boss arena') then if getPlayerStorageValue(cid, 3501) >= 1 then
        npcHandler:say('Welcome back to the boss arena. Would you like to see what {challenges} are avalible, or are you here to {report} about your success in the arena?', cid)
        talkState = 1
        end
    elseif(msgcontains(msg, 'boss arena')) then if getPlayerStorageValue(cid, 3501) ~= 1 then
        npcHandler:say('The boss arena is a place where strong and mighty warriors gather to test their skills in a fight against some of the toughest creatures in this world. Many have tried, many have failed. Do you think you have what it takes?', cid)
        talkState = 1
        elseif(msgcontains(msg, 'yes') and talkState == 1) then
            npcHandler:say('I am pleased to hear this. You are very brave. There are different types of {challenges}, each challenge has its own difficulty. Please tell me which challenge you would like to take on.', cid)
            setPlayerStorageValue(cid, 3501, 1)
            talkState = 2
            elseif msgcontains(msg, 'challenges') then 
                npcHandler:say('Currently, the only challenge avalible is the {White Pale}.', cid)
                talkState = 3
                elseif(msgcontains(msg, 'white pale') or msgcontains(msg, 'White Pale') and talkState == 3) then
                    npcHandler:say('The White Pale is the easiest monster in the arena. It costs 5 boss tokens to spawn. Would you like to enter the arena?', cid)
                    talkState = 4
                    elseif(msgcontains(msg, 'yes') and talkState == 4) then
                        if(getPlayerItemCount(cid, 24115) >= 5) then
                        doPlayerRemoveItem(cid, 24115, 5)
                        setPlayerStorageValue(cid, 3501, 2)
                        npcHandler:say('Good luck. Flip the lever when you are ready.', cid)
                        else npcHandler:say('You must have 5 {boss tokens} to enter the arena.', cid)
                        talkState = 0
                        end
                    end
                end

    if msgcontains(msg, 'report') then if getPlayerStorageValue(cid, 3501) == 3 then
            npcHandler:say('Wow, you did it! Congratulations. Here is a small reward for your hard work.', cid)
            doPlayerAddItem(cid, 2160, 5)
            setPlayerStorageValue(cid, 3501, 4)
        end
    end

    if(msgcontains(msg, 'boss tokens') or msgcontains(msg, 'boss token')) then
        npcHandler:say('Boss tokens are used to gain access to the {boss arena}, in which you can fight unique bosses and get very rare loot. Boss tokens are dropped by every single creature in the game with varying loot chances. You can also get boss tokens by doing missions for NPC\'s and from many different quests..', cid)
    end

    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top