• 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 My NPC don't respond to 'yes'

gabriel28

Member
Joined
Mar 16, 2012
Messages
199
Solutions
6
Reaction score
24
I'm learning to build mission npc, but I'm having trouble with NPC 2 and 3, they do not respond to 'yes'.
Can someone help me? Thanks in advance.
They are related:
The NPC 1 tell to bring stuffs from NPC 2. And NPC 2 say that to do that, need itens from NPC3.


NPC 1

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:eek:nCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:eek:nCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:eek:nCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:eek:nThink()           end
local storage = 135001
function creatureSayCallback(cid, type, msg)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
    msg = msg:lower();
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
         if msg == "catacounbs" then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("Hello! I think you are here to get acess to the entrance of The Catacounbs, right?", cid)
                 talkState[talkUser] = 1
             elseif getPlayerStorageValue(cid, storage) == 5 then
                 selfSay("Did you bring me the itens?", cid)
                 talkState[talkUser] = 1
             elseif getPlayerStorageValue(cid, storage) == 6 then
                 selfSay("Thanks for the help.", cid)
                else
                    selfSay("Something is missing.", cid)
             end
             npcHandler:addFocus(cid)
         else
             return false
         end

     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("For I give you the acess you need to make me a favor. Go to Nico and tell him that I want the {stuffs}. He'll know what is.", cid)
             setPlayerStorageValue(cid, storage, 1)
         elseif getPlayerStorageValue(cid, storage) == 5 then
             if doPlayerRemoveItem(cid, 2796, 1) then
                 selfSay("Well, now you can pass the door.", cid)
                 doPlayerAddItem(cid, 2160, 3)
                 doPlayerAddExp(cid, 5000)
                 setPlayerStorageValue(cid, storage, 6)
             else
                 selfSay("You don't have it.", cid)
             end
            else
                selfSay("I think you've not talk with Nico yet", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

NPC 2

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:eek:nCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:eek:nCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:eek:nCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:eek:nThink()           end
local storage = 135001
function creatureSayCallback(cid, type, msg)

        if(not npcHandler:isFocused(cid)) then
        return false
    end
    msg = msg:lower();
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
         if msg == "stuffs" then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("What you mean?", cid)
             elseif getPlayerStorageValue(cid, storage) == 1 then
                 selfSay("I think you come here for Tery. Well, to do what him want I need that you go to Lian and bring me some {mix herbs}, can you do it?", cid)
                 talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 4 then
                 selfSay("Did you bring the mix herbs?", cid)
                 talkState[talkUser] = 1   
             elseif getPlayerStorageValue(cid, storage) == 5 then
                 selfSay("Already done.", cid)
                else
                 selfSay("Something is missing.", cid)
             end
             npcHandler:addFocus(cid)
         else
             return false
         end

     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == 1 then
             selfSay("So be it. Come back when you have it.", cid)
             setPlayerStorageValue(cid, storage, 2)
         elseif getPlayerStorageValue(cid, storage) == 4 then
             if doPlayerRemoveItem(cid, 2801, 1) then
                 selfSay("Here are. Tell Tery to come visit me at any time.", cid)
                 doPlayerAddItem(cid, 2796, 1)
                 setPlayerStorageValue(cid, storage, 5)
             else
                 selfSay("You don't have it.", cid)
             end
            else
                selfSay("I think you've not talk with Lian yet", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

NPC 3

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:eek:nCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:eek:nCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:eek:nCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:eek:nThink()           end
local storage = 135001
function creatureSayCallback(cid, type, msg)

        if(not npcHandler:isFocused(cid)) then
        return false
    end
    msg = msg:lower();
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
         if msg == "mix herbs" then
             if getPlayerStorageValue(cid, storage) <= 1 then
                 selfSay("What do you mean by that?", cid)
             elseif getPlayerStorageValue(cid, storage) == 2 then
                 selfSay("Hm...Ok then. Back with one of each item below: blood herb, stone herb, star herb, sling herb, powder herb and shadow herb. Ok?", cid)
                 talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 3 then
                 selfSay("You bring the herbs?", cid)
                 talkState[talkUser] = 1   
             elseif getPlayerStorageValue(cid, storage) == 6 then
                 selfSay("I already gave it to you. Have you memory loss?", cid)
                else
                 selfSay("Something is missing.", cid)
             end
             npcHandler:addFocus(cid)
         else
             return false
         end

     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == 2 then
             selfSay("Ok, come back when you have it.", cid)
             setPlayerStorageValue(cid, storage, 3)
         elseif getPlayerStorageValue(cid, storage) == 3 then
             if doPlayerRemoveItem(cid, 2798, 1) and doPlayerRemoveItem(cid, 2799, 1) and doPlayerRemoveItem(cid, 2800, 1) and doPlayerRemoveItem(cid, 2802, 1) and doPlayerRemoveItem(cid, 2803, 1) and doPlayerRemoveItem(cid, 2804, 1) then
                 selfSay("So done. Here are the mix herb", cid)
                 doPlayerAddItem(cid, 2801, 1)
                 setPlayerStorageValue(cid, storage, 4)
             else
                 selfSay("You don't have it.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

up

up
 
Last edited by a moderator:
Solution
At line 34 on NPC 2 and 3 you had
Lua:
else
   return false
end
Basically, if the if on line 18 wasn't true, the npc would stop talking to the player because of the return false, so I just removed the else and the return false from the script so it would continue with the rest of the valid words.
on NPC 1 you should remove line 32 and 33.
npc 2
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:eek:nCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:eek:nCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:eek:nCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:eek:nThink()           end
local storage = 135001
function creatureSayCallback(cid, type, msg)

        if(not npcHandler:isFocused(cid)) then
        return false
    end
    msg = msg:lower();
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
         if msg == "stuffs" then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("What you mean?", cid)
             elseif getPlayerStorageValue(cid, storage) == 1 then
                 selfSay("I think you come here for Tery. Well, to do what him want I need that you go to Lian and bring me some {mix herbs}, can you do it?", cid)
                 talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 4 then
                 selfSay("Did you bring the mix herbs?", cid)
                 talkState[talkUser] = 1 
             elseif getPlayerStorageValue(cid, storage) == 5 then
                 selfSay("Already done.", cid)
                else
                 selfSay("Something is missing.", cid)
             end
             npcHandler:addFocus(cid)
         end

     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == 1 then
             selfSay("So be it. Come back when you have it.", cid)
             setPlayerStorageValue(cid, storage, 2)
         elseif getPlayerStorageValue(cid, storage) == 4 then
             if doPlayerRemoveItem(cid, 2801, 1) then
                 selfSay("Here are. Tell Tery to come visit me at any time.", cid)
                 doPlayerAddItem(cid, 2796, 1)
                 setPlayerStorageValue(cid, storage, 5)
             else
                 selfSay("You don't have it.", cid)
             end
            else
                selfSay("I think you've not talk with Lian yet", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
npc 3
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:eek:nCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:eek:nCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:eek:nCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:eek:nThink()           end
local storage = 135001
function creatureSayCallback(cid, type, msg)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
    msg = msg:lower();
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
     if msg == "mix herbs" then
         if getPlayerStorageValue(cid, storage) <= 1 then
             selfSay("What do you mean by that?", cid)
         elseif getPlayerStorageValue(cid, storage) == 2 then
             selfSay("Hm...Ok then. Back with one of each item below: blood herb, stone herb, star herb, sling herb, powder herb and shadow herb. Ok?", cid)
             talkState[talkUser] = 1
        elseif getPlayerStorageValue(cid, storage) == 3 then
             selfSay("You bring the herbs?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 6 then
             selfSay("I already gave it to you. Have you memory loss?", cid)
            else
             selfSay("Something is missing.", cid)
         end
         npcHandler:addFocus(cid)
     end

     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == 2 then
             selfSay("Ok, come back when you have it.", cid)
             setPlayerStorageValue(cid, storage, 3)
         elseif getPlayerStorageValue(cid, storage) == 3 then
             if doPlayerRemoveItem(cid, 2798, 1) and doPlayerRemoveItem(cid, 2799, 1) and doPlayerRemoveItem(cid, 2800, 1) and doPlayerRemoveItem(cid, 2802, 1) and doPlayerRemoveItem(cid, 2803, 1) and doPlayerRemoveItem(cid, 2804, 1) then
                 selfSay("So done. Here are the mix herb", cid)
                 doPlayerAddItem(cid, 2801, 1)
                 setPlayerStorageValue(cid, storage, 4)
             else
                 selfSay("You don't have it.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
As in they don't work?
They aren't the same lol

I don't tested yet because I'm all the day in the University these days. But, talking about the scripts that u posted, I don't know, but here (for me) thay are the same, have the same msg trigger, give the same storages, remove the same itens, have the same msg as answers. xD
 
Well, have you tried comparing the number of lines in the code?
Hint: check line 34 on both of your codes and mine.
You should really test things before saying they don't work lol
 
Well, have you tried comparing the number of lines in the code?
Hint: check line 34 on both of your codes and mine.
You should really test things before saying they don't work lol

No, man, that's not what I said, I did not say it did not work.
When I said that the scripts you posted were the same, I meant they were the same with each other, you know? The NPC 2 script you posted is the same as the NPC 3 script you posted, that's what I meant.
 
Kek, my bad edited that post.


Don't worry, I was not clear enough.
Thank you, the script now works. Could you tell me where I went wrong? Because I'll don't make the same mistake and be able to fix NPC 1, because it's him that is not working right now. LOL
 
At line 34 on NPC 2 and 3 you had
Lua:
else
   return false
end
Basically, if the if on line 18 wasn't true, the npc would stop talking to the player because of the return false, so I just removed the else and the return false from the script so it would continue with the rest of the valid words.
on NPC 1 you should remove line 32 and 33.
 
Solution

I've do that when I compare your script with the one I made, and I supposed that this was the bug, so I removed and fixed it by myself. But thanks a lot with the help and explanation about what the return false did.
 
Good, not many people try themselves and wait to get spoonfed lol.

This is what I do to try to "learn" how to make some script. For now, I just know how to modify some stuffs, was that way I made this NPCs, in the same day after read Limo's Tutorial about NPC, so I taked one script as base and made it. hahahaha
 
Back
Top