local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
[COLOR="red"][B]local ticket_id = XXXX
local ticket = 1000[/B][/COLOR]
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 thinkCallback(cid)
if math.random(500) == 1 then
npcHandler:say("Buy your ticket's here!")
end
return true
end
function creatureSayCallback(cid, type, msg)
if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
local v = getPlayerMoney(cid)
if v < ticket then
npcHandler:say(getPlayerSex(cid) == 0 and "Sorry ma'am, you need " .. ticket .. " gold." or "Sorry sir, you need " .. ticket .. " gold.", cid)
Topic[cid] = 0
else
npcHandler:say("How can I help you?", cid)
Topic[cid] = 1
end
npcHandler:addFocus(cid)
elseif(not npcHandler:isFocused(cid)) then
return false
elseif msgcontains(msg, "no") then
npcHandler:say("Then not.", cid, TRUE)
Topic[cid] = 0
elseif msgcontains(msg, "ticket") and Topic[cid] == 1 then
npcHandler:say("Would you like to purchase a ticket for " .. ticket .. " gold coins?", cid)
Topic[cid] = 2
elseif Topic[cid] == 2 then
if msgcontains(msg, "yes") then
if doPlayerRemoveMoney(cid, ticket) then
npcHandler:say("Here you are.", cid)
doPlayerAddItem(cid, ticket_id, 1)
Topic[cid] = 0
else
npcHandler:say("Sorry, you don't have enough money.", cid)
Topic[cid] = 1
end
elseif msgcontains(msg, "no") then
npcHandler:say("Okay then.", cid)
Topic[cid] = 0
end
elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
npcHandler:say("Good bye.", cid, TRUE)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)