local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local locations = {
["Thais"] = {pos = {x = 100, y = 100, z = 7}, gold = 100},
["Carlin"] = {pos = {x = 100, y = 100, z = 7}, gold = 120},
["Venore"] = {pos = {x = 100, y = 100, z = 7}, gold = 90}
}
local function addCptl(first, rest)
return first:upper()..rest:lower()
end
local x = locations[msg:gsub("(%a)([%w_']*)", addCptl)]
local travel = (msgcontains(msg, 'travel'))
if travel then
if getPlayerPremiumDays(cid) >= 1 then
selfSay('Where do you want to go? I can bring you to Thais, Carlin or Venore.', cid)
talkState[talkUser] = 1
else
selfSay('Travel is only for premium.', cid)
end
end
if x and talkState[talkUser] == 1 then
selfSay('Do you want to travel to '..msg..' for '..x.gold..' gold?', cid)
xmsg = msg
talkState[talkUser] = 2
end
local agree = (msgcontains(msg, 'yes'))
if agree and talkState[talkUser] == 2 then
x = locations[xmsg:gsub("(%a)([%w_']*)", addCptl)]
if doPlayerRemoveMoney(cid, x.gold) then
selfSay('Here you go, have a fun trip to '..xmsg..'.', cid)
doTeleportThing(cid, x.pos)
talkState[talkUser] = 0
else
selfSay('You don\'t have enough money.', cid)
talkState[talkUser] = 0
end
end
if not x and not travel and not agree then
selfSay('What? I don\'t understand what you mean with '..msg..'.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())