• 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.0] NPC Quest Script Help

Jaed Le Raep

★Gaeming★
Joined
Sep 3, 2007
Messages
1,296
Reaction score
441
Hey guys, I'm having a problem with this script. Whenever I get to Creston and get the quest, everything works out (the quest log and etc is coded in the quests.xml), but when I say stockade, the npc doesn't respond. Not sure why, so I'm hoping you can help. As far as greeting and the NPC getting you to say Creston, that is handled in the NPC's xml file. This is a sloppy script template I've had since 2010, so besides helping me troubleshoot the issue, could you also help clean it up?

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
local storage = 8000

    if(msgcontains(msg, 'Creston')) then
        if(getPlayerStorageValue(cid, storage) < 1) then
            npcHandler:say("Yer\' gonna go there and get me {10 cheese}, {25 fishes}, and {50 lumps of dough}. Once yer do, you\'ll have some standing in my crew. {Before you leave, go ask Jenkins for} {your belongings}.", cid)
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Quest: Awaken")
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Objective: Earn Your Standing")
            setPlayerStorageValue(cid, storage, 1)
            talkState[talkUser] = 0
        elseif(getPlayerStorageValue(cid, storage) == 1) then
            npcHandler:say("Get yer' ass to Creston, you still haven't gotten our stockade!", cid)
            talkState[talkUser] = 0
        elseif(getPlayerStorageValue(cid, storage) >= 2) then
            npcHandler:say("Ready to head back to Creston?", cid)
            talkState[talkUser] = 2
    end
    if(msgcontains(msg, 'Stockade')) then
        if (getPlayerStorageValue(cid, storage) == 1) and doPlayerRemoveItem(cid, 11210, 5) == true then
            setPlayerStorageValue(cid, storage, 3)
            doPlayerAddItem(cid, 2345)
            doPlayerAddExp(cid, 50)
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "Objective Complete: Earn Your Standing")
            npcHandler:say("Yer' now one of us! Let me know when you want to go to Creston.", cid)
        else
            npcHandler:say("Go and get the rest of what we need for the stockade!", cid)
            talkState[talkUser] = 0
    end
   
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
            npcHandler:say("Get ready to sail to Creston!", cid)
            talkState[talkUser] = 0
        else
            npcHandler:say("Let me know when ye's be ready!", cid)
            talkState[talkUser] = 0
    end
   
    return TRUE
end
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
The player's 8000 storage has not been touched. It's passed all parameters for the Stockade keyword, yet the npc won't say a single thing.
 
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
local storage = 8000

    if(msgcontains(msg, 'Creston')) then
        if(getPlayerStorageValue(cid, storage) < 1) then
            npcHandler:say("Yer\' gonna go there and get me {10 cheese}, {25 fishes}, and {50 lumps of dough}. Once yer do, you\'ll have some standing in my crew. {Before you leave, go ask Jenkins for} {your belongings}.", cid)
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Quest: Awaken")
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Objective: Earn Your Standing")
            setPlayerStorageValue(cid, storage, 1)
            talkState[talkUser] = 0
        elseif(getPlayerStorageValue(cid, storage) == 1) then
            npcHandler:say("Get yer' ass to Creston, you still haven't gotten our stockade!", cid)
            talkState[talkUser] = 0
        elseif(getPlayerStorageValue(cid, storage) >= 2) then
            npcHandler:say("Ready to head back to Creston?", cid)
            talkState[talkUser] = 2
        end
    elseif(msgcontains(msg, 'Stockade')) then
        if (getPlayerStorageValue(cid, storage) == 1) and doPlayerRemoveItem(cid, 11210, 5) == true then
            setPlayerStorageValue(cid, storage, 3)
            doPlayerAddItem(cid, 2345)
            doPlayerAddExp(cid, 50)
            addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "Objective Complete: Earn Your Standing")
            npcHandler:say("Yer' now one of us! Let me know when you want to go to Creston.", cid)
        else
            npcHandler:say("Go and get the rest of what we need for the stockade!", cid)
            talkState[talkUser] = 0
        end
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
        npcHandler:say("Get ready to sail to Creston!", cid)
        talkState[talkUser] = 0
    else
        npcHandler:say("Let me know when ye's be ready!", cid)
        talkState[talkUser] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
