local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
local Price = {}
local Type = {}
local storageKeyHere = 1337 -- change this to storageKey
local storageValueHere = 0 -- change this to the storageValue you want the npc to assign when you say hi
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)
-- only get focus to player's whit storageValue lower then 0
if (not npcHandler:isFocused(cid) and getPlayerStorageValue(cid, storageKeyHere) >= 0 and (msgcontains(msg, "hello$") or msgcontains(msg, "hi$"))) then
npcHandler:say("You made it, Good bye " .. getCreatureName(cid) .. ".", cid) -- msg in npc Channel
npcHandler:say("You made it, Good bye " .. getCreatureName(cid) .. ".") -- msg in default chat
Topic[cid] = nil
return true
elseif (not npcHandler:isFocused(cid) and (msgcontains(msg, "hello$") or msgcontains(msg, "hi$"))) then
npcHandler:addFocus(cid)
npcHandler:say("Hello, " .. getCreatureName(cid) .. ".", cid) -- msg in npc Channel
npcHandler:say("Hello, " .. getCreatureName(cid) .. ".") -- msg in default chat
doPlayerSetStorageValue(cid, storageKeyHere, storageValueHere) -- set the storageValue to 0
Topic[cid] = nil
return true
elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "bye"))) then
npcHandler:say("Good bye, " .. getCreatureName(cid) .. ".", cid)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
return true
-- Remove item give item Example
elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "enchant knight axe"))) then
npcHandler:say("Do you want to enchant a knight axe to a fiery knight axe, for free?", cid)
Type[cid] = 2430 -- itemid of a regular knight axe
Topic[cid] = 1
elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and getPlayerItemCount(cid, Type[cid]) > 0 and (msgcontains(msg, "yes"))) then
npcHandler:say("Here you go.", cid)
doPlayerRemoveItem(cid, Type[cid], 1)
Type[cid] = 7750 -- itemid of a fiery knight axe
doPlayerAddItem(cid, Type[cid], 1, true)
Type[cid] = nil
Topic[cid] = nil
elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and getPlayerItemCount(cid, Type[cid]) < 1 and (msgcontains(msg, "yes"))) then
npcHandler:say("Sorry, you don't have any knight axe.", cid)
Type[cid] = nil
Topic[cid] = nil
elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and (not msgcontains(msg, "yes"))) then
npcHandler:say("Okey, is there anything else i can do for you?", cid)
Type[cid] = nil
Topic[cid] = nil
-- teleport Example of boat npc
elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "carlin"))) then
Price[cid] = 110 -- set the price to use the boat
npcHandler:say("Do you seek a passage to Carlin for " .. Price[cid] .. " gold?", cid)
Topic[cid] = 2
elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "ab'dendriel"))) then
Price[cid] = 130
npcHandler:say("Do you seek a passage to Ab'Dendriel for " .. Price[cid] .. " gold?", cid)
Topic[cid] = 3
elseif (npcHandler:isFocused(cid) and Topic[cid] == 2 and isPremium(cid) and getPlayerMoney(cid) >= Price[cid] and (msgcontains(msg, "yes"))) then
-- Note: isPremium(cid) mean's the player needs premium on the account to travel/teleport. Remove it to let free accounts use the boat aswell
doPlayerRemoveMoney(cid, Price[cid]) -- pay the price to use the boat
Price[cid] = nil
npcHandler:say("Set the sails!", cid)
doTeleportThing(cid, {x= 32387,y= 31821,z = 6}) -- real tibia cords, to carlin
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
elseif (npcHandler:isFocused(cid) and Topic[cid] == 3 and isPremium(cid) and getPlayerMoney(cid) >= Price[cid] and (msgcontains(msg, "yes"))) then
doPlayerRemoveMoney(cid, Price[cid])
Price[cid] = nil
npcHandler:say("Set the sails!", cid)
doTeleportThing(cid, {x= 32733,y= 31668,z = 6}) -- real tibia cords, to ab'dendriel
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, get lost.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)