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 teleports = {
["Yalahar"] = {pos = {x=89,y=126,z=7} , price = 500}, -- name,pos,price
["Carlin"] = {pos = {x=92,y=132,z=7} , price = 800}, -- name,pos,price
["Svargrond"] = {pos = {x=98,y=125,z=7} , price = 1500} -- yalahar name,pos,price
}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local str = ""
if msgcontains(msg, 'teleport') then
if getPlayerVipDays(cid) > 0 then
for k,v in pairs(teleports) 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
else
selfSay("I only serve Vip player.",cid)
end
elseif Topic[cid] == 1 then
for k,v in pairs(teleports) 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 "..teleports[chosen[cid]].price.."?",cid)
Topic[cid] = 2
end
elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
if doPlayerRemoveMoney(cid,teleports[chosen[cid]].price) then
selfSay("There you go.",cid)
addEvent(doTeleportThing,200,cid,teleports[chosen[cid]].pos,false)
addEvent(doSendMagicEffect,300,teleports[chosen[cid]].pos,10)
Topic[cid] = 0
else
selfSay("Come back when you have 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())