If you tab the script you can see that the if statement for stockade is inside the if statement for creston.
Code:
  if(msgcontains(msg, 'Creston')) then
       if(getPlayerStorageValue(cid, storage) < 1) then
           npcHandler:say("Yer\' gonna go there and get me {10 cheese}, {25 fishes}, and {50 lumps of dough}. Once yer do, you\'ll have some standing in my crew. {Before you leave, go ask Jenkins for} {your belongings}.", cid)
           addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Quest: Awaken")
           addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Objective: Earn Your Standing")
           setPlayerStorageValue(cid, storage, 1)
           talkState[talkUser] = 0
       elseif(getPlayerStorageValue(cid, storage) == 1) then
           npcHandler:say("Get yer' ass to Creston, you still haven't gotten our stockade!", cid)
           talkState[talkUser] = 0
       elseif(getPlayerStorageValue(cid, storage) >= 2) then
           npcHandler:say("Ready to head back to Creston?", cid)
           talkState[talkUser] = 2
       end
       if(msgcontains(msg, 'Stockade')) then
           if (getPlayerStorageValue(cid, storage) == 1) and doPlayerRemoveItem(cid, 11210, 5) == true then
               setPlayerStorageValue(cid, storage, 3)
               doPlayerAddItem(cid, 2345)
               doPlayerAddExp(cid, 50)
               addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "Objective Complete: Earn Your Standing")
               npcHandler:say("Yer' now one of us! Let me know when you want to go to Creston.", cid)
           else
               npcHandler:say("Go and get the rest of what we need for the stockade!", cid)
               talkState[talkUser] = 0
           end
Like this both if statements need to be true, so someone should say creston and stockage, but then the msg contains creston so it will still respond on the first one.
By using elseif it would check if people say stockage if the if statement above isn't true (so if people didn't say creston).

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
     local storage = 8000

     if(msgcontains(msg, 'Creston')) then
         if(getPlayerStorageValue(cid, storage) < 1) then
             npcHandler:say("Yer\' gonna go there and get me {10 cheese}, {25 fishes}, and {50 lumps of dough}. Once yer do, you\'ll have some standing in my crew. {Before you leave, go ask Jenkins for} {your belongings}.", cid)
             addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Quest: Awaken")
             addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "New Objective: Earn Your Standing")
             setPlayerStorageValue(cid, storage, 1)
             talkState[talkUser] = 0
         elseif(getPlayerStorageValue(cid, storage) == 1) then
             npcHandler:say("Get yer' ass to Creston, you still haven't gotten our stockade!", cid)
             talkState[talkUser] = 0
         elseif(getPlayerStorageValue(cid, storage) >= 2) then
             npcHandler:say("Ready to head back to Creston?", cid)
             talkState[talkUser] = 2
         end
     elseif(msgcontains(msg, 'Stockade')) then
         if (getPlayerStorageValue(cid, storage) == 1) and doPlayerRemoveItem(cid, 11210, 5) == true then
             setPlayerStorageValue(cid, storage, 3)
             doPlayerAddItem(cid, 2345)
             doPlayerAddExp(cid, 50)
             addEvent(doPlayerSendTextMessage, 500, cid, MESSAGE_INFO_DESCR, "Objective Complete: Earn Your Standing")
             npcHandler:say("Yer' now one of us! Let me know when you want to go to Creston.", cid)
         else
             npcHandler:say("Go and get the rest of what we need for the stockade!", cid)
             talkState[talkUser] = 0
         end
     elseif talkState[talkUser] == 2 then
         if msgcontains(msg, 'yes') then
             npcHandler:say("Get ready to sail to Creston!", cid)
         else
             npcHandler:say("Let me know when ye's be ready!", cid)
         end
         talkState[talkUser] = 0
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Edit: didn't see Ninja's post.
 
Wow Limos and Ninja, thanks for the help. Limos, thank you so much for explaining it, though, because I never would have gotten it. This mistake is part of what I mean by having forgotten the basics, just a simple mistake such as tabbing caused an issue I couldn't figure out how to fix for about three days. Thank you :)
 
Wow Limos and Ninja, thanks for the help. Limos, thank you so much for explaining it, though, because I never would have gotten it. This mistake is part of what I mean by having forgotten the basics, just a simple mistake such as tabbing caused an issue I couldn't figure out how to fix for about three days. Thank you :)
It wasen't the tabbing that ruined it. It was that its alot easier to see the problems when its tabbed. Try fixing chaos bangle with over 350 lines of code when NOTHING is tabbed. *hangs myself*

"If you tab the script you can see that the if statement for stockade is inside the if statement for creston."
 
It wasen't the tabbing that ruined it. It was that its alot easier to see the problems when its tabbed. Try fixing chaos bangle with over 350 lines of code when NOTHING is tabbed. *hangs myself*

"If you tab the script you can see that the if statement for stockade is inside the if statement for creston."

I mispoke when I said the tabbing was the issue. Every single script that I have and use is tabbed and properly formatted. This time it was just the fact that I didn't realize that and "if" section below another "if" section would cause this loop that provides really no error message. Anyway, thanks again guys. @Ninja @Limos
 
Back
Top