• 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 Oracleish NPC not working

Azze19

Solo developer
Joined
Jul 4, 2014
Messages
75
Reaction score
23
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

local Topic = {}
local vocStr = {Squire, Archer}
local vocNum = {4, 6}
local voc = 0

function thinkCallback(cid)
if math.random(300) == 1 then
npcHandler:say("Join the Guard today!")
end
return true
end

-- Set the greeting callback function
npcHandler:setCallback(CALLBACK_GREET, greetcallback)

function greetcallback(cid, type, msg)
    if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
        if (getPlayerVocation(cid)) == 0 then -- checks if player has no vocation and offers enrollment
            npcHandler:say("Ah! Hiho! |PLAYERNAME|. I see you haven't chosen a career path, the guard has open positions, would you like to {enroll}?", cid)
            npcHandler:addFocus(cid)
            Topic[cid] = 0
            while Topic[cid] == 0 do
                if (msgcontains(msg, "enroll") or msgcontains(msg, "yes") and Topic[cid]) == 0 then
                    npcHandler:say ("Oh, so you want to enroll to the guard, yes?", cid)
                    if (msgcontains (msg, "yes")) then
                        Topic[cid] = 1
                    elseif (msgcontains (msg, "no")) then
                        npcHandler:say ("That's a shame!", cid)
                    else
                        npcHandler:say ("What was that?", cid)
                    end
                elseif (Topic[cid] == 1) then
                    npcHandler:say ("Very well. Here at the guard we have to branches, {melee} fighters and {distance} fighters; What would you like to specialize in?", cid)
                    if (msgcontains (msg, "melee")) then
                        voc = 1
                        assgnvoc(cid)
                    elseif (msgcontains (msg, "distance")) then
                        voc = 2
                        assgnvoc(cid)
                    else
                        npcHandler:say ("What was that?", cid)
                        Topic[cid] = 0
                    end                  
                elseif (Topic[cid] == 0) then
                    npcHandler:say ("So, how may I help you?", cid)
                end      
            end  
        elseif (getPlayerVocation(cid) ~= vocNum) then -- gives custom greet to those who do not belong to the guard
            npcHandler:say("Hi, |PLAYERNAME|. Welcome to the Guard HQ. How may I help you?", cid)
            npcHandler:addFocus(cid)
        elseif (getPlayerVocation(cid) == vocNum and Topic[cid] == 0) then  -- welcomes back to members of the guard
            npcHandler:say("Hello, welcome back |PLAYERNAME|.", cid)
            npcHandler:addFocus(cid)
        end
    end
end

function assgnvoc(cid)
    doPlayerSetVocation(cid, vocNum[voc])
    npcHandler:say ("Alright, you are now a .. vocStr[voc].. for the guard.", cid)
    npcHandler:say ("There's some more stuff I should teach you before you leave, do you want me to give you a short tutorial?", cid)
    if (msgcontains (msg, "yes")) then
        npcHandler:say ("Great! let's begin!", cid)
        if (vocation == 1) then
            tutorial(cid)
            tutorialmelee(cid)
            tutorialheal(cid)
        else
            tutorial(cid)
            tutorialheal(cid)
        end
        npcHandler:say ("From now on you can ask for {missions} to me or Warden Finduin.", cid)
    else
        npcHandler:say ("Are you sure? This information is quite important...", cid)
        if msgcontains (msg, "yes") then
            npcHandler:say ("That's a shame, but as you wish. From now on you can ask for {missions} to me or Warden Finduin.", cid)
            Topic[cid] = 0
        else
            npcHandler:say ("Great! let's begin!", cid)
            tutorial(cid)
        end  
    end
end

function tutorial(cid)
    npcHandler:say("Very well. First of all, if you want to walk faster, you just need to {<dash>}, got it?", cid)
        if msgcontains(msg, "yes") then
            npcHandler:say("Good! moving on...", cid)
        elseif msgcontains(msg, "no") then
            npcHandler:say("No worries, just say {<dash>} to focus your energy and you'll walk faster. Ok?", cid)
        end
end
  
function tutorialmelee(cid)
    npcHandler:say("Now that you've learnt how to focus your energy to dash, let's see how you {<strike>}, got it?", cid)
        if msgcontains(msg, "yes") then
            npcHandler:say("Excellent! You're a fast learner!", cid)
        elseif msgcontains(msg, "no") then
            npcHandler:say("I see. Just like dashing, to make a good hit, you need to focus by saying {<strike>} and your target will receive a good blow! Alrite?", cid)
        end
end

function tutorialheal(cid)
     npcHandler:say("We're almost done so hang in there with me. Last but not least, I'm gonna show you how can you regain health. You can either {<apply bandage>}, but that will obviously require that you are carrying bandages with you; or you can pray to our Almighty 'El' to heal you, just repeat after me {I placito gratia habituali sanante}, Ok?", cid)
        if msgcontains(msg, "yes") then
            npcHandler:say("Nice! We're done now, it wasn't so bad, was it? You can keep coming to me to show you new techniqes, you just need to get {experience}", cid)
        elseif msgcontains(msg, "no") then
            npcHandler:say("It's OK, to be able to {<apply bandage>} you must be sure you have an available bandage in your backpack, else it won't work. For the prayer, you have to say {I placito gratia habituali sanante}, but you must have the required energy to do so, Alright? See? it didn't take me so long after all! Haha!")
        end
end

-- npc answer to keyword "job"
local jobNode = keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the commander of the royal guard, my job is to overlook the safety of our citizens and {enroll} new recruits to man the guard.'})
  
-- npc answer to keyword "information"
local infoNode = keywordHandler:addKeyword({'information'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Here at the guard we employ {Melee} and {Distance} fighters only.'})

-- npc answer to keyword "mission"
local missionNode = keywordHandler:addKeyword ({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'There are no new missions at this moment, come back later.'})


npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:addModule(FocusModule:new())

This NPC assigns the vocation Squire and Archer (with subsequents promotions) however the function greetcallback is not working, when the player says 'hi' the NPC only answers "greetings |PLAYERNAME|". Anyone has any idea where I went wrong?

Edit: the console shows no error when running the script.
 
@Slavi Dodo that's the problem, the server's console shows no error when running the script, the only way I know it's not working is because the NPC is not doing what is intended.
 
Last edited:
Not really 100% sure, but I think this might work.
Code:
npcHandler:say("Ah! Hiho! " ..cid:getName().. ". I see you haven't chosen a career path, the guard has open positions, would you like to {enroll}?", cid)
 
Back
Top