• 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!

Npc system

Console Error
Imgur: The most awesome images on the Internet
Npc script
LUA:
dofile(getDataDir() .. 'global/greeting.lua')

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local fire = createConditionObject(CONDITION_FIRE)
setConditionParam(fire, CONDITION_PARAM_DELAYED, 10)
addDamageCondition(fire, 450, 3000, -10)

-- OTServ event handling functions start
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


keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "My name is Adrenius."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm a priest of Fafnar."})
keywordHandler:addKeyword({'fafnar'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Fafnar is the stronger one of the two suns above our world."})
keywordHandler:addKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Yyyyess. Yes, it's the capital city of Tibia I think."})
keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Carlin? Don't you mean Thais?"})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Who needs a king? I don't."})
keywordHandler:addKeyword({'weapon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Who needs weapons? I never had and i never will have weapons - what for?"})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Help? Help? Nothing more? Don't we all demand some help?"})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Time? What is time? A word? A thing? An object?"})
keywordHandler:addKeyword({'sword'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Swords? Don't you have something else to do?"})
keywordHandler:addKeyword({'desert'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Sand, sand and again sand. Sand all over. Yes, I'd say: it's truly a desert!"})
keywordHandler:addKeyword({'excalibug'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "What's that? You start annoying me."})
keywordHandler:addKeyword({'fight'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Leave me alone. I don't want to fight."})
keywordHandler:addKeyword({'god'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Fafnar is the greatest among the gods."})
keywordHandler:addKeyword({'way'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Way? Which way? I forgot where most ways go to... excuse me."})
keywordHandler:addKeyword({'door'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Who needs doors? Free your mind!"})
keywordHandler:addKeyword({'secret'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Secrets ... What do you mean?"})
keywordHandler:addKeyword({'treasure'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Treasures? What is a treasure for you?"})
keywordHandler:addKeyword({'book'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Read books, it increases your intelligence and, furthermore, it's a great source of inspiration!"})
keywordHandler:addKeyword({'gharonk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Hmmmm... I don't know much about it."})
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can offer you religion and mysticism."})
keywordHandler:addKeyword({'library'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I heard of the library, but I never was very interested in it."})


function creatureSayCallback(cid, type, msg) msg = string.lower(msg)
    if(npcHandler.focus ~= cid) then
        return false
    end
if msgcontains(msg, 'netlios') or msgcontains(msg, 'Netlios') then
    NPCSay("This fool! His book is nothing but a hoax! At least I believe that. Or did you find an answer for my questions?", 1)
    adrenius_talk_state = 1
   
   
elseif adrenius_talk_state == 1 and msgcontains(msg, 'yes') or adrenius_talk_state == 1 and msgcontains(msg, 'Yes') then
    NPCSay("By the way, I would like a donation for my temple. Are 500 gold ok?", 1)
    adrenius_talk_state = 2
elseif adrenius_talk_state == 1 and msgcontains(msg, 'no') or adrenius_talk_state == 1 and msgcontains(msg, 'No') then
    NPCSay("Oh. So once again I am proved right.", 1)
    adrenius_talk_state = 0
elseif adrenius_talk_state == 1 and msgcontains(msg, '') then
    NPCSay("You can't even say 'yes' or 'no'. You are not worth talking to me!", 1)
    adrenius_talk_state = 0
    npcHandler:releaseFocus()
    npcHandler:resetNpc()   
   
elseif adrenius_talk_state == 2 and msgcontains(msg, 'yes') or adrenius_talk_state == 2 and msgcontains(msg, 'Yes') then
    if doPlayerRemoveMoney(cid, 500) == TRUE then
    NPCSay("Thank you very much. Now, name me the first person in alphabetical order, his age, his fate, and how long he was on his journeys!", 1)
    adrenius_talk_state = 4   
    else
    NPCSay("You want to fool me? May Fafnar burn your soul!", 1)
    doSendMagicEffect(getCreaturePosition(getNpcCid(  )), 13)
    doSendMagicEffect(getPlayerPosition(cid), 15)
    doAddCondition(cid, fire)
    adrenius_talk_state = 0   
    end
elseif adrenius_talk_state == 2 and msgcontains(msg, '') then
    NPCSay("Then I don't want to talk to you.", 1)
    adrenius_talk_state = 0
    npcHandler:releaseFocus()
    npcHandler:resetNpc()

elseif adrenius_talk_state == 4 and msgcontains(msg, 'anaso') and msgcontains(msg, '41') and msgcontains(msg, 'mother') and msgcontains(msg, '117') or adrenius_talk_state == 4 and msgcontains(msg, 'Anaso') and msgcontains(msg, '41') and msgcontains(msg, 'Mother') and msgcontains(msg, '117') then
    NPCSay("Hmmm, maybe. What can you tell me about the second 'adventurer'?", 1)
    adrenius_talk_state = 5
elseif adrenius_talk_state == 4 and msgcontains(msg, '') then
    NPCSay("No, sorry, that doesn't sound correct to me. Maybe you should reconsider your words one more time...", 1)
    adrenius_talk_state = 4

elseif adrenius_talk_state == 5 and msgcontains(msg, 'elaeus') and msgcontains(msg, '39') and msgcontains(msg, 'dragon') and msgcontains(msg, '100') or adrenius_talk_state == 5 and msgcontains(msg, 'Elaeus') and msgcontains(msg, '39') and msgcontains(msg, 'Dragon') and msgcontains(msg, '100') then
    NPCSay("Yes, that might be true. What did you find out about the third man?", 1)
    adrenius_talk_state = 6
elseif adrenius_talk_state == 5 and msgcontains(msg, '') then
    NPCSay("No, no, no! Think about it, that simply can't be true!", 1)
    adrenius_talk_state = 5

elseif adrenius_talk_state == 6 and msgcontains(msg, 'gadinius') and msgcontains(msg, '42') and msgcontains(msg, 'fire') and msgcontains(msg, '83') or adrenius_talk_state == 6 and msgcontains(msg, 'Gadinius') and msgcontains(msg, '42') and msgcontains(msg, 'Fire') and msgcontains(msg, '83') then
    NPCSay("Correct again! Hmmmm... I doubt you know anything about the fourth person!", 1)
    adrenius_talk_state = 7
elseif adrenius_talk_state == 6 and msgcontains(msg, '') then
    NPCSay("Hmmmm... well, no. That is not true, it does not fit to the data provided by the books.", 1)
    adrenius_talk_state = 6

elseif adrenius_talk_state == 7 and msgcontains(msg, 'heso') and msgcontains(msg, '40') and msgcontains(msg, 'troll') and msgcontains(msg, '66') or adrenius_talk_state == 7 and msgcontains(msg, 'Heso') and msgcontains(msg, '40') and msgcontains(msg, 'Troll') and msgcontains(msg, '66') then
    NPCSay("Yes! Really, how did you figure that out? I bet, you don't know anything about the last adventurer!", 1)
    adrenius_talk_state = 8
elseif adrenius_talk_state == 7 and msgcontains(msg, '') then
    NPCSay("No, sorry. Incorrect...", 1)
    adrenius_talk_state = 7
   
elseif adrenius_talk_state == 8 and msgcontains(msg, 'hestus') and msgcontains(msg, '38') and msgcontains(msg, 'poison') and msgcontains(msg, '134') or adrenius_talk_state == 8 and msgcontains(msg, 'Hestus') and msgcontains(msg, '38') and msgcontains(msg, 'Poison') and msgcontains(msg, '134') then
    NPCSay("That's right! Why didn't I see it? It's obvious, Netlios was right, and his stories are great! Wait, I'll give you something!", 1)
    DESERTTPROOM = doPlayerAddItem(cid, 2088, 1)
    doSetItemActionId(DESERTTPROOM, 2016)
    doSetItemSpecialDescription(DESERTTPROOM, "(Key: 4023)")
    adrenius_talk_state = 0
elseif adrenius_talk_state == 8 and msgcontains(msg, '') then
    NPCSay("Well, and again it was shown: I am right and Netlios is wrong!", 1)
    adrenius_talk_state = 8
   
end       
    return 1
end


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
OTHER NPC TEST
Imgur: The most awesome images on the Internet

NPC XML
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Captain Seahorse" script="data/npc/scripts/barco_edron.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="129" head="19" body="113" legs="95" feet="115" addons="0"/>
<voices>
<voice text="Passages to Thais, Carlin, Ab'Dendriel, Venore, Ankrahmun." interval2="100" margin="1" yell="no"/>
</voices>
<parameters>
<parameter key="message_farewell" value="Good bye. Recommend us if you were satisfied with our service." />
<parameter key="message_walkaway" value="Good bye. Recommend us if you were satisfied with our service." />
 <parameter key="module_keywords" value="1" />
 <parameter key="keywords" value="name;edron;" />
 <parameter key="keyword_reply1" value="My name is Captain Seahorse from the Royal Tibia Line." />
 <parameter key="keyword_reply2" value="This is Edron. Where do you want to go?" />
 <parameter key="message_greet" value="Welcome on board, |PLAYERNAME|. Where may I sail you today?"/>
</parameters>
</npc>

NPC SCRIPT
LUA:
local keywordHandler = KeywordHandler:new()
        local npcHandler = NpcHandler:new(keywordHandler)
        NpcSystem.parseParameters(npcHandler)
       
       
       
        -- OTServ event handling functions start
        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
        -- OTServ event handling functions end
 local function creatureSayCallback(cid, type, msg)
   
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    if (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'carlin') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 110) == TRUE then
        doTeleportThing(cid,{x=32387, y=31820, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'ab\'dendriel') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 70) == TRUE then
        doTeleportThing(cid,{x=32734, y=31669, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end       
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'thais') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 160) == TRUE then
        doTeleportThing(cid,{x=32313, y=32212, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'venore') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 40) == TRUE then
        doTeleportThing(cid,{x=32954, y=32022, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'ankrahmun') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 160) == TRUE then
        doTeleportThing(cid,{x=33092, y=32883, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'cormaya') and (not npcHandler:isFocused(cid))) then
        if doPlayerRemoveMoney(cid, 20) == TRUE then
        doTeleportThing(cid,{x=33288, y=31956, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end       
    elseif (msgcontains(msg, 'bring') and msgcontains(msg, 'me') and msgcontains(msg, 'to') and msgcontains(msg, 'port') and msgcontains(msg, 'hope') and (not npcHandler:isFocused(cid))) then
    if isPremium(cid) == TRUE then
        if doPlayerRemoveMoney(cid, 150) == TRUE then
        doTeleportThing(cid,{x=32532, y=32784, z=7})
        npcHandler:addFocus(cid)
        else 
         selfSay('Sorry, you don\'t have enough money.') 
        end
       end   
    end
    return true
end         
       
        -- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
    local travelNode = keywordHandler:addKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you seek a passage to Thais for 160 gold coins?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 160, destination = {x=32313, y=32212, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})

    local travelNode = keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to sail to Carlin for 110 gold coins?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 0, destination = {x=32387, y=31820, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
       
    local travelNode = keywordHandler:addKeyword({'ab\'dendriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to sail to Ab\'dendriel for 70 gold coins?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 0, destination = {x=32734, y=31668, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
                   
    local travelNode = keywordHandler:addKeyword({'venore'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to sail to Venore for 40 gold coins?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 40, destination = {x=32954, y=32022, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
       
    local travelNode = keywordHandler:addKeyword({'ankrahmun'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you seek a passage to Ankrahmun for 160 gold coins?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 160, destination = {x=33092, y=32883, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
   
    local travelNode = keywordHandler:addKeyword({'cormaya'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you seek a passage to Cormaya?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 20, destination = {x=33288, y=31956, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
           
    local travelNode = keywordHandler:addKeyword({'port hope'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you seek a passage to port hope?'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 150, destination = {x=32532, y=32784, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})

        keywordHandler:addKeyword({'sail'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Where do you want to go? To Thais, Carlin, Ab\'Dendriel, Venore, Ankrahmun or the isle Cormaya?'})
        keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this sailing ship.'})
        keywordHandler:addKeyword({'captain'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this sailing ship.'})
       
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
        npcHandler:addModule(FocusModule:new())
 
Back
Top