• 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 Make NPC not to answer to "Hi" or "Hello"

Misterion

New Member
Joined
Jan 24, 2014
Messages
52
Reaction score
4
Hi and Hello everybody hahahaha!

So, I've wondering, since my desire is to make a very different NPC that's not human, just like the Blind Guard in Rookgard or even King Tibianus. I've downloaded some NPCs from global 8.6 server but the NPCs still answer me when I say Hi or Hello, even if it's not the appropriate word to talk to them.

Here's the XML and the NPC script:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="King Tibianus" script="data/npc/scripts/King Tibianus.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="332" head="21" body="87" legs="107" feet="95" addons="0"/>
<parameters>
       <parameter key="message_greet" value="I greet thee, my loyal subject |PLAYERNAME|."/>
        <parameter key="message_farewell" value="Good bye, |PLAYERNAME|"/>
        <parameter key="message_walkaway" value="Good bye, |PLAYERNAME|" />
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="job;king;" />
        <parameter key="keyword_reply1" value="I am your sovereign, King Tibianus III, and it's my duty to uphold justice and provide guidance for my subjects." />
        <parameter key="keyword_reply2" value="I am the king, so watch what you say!" />
    </parameters>

</npc>

Script:
Lua:
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 node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to be promoted in your vocation?'})
    node1:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You are already promoted'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Okay then..', reset = true})
--[[
local node2 = keywordHandler:addKeyword({'epic'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can epicize you for 200000 gold coins. Do you want me to epicize you?'})
    node2:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 200000, level = 120, promotion = 2, text = 'Congratulations! You are now epicized.'})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
]]--

npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Solution
I personally find it fairly simple to create NPCs using the example82.lua as a template.
example82

If you scroll down to the onCreatureSay function
where it says
Lua:
if((msg == "hi") and not (isFocused(cid))) then
you can change it to something like
Lua:
local greetings = {"hi king", "hail king", "greetings", "good day"}
if isInArray(greetings, msg) and not isFocused(cid) then
You can simply add a new greet message on focus in King Tibianus.lua:

Lua:
local focusModule = FocusModule:new()
focusModule:addGreetMessage('hail king')
focusModule:addGreetMessage('salutations king')
npcHandler:addModule(focusModule)

The lua file should be like this:
Lua:
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 node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to be promoted in your vocation?'})
    node1:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You are already promoted'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Okay then..', reset = true})
--[[
local node2 = keywordHandler:addKeyword({'epic'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can epicize you for 200000 gold coins. Do you want me to epicize you?'})
    node2:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 200000, level = 120, promotion = 2, text = 'Congratulations! You are now epicized.'})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
]]--

-- npcHandler:addModule(FocusModule:new())
local focusModule = FocusModule:new()
focusModule:addGreetMessage('hail king')
focusModule:addGreetMessage('salutations king')
npcHandler:addModule(focusModule)

We have removed here the normal focus module (you can remove this line from the code above if you want):
Lua:
-- npcHandler:addModule(FocusModule:new())
 
Last edited:
Oh God! I've forgotten to quote that I'm using TFS 0.3.6 Crying Damson (old, just like my Otserver). I suppose that those functions you told me to add are only usable in newer versions of TFS, right?
 
Oh God! I've forgotten to quote that I'm using TFS 0.3.6 Crying Damson (old, just like my Otserver). I suppose that those functions you told me to add are only usable in newer versions of TFS, right?
You could always try, right? And if didn't work you could give us the errors.

(But yes, you are right, you should mention the server version, always)
 
You could always try, right? And if didn't work you could give us the errors.

(But yes, you are right, you should mention the server version, always)
I've tried. Here's the error:

