local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
local chosen = {}
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 greetCallback(cid)
Topic[cid] = 0
chosen[cid] = nil
return true
end
local monsters = {
["xxx"] = {pos = {x=1021,y=1038,z=7} , price = 500}, -- monster name,pos,price
["xxx"] = {pos = {x=1030,y=932,z=7} , price = 500},
["xxx"] = {pos = {x=98,y=125,z=7} , price = 1500}
["xxx"] = {pos = {x=98,y=125,z=7} , price = 1500}
}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local str = ""
if msgcontains(msg, 'travel') then
for k,v in pairs(monsters) do
str = str..""..(string.len(str) > 0 and ', ' or '').."{"..k.."}"
end
npcHandler:say("Where to? I can take you to "..str..".", cid)
Topic[cid] = 1
elseif Topic[cid] == 1 then
for k,v in pairs(monsters) do
if msgcontains(msg, k) then
chosen[cid] = k
end
end
if chosen ~= nil then
selfSay("So do you want to go to {"..chosen[cid].."} for "..monsters[chosen[cid]].price.."?",cid)
Topic[cid] = 2
end
elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
if doPlayerRemoveMoney(cid,monsters[chosen[cid]].price) then
selfSay("There you go.",cid)
addEvent(doTeleportThing,200,cid,monsters[chosen[cid]].pos,false)
addEvent(doSendMagicEffect,300,monsters[chosen[cid]].pos,10)
Topic[cid] = 0
else
selfSay("You dont have enough money...",cid)
Topic[cid] = 0
end
elseif msgcontains(msg, 'no') and Topic[cid] == 2 then
selfSay("Maybe later then.",cid)
chosen[cid] = nil
Topic[cid] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())