local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}
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 locations = {
["Room 1"] = {pos = {x = 2000, y = 2000, z = 7}, cost = 10, GlobalStorage = 50001},
["Room 2"] = {pos = {x = 2000, y = 2000, z = 7}, cost = 10, GlobalStorage = 50002},
["Room 3"] = {pos = {x = 2000, y = 2000, z = 7}, cost = 10, GlobalStorage = 50003}
}
local function Cptl(f, r)
return f:upper()..r:lower()
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 x = locations[msg:gsub("(%a)([%w_']*)", Cptl)]
if msgcontains(msg, 'travel') or msgcontains(msg, 'passage') then
if getPlayerPremiumDays(cid) >= 0 then
selfSay('Where do you want to go? I can bring you to { Room 1 }, { Room 2 } or { Room 3 }.', cid)
talkState[talkUser] = 1
else
selfSay('Travel is only for premium.', cid)
end
elseif x and talkState[talkUser] == 1 then
selfSay('Do you want to travel to '..msg..' for '..x.cost..' token?', cid)
xmsg[cid] = msg
talkState[talkUser] = 2
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
x = locations[xmsg[cid]:gsub("(%a)([%w_']*)", Cptl)]
if getGlobalStorageValue(x.GlobalStorage) < 2 then
if doPlayerRemoveItem(cid,9020, x.cost) then
selfSay('Here you go, have a fun trip to '..xmsg[cid]..'.', cid)
doTeleportThing(cid, x.pos)
setGlobalStorageValue(x.GlobalStorage, getGlobalStorageValue(x.GlobalStorage) == -1 and 1 or getGlobalStorageValue(x.GlobalStorage) + 1)
talkState[talkUser] = 0
else
selfSay('You don\'t have enough token.', cid)
end
else
selfSay('Sorry, there are two players in area .', cid)
talkState[talkUser] = 0
end
else
selfSay('What? I don\'t understand what you mean with '..msg..'.', cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())