Lua:
Description:
data/npc/scripts/arcoshaal.lua:21: attempt to call method 'addGreetMessage' (a nil value)
[Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/arcoshaal.lua

the script wont load!

you just have to go to npc folders and edit where it's say "hi" in the folder by some word that you want..
I would change all the NPCs if I do that, so I want to do it singularly to a specific NPC.
 
Here is a other way of doing it.
It have some problem whit the update focus timer i mean after 1,5min the npc would ungreet you even if you type stuff to the npc.

Lua:
-- File generated by Npc Converter v0.5
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local Price = {}

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) and msgcontains(msg, "abcdefghijklmnopqrstuvwxyzåäö$")) then  -- ignore this
   elseif (not npcHandler:isFocused(cid) and (msgcontains(msg, "hello king") or msgcontains(msg, "hail king") or msgcontains(msg, "salutations king"))) then
       npcHandler:addFocus(cid)
       npcHandler:say("I greet thee, my loyal subject.", cid)
       npcHandler:say("I greet thee, my loyal subject.")
       Topic[cid] = nil
       return true
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and getPlayerVocation(cid) > 4 and (msgcontains(msg, "yes"))) then
       npcHandler:say("You are already promoted.", cid)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and getPlayerLevel(cid) < 20 and (msgcontains(msg, "yes"))) then
       npcHandler:say("You need to be at least level 20 in order to be promoted.", cid)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and getPlayerMoney(cid) < Price[cid] and (msgcontains(msg, "yes"))) then
       npcHandler:say("You do not have enough money.", cid)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and isPremium(cid) and (msgcontains(msg, "yes"))) then
       doPlayerRemoveMoney(cid, Price[cid])
       Price[cid] = nil
       npcHandler:say("Congratulations! You are now promoted. Visit the sage Eremo for new spells.", cid)
       local promote = getPlayerVocation(cid) + 4
       doPlayerSetVocation(cid, promote)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and (msgcontains(msg, "yes"))) then
       npcHandler:say("You need a premium account in order to promote.", cid)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 4 and (not msgcontains(msg, "this is a when you dont say yes or no$"))) then
       npcHandler:say("Ok, then not.", cid)
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "bye") or msgcontains(msg, "farewell"))) then
       npcHandler:say("Good bye, " .. getCreatureName(cid) .. "!", cid)
       Topic[cid] = nil
       npcHandler:releaseFocus(cid)
       return true
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "job"))) then
       npcHandler:say("I am your sovereign, King Tibianus III, and it's my duty to provide justice and guidance for my subjects.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "justice"))) then
       npcHandler:say("I try my best to be just and fair to our citizens. The army and the TBI are a great help for fulfilling this duty.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "name"))) then
       npcHandler:say("It's hard to believe that you don't know your own king!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "news"))) then
       npcHandler:say("The latest news are usually brought to our magnificent town by brave adventurers. They spread tales of their journeys at Frodo's tavern.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "tibia") or msgcontains(msg, "land"))) then
       npcHandler:say("Soon the whole land will be ruled by me once again!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "how are you"))) then
       npcHandler:say("Thank you, I'm fine.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "castle"))) then
       npcHandler:say("Rain Castle is my home.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "sell"))) then
       npcHandler:say("Sell? Sell what? My kingdom isn't for sale!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "god"))) then
       npcHandler:say("Honor the gods and pay your taxes.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "zathroth"))) then
       npcHandler:say("Please ask a priest about the gods.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "citizen"))) then
       npcHandler:say("The citizens of Tibia are my subjects. Ask the old monk Quentin to learn more about them.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "sam"))) then
       npcHandler:say("He is a skilled blacksmith and a loyal subject.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "frodo"))) then
       npcHandler:say("He is the owner of Frodo's Hut and a faithful tax-payer.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "gorn"))) then
       npcHandler:say("He was once one of Tibia's greatest fighters. Now he is selling equipment.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "benjamin"))) then
       npcHandler:say("He was once my greatest general. Now he is very old and senile but we entrusted him with work for the Royal Tibia Mail.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "harkath") or msgcontains(msg, "bloodblade") or msgcontains(msg, "general"))) then
       npcHandler:say("Harkath Bloodblade is the general of our glorious army.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "noodles"))) then
       npcHandler:say("The royal poodle Noodles is my greatest treasure!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "ferumbras"))) then
       npcHandler:say("He is a follower of the evil god Zathroth and responsible for many attacks on us. Kill him on sight!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "bozo"))) then
       npcHandler:say("He is my royal jester and cheers me up now and then.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "treasure"))) then
       npcHandler:say("The royal poodle Noodles is my greatest treasure!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "monster"))) then
       npcHandler:say("Go and hunt them! For king and country!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "help"))) then
       npcHandler:say("Visit Quentin, the monk, for help.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "quest") or msgcontains(msg, "mission"))) then
       npcHandler:say("I will call for heroes as soon as the need arises again and then reward them appropriately.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "gold") or msgcontains(msg, "money") or msgcontains(msg, "tax"))) then
       npcHandler:say("To pay your taxes, visit the royal tax collector.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "sewer"))) then
       npcHandler:say("What a disgusting topic!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "dungeon"))) then
       npcHandler:say("Dungeons are no places for kings.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "equipment"))) then
       npcHandler:say("Feel free to buy it in our town's fine shops.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "food"))) then
       npcHandler:say("Ask the royal cook for some food.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "time") or msgcontains(msg, "heroes") or msgcontains(msg, "hero$") or msgcontains(msg, "adventurer"))) then
       npcHandler:say("It's a time for heroes, that's for sure!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "tax collector"))) then
       npcHandler:say("He has been lazy lately. I bet you have not payed any taxes at all.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "king"))) then
       npcHandler:say("I am the king, so mind your words!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "army"))) then
       npcHandler:say("Ask the soldiers about that topic.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "enemy") or msgcontains(msg, "enemies"))) then
       npcHandler:say("Our enemies are numerous. The evil minotaurs, Ferumbras, and the renegade city of Carlin to the north are just some of them.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "city north") or msgcontains(msg, "carlin"))) then
       npcHandler:say("They dare to reject my reign over the whole continent!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "thais") or msgcontains(msg, "city"))) then
       npcHandler:say("Our beloved city has some fine shops, guildhouses, and a modern system of sewers.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "shop"))) then
       npcHandler:say("Visit the shops of our merchants and craftsmen.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "merchant") or msgcontains(msg, "craftsmen"))) then
       npcHandler:say("Ask around about them.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "guild"))) then
       npcHandler:say("The four major guilds are the knights, the paladins, the druids, and the sorcerers.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "minotaur"))) then
       npcHandler:say("Vile monsters, but I must admit they are strong and sometimes even cunning ... in their own bestial way.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "paladin") or msgcontains(msg, "elane"))) then
       npcHandler:say("The paladins are great protectors for Thais.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "knight") or msgcontains(msg, "gregor"))) then
       npcHandler:say("The brave knights are necessary for human survival in Thais.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "sorcerer") or msgcontains(msg, "muriel"))) then
       npcHandler:say("The magic of the sorcerers is a powerful tool to smite our enemies.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "druid") or msgcontains(msg, "marvik"))) then
       npcHandler:say("We need the druidic healing powers to fight evil.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "good"))) then
       npcHandler:say("The forces of good are hard pressed in these dark times.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "evil"))) then
       npcHandler:say("We need all strength we can muster to smite evil!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "order"))) then
       npcHandler:say("We need order to survive!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "chaos"))) then
       npcHandler:say("Chaos arises from selfishness, and that's its weakness.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "excalibug"))) then
       npcHandler:say("It's the sword of the kings. If you could return this weapon to me I would reward you beyond your dreams.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "reward"))) then
       npcHandler:say("Well, if you want a reward, go on a quest to bring me Excalibug!", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "chester"))) then
       npcHandler:say("A very competent person. A little nervous but very competent.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "tbi$"))) then
       npcHandler:say("This organisation is important in holding our enemies in check. Its headquarter is located in the bastion in the northwall.", cid)
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "promot"))) then
       Price[cid] = 20000
       npcHandler:say("Do you want to be promoted in your vocation for " .. Price[cid] .. " gold?", cid)
       Topic[cid] = 4
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "eremo"))) then
       npcHandler:say("It is said that he lives on a small island near Edron. Maybe the people there know more about him.", cid)
   end
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "What a lack of manners!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
I've found, here in OTland, a script that does that without this kind of problem:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions
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 FocusModule:init(handler)
    local FOCUS_GREETSWORDS = {'hi king', 'hello king', 'hail king', 'hail the king'}
    local FOCUS_FAREWELLSWORDS = {'bye', 'farewell'}
        self.npcHandler = handler
        for i, word in pairs(FOCUS_GREETSWORDS) do
            local obj = {}
            table.insert(obj, word)
            obj.callback = FOCUS_GREETSWORDS.callback or FocusModule.messageMatcher
            handler.keywordHandler:addKeyword(obj, FocusModule.onGreet, {module = self})
        end
      
        for i, word in pairs(FOCUS_FAREWELLSWORDS) do
            local obj = {}
            table.insert(obj, word)
            obj.callback = FOCUS_FAREWELLSWORDS.callback or FocusModule.messageMatcher
            handler.keywordHandler:addKeyword(obj, FocusModule.onFarewell, {module = self})
        end
      
        return true
    end
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am your sovereign, King Tibianus III, and it's my duty to provide justice and guidance for my subjects."})
keywordHandler:addKeyword({'justice'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I try my best to be just and fair to our citizens. The army and the TBI are a great help for fulfilling this duty."})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It's hard to believe that you don't know your own king!"})
keywordHandler:addKeyword({'new'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The latest news are usually brought to our magnificent town by brave adventurers. They spread tales of their journeys at Frodo's tavern."})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Soon the whole land will be ruled by me once again!"})
keywordHandler:addKeyword({'land'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Soon the whole land will be ruled by me once again!"})
keywordHandler:addKeyword({'how are you'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Thank you, I'm fine."})
keywordHandler:addKeyword({'castle'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Rain Castle is my home."})
keywordHandler:addKeyword({'sell'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Sell? Sell what? My kingdom isn't for sale!"})
keywordHandler:addKeyword({'god'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Honor the gods and pay your taxes."})
keywordHandler:addKeyword({'zathroth'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Please ask a priest about the gods."})
keywordHandler:addKeyword({'citizen'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The citizens of Tibia are my subjects. Ask the old monk Quentin to learn more about them."})
keywordHandler:addKeyword({'sam'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He is a skilled blacksmith and a loyal subject."})
keywordHandler:addKeyword({'frodo'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He is the owner of Frodo's Hut and a faithful tax-payer."})
keywordHandler:addKeyword({'gorn'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He was once one of Tibia's greatest fighters. Now he is selling equipment."})
keywordHandler:addKeyword({'benjamin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He was once my greatest general. Now he is very old and senile but we entrusted him with work for the Royal Tibia Mail."})
keywordHandler:addKeyword({'harkath'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Harkath Bloodblade is the general of our glorious army."})
keywordHandler:addKeyword({'bloodblade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Harkath Bloodblade is the general of our glorious army."})
keywordHandler:addKeyword({'noodles'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The royal poodle Noodles is my greatest treasure!"})
keywordHandler:addKeyword({'ferumbras'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He is a follower of the evil god Zathroth and responsible for many attacks on us. Kill him on sight!"})
keywordHandler:addKeyword({'bozo'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He is my royal jester and cheers me up now and then."})
keywordHandler:addKeyword({'treasure'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The royal poodle Noodles is my greatest treasure!"})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Go and hunt them! For king and country!"})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Visit Quentin, the monk, for help."})
keywordHandler:addKeyword({'quest'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I will call for heroes as soon as the need arises again and then reward them appropriately."})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I will call for heroes as soon as the need arises again and then reward them appropriately."})
keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "To pay your taxes, visit the royal tax collector."})
keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "To pay your taxes, visit the royal tax collector."})
keywordHandler:addKeyword({'sewer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "What a disgusting topic!"})
keywordHandler:addKeyword({'dungeon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Dungeons are no places for kings."})
keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Feel free to buy it in our town's fine shops."})
keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ask the royal cook for some food."})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It's a time for heroes, that's for sure!"})
keywordHandler:addKeyword({'hero'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It's a time for heroes, that's for sure!"})
keywordHandler:addKeyword({'adventurer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It's a time for heroes, that's for sure!"})
keywordHandler:addKeyword({'collector'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He has been lazy lately. I bet you have not payed any taxes at all."})
keywordHandler:addKeyword({'tax'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "To pay your taxes, visit the royal tax collector."})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am the king, so mind your words!"})
keywordHandler:addKeyword({'army'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ask the soldiers about that topic."})
keywordHandler:addKeyword({'enem'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Our enemies are numerous. The evil minotaurs, Ferumbras, and the renegade city of Carlin to the north are just some of them."})
keywordHandler:addKeyword({'north'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "They dare to reject my reign over the whole continent!"})
keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "They dare to reject my reign over the whole continent!"})
keywordHandler:addKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Our beloved city has some fine shops, guildhouses, and a modern system of sewers."})
keywordHandler:addKeyword({'city'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Our beloved city has some fine shops, guildhouses, and a modern system of sewers."})
keywordHandler:addKeyword({'shop'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Visit the shops of our merchants and craftsmen."})
keywordHandler:addKeyword({'merchant'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ask around about them."})
keywordHandler:addKeyword({'craftsmen'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ask around about them."})
keywordHandler:addKeyword({'guild'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The four major guilds are the knights, the paladins, the druids, and the sorcerers."})
keywordHandler:addKeyword({'minotaur'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Vile monsters, but I must admit they are strong and sometimes even cunning ... in their own bestial way."})
keywordHandler:addKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The paladins are great protectors for Thais."})
keywordHandler:addKeyword({'elane'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The paladins are great protectors for Thais."})
keywordHandler:addKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The brave knights are necessary for human survival in Thais."})
keywordHandler:addKeyword({'gregor'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The brave knights are necessary for human survival in Thais."})
keywordHandler:addKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The magic of the sorcerers is a powerful tool to smite our enemies."})
keywordHandler:addKeyword({'muriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The magic of the sorcerers is a powerful tool to smite our enemies."})
keywordHandler:addKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "We need the druidic healing powers to fight evil."})
keywordHandler:addKeyword({'marvik'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "We need the druidic healing powers to fight evil."})
keywordHandler:addKeyword({'good'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The forces of good are hard pressed in these dark times."})
keywordHandler:addKeyword({'evil'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "We need all strength we can muster to smite evil!"})
keywordHandler:addKeyword({'order'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "We need order to survive!"})
keywordHandler:addKeyword({'chaos'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Chaos arises from selfishness, and that's its weakness."})
keywordHandler:addKeyword({'excalibug'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It's the sword of the kings. If you could return this weapon to me I would reward you beyond your dreams."})
keywordHandler:addKeyword({'reward'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Well, if you want a reward, go on a quest to bring me Excalibug!"})
keywordHandler:addKeyword({'chester'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "A very competent person. A little nervous but very competent."})
keywordHandler:addKeyword({'tbi'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "This organisation is important in holding our enemies in check. Its headquarter is located in the bastion in the northwall."})
keywordHandler:addKeyword({'eremo'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "It is said that he lives on a small island near Edron. Maybe the people there know more about him."})
function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end
    if msgcontains(msg, 'promotion') or msgcontains(msg, 'promote') then
        npcHandler:say("Do you want to be promoted in your vocation for 20000 gold?", 1)
        talk_state = 2578 
    elseif talk_state == 2578 and msgcontains(msg, 'yes') then
        if getPlayerVocation(cid) >= 1 and getPlayerVocation(cid) <= 4 then
            if getPlayerLevel(cid) >= 20 then
                if isPremium(cid) == true then
                    if doPlayerRemoveMoney(cid, 20000) == true then
                    doPlayerSetVocation(cid, getPlayerVocation(cid)+4)
                    CheckPlayerBlessings(cid)
                    npcHandler:say("Congratulations! You are now promoted. Visit the sage Eremo for new spells.", 1)
                    talk_state = 0     
                    else
                    npcHandler:say("You do not have enough money.", 1)
                    talk_state = 0         
                    end
                else
                npcHandler:say("You need a premium account in order to promote.", 1)
                talk_state = 0             
                end
            else
            npcHandler:say("You need to be at least level 20 in order to be promoted.", 1)
            talk_state = 0         
            end
        else
        npcHandler:say("You are already promoted.", 1)
        talk_state = 0 
        end
    end 
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

In
local FOCUS_GREETSWORDS = {'hi king', 'hello king', 'hail king', 'hail the king'}
local FOCUS_FAREWELLSWORDS = {'bye', 'farewell'}

So I think that this is it. Credits go to Peonso and ond, both members of OTland. They did that by the request of nanhuto.
 
I personally find it fairly simple to create NPCs using the example82.lua as a template.
example82

If you scroll down to the onCreatureSay function
where it says
Lua:
if((msg == "hi") and not (isFocused(cid))) then
you can change it to something like
Lua:
local greetings = {"hi king", "hail king", "greetings", "good day"}
if isInArray(greetings, msg) and not isFocused(cid) then
 
Last edited:
Solution
Lua:
local distance = getDistanceTo(cid)
if distance > 4 then
    return false
end
 
Back
Top