local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 function getCount(msg)
local ret = -1
local b, e = string.find(msg, "%d+")
if b ~= nil and e ~= nil then
ret = tonumber(string.sub(msg, b, e))
end
return ret
end
function creatureSayCallback(cid, type, msg)
if(npcHandler.focus ~= cid) then
return false
end
local count = (getCount(msg))
local premium_day_price = 1000 -- price of each day of premium account (in gold coins)
if msgcontains(msg, 'premium') or msgcontains(msg, 'premmy') then
talk_state = 1
selfSay("How much premium days you want to buy?")
elseif isNumber(getCount(msg)) == TRUE and talk_state == 1 then
talk_state = 2
premium_days = count
cost = math.floor(premium_days * premium_day_price)
selfSay("Do you want to buy "..premium_days.." premium account days for "..cost.." gold coins?")
elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
if doPlayerRemoveMoney(cid, cost) == TRUE then
doPlayerAddPremiumDays(cid, premium_days)
selfSay("You have successfully bought "..premium_days.." premium account days for "..cost.." gold coins.")
else
selfSay("Sorry, you do not have enough money.")
end
elseif msgcontains(msg, 'no') and talk_state == 2 then
selfSay('Then not.')
talk_state = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())