• 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 0.X (lua) HELP NPC QUEST with storage

royalpala

Well-Known Member
Joined
Dec 31, 2019
Messages
85
Solutions
1
Reaction score
68
Good evening, people
I am working on a Quest NPC and had some problems while testing into my OTserver Im not a pro but i did my best and I dont know whats wrong with this
npc is responding various texts when I say "reborn" ,"reborn knight" "reborn paladin" "reborn druid" "reborn sorcerer".
when you say "Quest" or "brooch" and then "yes" he is not responding
this script has been hours and hours of worktime and i would like it to get to work

this NPC has a Task for level 200 and another Quest
also I dont know if the storage values are ok..

TFS 0.4 for 8.6
theres no error messages on console

sorry if the script is too long

Lua:
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, 'reborn knight') or msgcontains(msg, 'rebirth knight')) then
        selfSay('Are you sure you want to Reset your vocation to start this Task?', cid)
        talkState[talkUser] = 2
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
        if(getPlayerVocation(cid) == 8 and getPlayerLevel(cid) == 200) then
        doPlayerSetVocation(cid, 0)
         doPlayerSetStorageValue(cid, 6010, 1)
          selfSay('While this task is open you have access to the spell EXORI NON, Your vocation has been removed, now you need to reach level 250, come back to me when you are done!', cid)

            elseif (getPlayerVocation(cid) == 8 and getPlayerLevel(cid) > 200) then
                selfSay('Seems like you are too strong already for this task! you need to be level 200!', cid)

            elseif (getPlayerVocation(cid) == 8 and getPlayerLevel(cid) < 200) then
                selfSay('Seems like you are too weak for this task! you need to be level 200!', cid)

            elseif getPlayerVocation(cid) ~= 8 then
                selfSay('Sorry, you need to be an Elite knight with level 200 to start this task', cid)
            end

        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
end
---------------------------
if(msgcontains(msg, 'reborn paladin') or msgcontains(msg, 'rebirth paladin'))  then
        selfSay('Are you sure you want to Reset your vocation to start this Task?', cid)
        talkState[talkUser] = 3
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
        if(getPlayerVocation(cid) == 7 and getPlayerLevel(cid) == 200) then
        doPlayerSetVocation(cid, 0)
         doPlayerSetStorageValue(cid, 6011, 1)
          selfSay('While this task is open you have access to the spell EXORI NON, Your vocation has been removed, now you need to reach level 250, come back to me when you are done!', cid)

            elseif (getPlayerVocation(cid) == 7 and getPlayerLevel(cid) > 200) then
                selfSay('Seems like you are too strong already for this task! you need to be level 200!', cid)

            elseif (getPlayerVocation(cid) == 7 and getPlayerLevel(cid) < 200) then
                selfSay('Seems like you are too weak for this task! you need to be level 200!', cid)

            elseif getPlayerVocation(cid) ~= 7 then
                selfSay('Sorry, you need to be a Royal Paladin with level 200 to start this task', cid)
            end

        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
end
---------------------------
if(msgcontains(msg, 'reborn druid') or msgcontains(msg, 'rebirth druid')) then
        selfSay('Are you sure you want to Reset your vocation to start this Task?', cid)
        talkState[talkUser] = 4
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 4) then
        if(getPlayerVocation(cid) == 6 and getPlayerLevel(cid) == 200) then
        doPlayerSetVocation(cid, 0)
        doPlayerAddItem(cid, 12648 ,1)
         doPlayerSetStorageValue(cid, 6012, 1)
          selfSay('While this task is open you have access to the spell EXORI NON, Your vocation has been removed, now you need to reach level 250, come back to me when you are done!', cid)

            elseif (getPlayerVocation(cid) == 6 and getPlayerLevel(cid) > 200) then
                selfSay('Seems like you are too strong already for this task! you need to be level 200!', cid)

            elseif (getPlayerVocation(cid) == 6 and getPlayerLevel(cid) < 200) then
                selfSay('Seems like you are too weak for this task! you need to be level 200!', cid)

            elseif getPlayerVocation(cid) ~= 6 then
                selfSay('Sorry, you need an Elder Druid with level 200 to start this task', cid)
            end

        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
