• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Two small NPC issues

Thaian Citizen

Hexenjäger
Joined
Apr 5, 2013
Messages
144
Solutions
4
Reaction score
17
Location
germany
Now I think these issues are quite easy to fix, yet I can't figure it out myself...

I am using crying damson version of TFS 0.3.6 -8.60 server that was posted by Printer~

The first (My own oracle npc, I know its not an optimum script but I try to do as much as I can by myself from scratch, the problem is, whenever I talk to him he also does the last else action and tells me "I can't understand you. Could you speak clearly?!" he does say this in addition to the right keyword respond, the npc code:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local destiny = { vocation = {}, city = {} }

local towns = {
    ["celestial village"] = { id = 2, x=9651, y=10270, z=6 }
}

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

npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. Are you prepared to face your destiny?')

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 msg == "yes" then
        if (getPlayerLevel(cid) < 8) then
            selfSay("You are not ready if you are below level 8!", cid)
            npcHandler:releaseFocus(cid)
        else
            if (not getPlayerVocation(cid) == 0) then
                selfSay("You already have a vocation!", cid)
                npcHandler:releaseFocus(cid)
            else
                selfSay("Then tell me your occupation.. Do you want to be a {knight}, {paladin}, {sorcerer} or {druid}?!", cid)
                talkState[talkUser] = 1
            end
        end
    elseif msg == "no" then
        selfSay("Well don't waste my time then..", cid)
        npcHandler:releaseFocus(cid)
    end
   
    if msg == "knight" and talkState[talkUser] == 1 then
        selfSay("So you want to be a {knight}, are you sure?", cid)
        destiny.vocation = "knight"
        talkState[talkUser] = 2
    elseif msg == "paladin" and talkState[talkUser] == 1 then
        selfSay("So you want to be a {paladin}, are you sure?", cid)
        destiny.vocation = "paladin"
        talkState[talkUser] = 2
    elseif msg == "sorcerer" and talkState[talkUser] == 1 then
        selfSay("So you want to be a {sorcerer}, are you sure?", cid)
        destiny.vocation = "sorcerer"
        talkState[talkUser] = 2
    elseif msg == "druid" and talkState[talkUser] == 1 then
        selfSay("So you want to be a {druid}, are you sure?", cid)
        destiny.vocation = "druid"
        talkState[talkUser] = 2
    end
   
    if msg == "yes" and talkState[talkUser] == 2 then
        selfSay("Ok, you will become a "..destiny.vocation.."..", cid)
        if isPremium(cid) then
            selfSay("Where do you want me to bring you? {Celestial Village}, ......", cid, true)
        else
            selfSay("Where do you want me to bring you? Example, ......", cid, true)
        end
        talkState[talkUser] = 3
    elseif msg == "no" and talkState[talkUser] == 2 then
        selfSay("Then think about it and come back when you are sure..", cid)
        destiny.vocation = {}
        talkState[talkUser] = {}
    end
   
    if msg == "celestial village" and talkState[talkUser] == 3 then
        if isPremium(cid) then
            selfSay("Celestial Village, huh?! Is that where you want to go?", cid)
            destiny.city = "Celestial Village"
        else
            selfSay("I am not allowed to bring you there if you don't have premium access..", cid)
            destiny.vocation = {}
            talkState[talkUser] = {}
            npcHandler:releaseFocus(cid)
        end
        talkState[talkUser] = 4
    end
   
    if msg == "yes" and talkState[talkUser] == 4 then
        selfSay("Arrr, let's sail!", cid)
       
        if destiny.vocation == 'sorcerer' then
            doPlayerSetVocation(cid, 1)
        elseif destiny.vocation == 'druid' then
            doPlayerSetVocation(cid, 2)
        elseif destiny.vocation == 'paladin' then
            doPlayerSetVocation(cid, 3)
        else
            doPlayerSetVocation(cid, 4)
        end
   
        local toGo = towns[destiny.city:lower()]
        doPlayerSetTown(cid, toGo.id)
   
        local destination = { x = toGo.x, y = toGo.y, z = toGo.z }
   
        local tmp = getCreaturePosition(cid)
        doTeleportThing(cid, destination)
        doSendMagicEffect(tmp, CONST_ME_POFF)
        doSendMagicEffect(destination, CONST_ME_TELEPORT)
       
        destiny.vocation = {}
        destiny.city = {}
        talkState[talkUser] = {}
        npcHandler:releaseFocus(cid)
    elseif msg == "no" and talkState[talkUser] == 4 then
        selfSay("GOD DAMN! CAN YOU FINALLY DECIDE WHAT YOU WANT?!", cid)
        destiny.vocation = {}
        destiny.city = {}
        talkState[talkUser] = {}
        npcHandler:releaseFocus(cid)
    else
        selfSay("I can't understand you. Could you speak clearly?!", cid)
        destiny.vocation = {}
        destiny.city = {}
        talkState[talkUser] = {}
        npcHandler:releaseFocus(cid)
    end
   
    return true
end

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

Another problem I have is when i make shop npcs I regularly work with the default.lua and write the npc in xml.. but if you use the default responds of the npc or replacements of the default keywords the npc will always say it in default chat instead of npc chat, I know that you need cid at last parameter in your lua script for the npc to say that sentence in npc chat but i dont know what exactly to replace in the modules/npchandler or whatever lua

would be nice if someone can help with these
and sry for my weak formulation, im kinda exhausted..
 
Use elseif for all msg checks, so not: if, elseif, end, if, elseif, elseif, elseif, end, if, elseif, end, if, end, if, elseif, else, end
But like this: if, elseif, elseif, elseif, elseif, elseif, elseif, elseif, elseif, elseif, elseif, else, end

If you make a new if statement, it will look if that one is (also) true even if one of the other statements is already true and will do the else part if not, by using elseif it will skip the rest if 1 of them is true.

Btw, instead of having more statents for the same word, better check for the talkstate under that word, so 1 msg line for yes and 1 msg line for no.
There is also this.
Code:
if msg == "yes" then
This is always true if someone says yes, so it won't respond on the other statements with yes.
So what you can do is add a check for talkstate in that line or add all talkstate if/elseif statements under 1 line with yes/no and remove the other yes/no msg statements.
http://otland.net/threads/npc-mission.211063/#post-2022375
 
Last edited:
Ah yeah that makes sense, I will change it to that.. that tutorial is nice, I wrote a task system using the tutorial mission part as inspiration, fully working without problems, thanks
 
Back
Top