end
---------------------------

if(msgcontains(msg, 'reborn sorcerer') or msgcontains(msg, 'rebirth sorcerer')) then
        selfSay('Are you sure you want to Reset your vocation to start this Task?', cid)
        talkState[talkUser] = 5
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 5) then
        if(getPlayerVocation(cid) == 5 and getPlayerLevel(cid) == 200) then
        doPlayerSetVocation(cid, 0)
        doPlayerAddItem(cid, 12648, 1)
         doPlayerSetStorageValue(cid, 6013, 1)
          selfSay('While this task is open you have access to the spell EXORI NON, Your vocation has been removed, now you need to reach level 250, come back to me when you are done!', cid)
          talkState[talkUser] = 0

            elseif (getPlayerVocation(cid) == 5 and getPlayerLevel(cid) > 200) then
                selfSay('Seems like you are too strong already for this task! you need to be level 200!', cid)
                talkState[talkUser] = 0

            elseif (getPlayerVocation(cid) == 5 and getPlayerLevel(cid) < 200) then
                selfSay('Seems like you are too weak for this task! you need to be level 200!', cid)
                talkState[talkUser] = 0

            elseif getPlayerVocation(cid) ~= 5 then
                selfSay('Sorry, you need to be a Master Sorcerer with level 200 to start this task', cid)
                talkState[talkUser] = 0
            end

    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
end
---------------------------

if (msgcontains(msg, 'reborn') or msgcontains(msg, 'task') and getPlayerVocation(cid) == 0 and getPlayerLevel(cid) > 200 and getPlayerLevel(cid) < 250) then
        selfSay('you need to reach level 250 to end this Task, come back when you are stronger!', cid)
end

---------------------------

if (msgcontains(msg, 'reborn') or msgcontains(msg, 'task') and getPlayerVocation(cid) == 0 and getPlayerLevel(cid) >= 250 and getPlayerStorageValue(cid,6010) == 1 or getPlayerStorageValue(cid,6011) == 1 or getPlayerStorageValue(cid,6012) == 1  or getPlayerStorageValue(cid,6013) == 1)  then
        selfSay('Looks like you completed the task, are you ready to Reborn?', cid)
    talkState[talkUser] = 6
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 6 and getPlayerStorageValue(cid,6010)  == 1) then
        doPlayerSetVocation(cid, 8)
        doPlayerAddSkill(cid,1,20)
        doPlayerAddSkill(cid,2,20)
        doPlayerAddSkill(cid,3,20)
        doPlayerAddSkill(cid,5,20)
        doPlayerSetStorageValue(cid, 6014, 1)
selfSay('you completed the Task! you are an Elite Knight again and recieved bonus points on your skills', cid)
talkState[talkUser] = 0   

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6 and getPlayerStorageValue(cid,6011) == 1) then
        doPlayerSetVocation(cid, 7)
        doPlayerAddSkill(cid,4,20)
        doPlayerAddSkill(cid,5,15)
        doPlayerSetStorageValue(cid, 6014, 1)
selfSay('you completed the Task! you are a Royal Paladin again and recieved bonus points on your skills', cid)
talkState[talkUser] = 0   

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6 and getPlayerStorageValue(cid,6012) == 1) then
        doPlayerSetVocation(cid, 6)
        doPlayerAddSkill(cid,SKILL__MAGLEVEL,15)
        doPlayerAddSkill(cid,5,5)
        doPlayerSetStorageValue(cid, 6014, 1)
selfSay('you completed the Task! you are an Elder Druid again and recieved bonus points on your skills', cid)
talkState[talkUser] = 0   

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6 and getPlayerStorageValue(cid,6013) == 1)  then
        doPlayerSetVocation(cid, 5)
        doPlayerAddSkill(cid,SKILL__MAGLEVEL,15)
        doPlayerAddSkill(cid,5,5)
        doPlayerSetStorageValue(cid, 6014, 1)
selfSay('you completed the Task! you are a Master Sorcerer again and recieved bonus points on your skills', cid)
talkState[talkUser] = 0


    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)

    end

end

--------------------------------------

if (msgcontains(msg, 'reborn') or msgcontains(msg, 'task') or msgcontains(msg, 'rebirth') and getPlayerStorageValue(cid,6014) == 1) then
    selfSay('You already completed this Task! Leave something for the Noobs!', cid)
end

--------------------------------------

if msgcontains(msg, 'quest') then
    selfSay('Only promoted vocations are allowed on this quest, also, this quest is for level 150, ARE YOU READY?', cid)
    talkState[talkUser] = 7
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerVocation(cid) >= 5 and getPlayerLevel(cid) >= 150) then
        doPlayerSetStorageValue(cid, 6015, 1)
        selfSay('Some time ago I lost a valuable item of mine, If you can return it to me I will compensate you!, pssst! This is a little secret, but some statues serve as teleports, take a look at the Angel Statue at the top of the temple', cid)
        talkState[talkUser] = 0

    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerLevel(cid) >= 150 and getPlayerVocation(cid) < 5) then
        selfSay('You need to be promoted to start this quest', cid)
        talkState[talkUser] = 0

    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerLevel(cid) < 150 and getPlayerVocation(cid) >= 5) then
        selfSay('You need level 150 for this quest', cid)
        talkState[talkUser] = 0


    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)

    
    end
end

--------------------------------------
if msgcontains(msg, 'brooch') then
    selfSay('Oh, do you found my lost brooch?', cid)
    talkState[talkUser] = 8
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 8 and getPlayerStorageValue(cid,6016) == 1 and getPlayerItemCount(cid, 10140) >= 1)then
        if (getPlayerSex(cid) == 0 and getPlayerStorageValue(cid,6017) == -1) then
             doPlayerRemoveItem(cid, 10140, 1)
              doPlayerAddOutfit(cid, 370, 1)
             doPlayerAddOutfit(cid, 376, 1)
             doPlayerAddOutfit(cid, 377, 1)
             doPlayerAddOutfit(cid, 378, 1)
             doPlayerAddOutfit(cid, 379, 1)
             doPlayerAddOutfit(cid, 380, 1)
              doPlayerAddOutfit(cid, 382, 1)
             doPlayerSetStorageValue(cid, 6017, 1)
            selfSay('thank you so much, to compensate your good will I will gift you some fabulous outfits, check your outfit window!', cid)
            talkState[talkUser] = 0

        elseif (getPlayerSex(cid) == 1 and getPlayerStorageValue(cid,6018) == -1) then
             doPlayerRemoveItem(cid, 10140, 1)
              doPlayerAddOutfit(cid, 371, 1)
             doPlayerAddOutfit(cid, 372, 1)
             doPlayerAddOutfit(cid, 373, 1)
             doPlayerAddOutfit(cid, 374, 1)
             doPlayerAddOutfit(cid, 375, 1)
             doPlayerAddOutfit(cid, 381, 1)
             doPlayerSetStorageValue(cid, 6018, 1)
            selfSay('thank you so much, to compensate your good will I will gift you some fabulous outfits, check your outfit window!', cid)
            talkState[talkUser] = 0
        end


    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 8 and getPlayerStorageValue(cid,6016) == 1 and getPlayerItemCount(cid, 10140) < 1)then
        selfSay('looks like you completed the quest, but you need to bring me the brooch since I have a gift for you!', cid)
        talkState[talkUser] = 0

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 8 and getPlayerStorageValue(cid,6016) == -1 and getPlayerItemCount(cid, 10140) >= 1)then
        selfSay('looks like you didnt completed the quest, ask me for the quest and I will give you the information!', cid)
        talkState[talkUser] = 0

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 8 and getPlayerStorageValue(cid, 6017) == 1 and getPlayerSex(cid) == 0) then
         selfSay('My lady, you already gave me my lost brooch, do you remember, right?', cid)
         talkState[talkUser] = 0

    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 8 and getPlayerStorageValue(cid, 6018) == 1 and getPlayerSex(cid) == 1) then
         selfSay('My man, you already gave me my lost brooch, do you remember, right?', cid)
         talkState[talkUser] = 0


    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
         talkState[talkUser] = 0
         selfSay('Ok then.', cid)
    end

end

--------------------------------------


--------------------------------------
    return true
end


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

Attachments

Solution
You are placing the 'yes' statements inside of the other if statements.

Looking at 'quest'..

It's impossible for you to say 'yes' and get a responce, because you need to also say 'quest'.

For kicks and giggles, with your current npc try saying 'quest yes'.

Since your message both contains 'quest' and it also contains 'yes', your npc should work as expected.

So, the npc works.. just not as you want.

So you need to get all of those if statements on their own.

Typically inside of npc's you want to use an endless 'elseif' hierarchy, so that only 1 thing ever happens.

your old code.
Lua:
if msgcontains(msg, 'quest') then
    selfSay('Only promoted vocations are allowed on this quest, also, this quest is for level 150, ARE YOU READY?'...
You are placing the 'yes' statements inside of the other if statements.

Looking at 'quest'..

It's impossible for you to say 'yes' and get a responce, because you need to also say 'quest'.

For kicks and giggles, with your current npc try saying 'quest yes'.

Since your message both contains 'quest' and it also contains 'yes', your npc should work as expected.

So, the npc works.. just not as you want.

So you need to get all of those if statements on their own.

Typically inside of npc's you want to use an endless 'elseif' hierarchy, so that only 1 thing ever happens.

your old code.
Lua:
if msgcontains(msg, 'quest') then
    selfSay('Only promoted vocations are allowed on this quest, also, this quest is for level 150, ARE YOU READY?', cid)
    talkState[talkUser] = 7
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerVocation(cid) >= 5 and getPlayerLevel(cid) >= 150) then
        doPlayerSetStorageValue(cid, 6015, 1)
        selfSay('Some time ago I lost a valuable item of mine, If you can return it to me I will compensate you!, pssst! This is a little secret, but some statues serve as teleports, take a look at the Angel Statue at the top of the temple', cid)
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerLevel(cid) >= 150 and getPlayerVocation(cid) < 5) then
        selfSay('You need to be promoted to start this quest', cid)
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 7 and getPlayerLevel(cid) < 150 and getPlayerVocation(cid) >= 5) then
        selfSay('You need level 150 for this quest', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
end

with elseif hierarchy
Lua:
-- top of script
if msgcontains(msg, "reborn knight") or msgcontains(msg, "rebirth knight") then

-- .
-- .
-- .

elseif msgcontains(msg, "quest") then
    selfSay("Only promoted vocations are allowed on this quest, also, this quest is for level 150, ARE YOU READY?", cid)
    talkState[talkUser] = 7
 
elseif(msgcontains(msg, "yes") and talkState[talkUser] == 7 then
    local text = ""
    if getPlayerVocation(cid) < 5 then
        text = "You need to be promoted "
    end
    if getPlayerLevel(cid) < 150) then
        text = text .. "" .. (text == "" and "You need to be " or "and ") .. "level 150 "
    end
    if text ~= "" then
        text = text .. "to start this quest."
    else
        text = "Some time ago I lost a valuable item of mine, If you can return it to me I will compensate you!, pssst! This is a little secret, but some statues serve as teleports, take a look at the Angel Statue at the top of the temple"
        doPlayerSetStorageValue(cid, 6015, 1)
    end
    selfSay(text, cid)
    talkState[talkUser] = 0
 
elseif(msgcontains(msg, "no") and isInArray({1}, talkState[talkUser])) then
    selfSay("Ok then.", cid)
    talkState[talkUser] = 0

-- .
-- .
-- .

    -- bottom of script
    return true
end
 
Solution
@Xikini thank you!

I was thinking exactly about that when I woke up
looking at another old post I made some months ago and it has basically the same structure as you say (@Evil Puncker helped me that time lol)

I think the problem lies (basically) here:

change this :
Lua:
    if(msgcontains(msg, 'yes') and talkState[talkUser] == 7 ………………...

to this:
Lua:
   elseif(msgcontains(msg, "yes") and talkState[talkUser] == 7 ...…………………..

I will try tonight or tomorrow if it works :)
 
Last edited:
Back
Top