local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local 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
function greet(cid) talkState[cid] = 0 return true end
function getNpcName()
return getCreatureName(getNpcId())
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 temp = tonumber(msg)
if talkState[talkUser] == 0 and temp ~= nil and temp > 0 then
selfSay("Do you want to buy " .. msg .. " premium days for " .. msg .. " tokens and " .. (temp * 2) .. " crystal coins?", cid)
xmsg[cid] = msg
talkState[talkUser] = 1
elseif talkState[talkUser] == 0 and msgcontains(msg, "premium") then
selfSay("Please tell me how many days of premium you would like to purchase.", cid)
talkState[talkUser] = 0
elseif talkState[talkUser] == 1 and msgcontains(msg, "yes") then
local tempCount = tonumber(xmsg[cid])
if getPlayerItemCount(cid, 111111111111111111111111111111111111111111111111111111111111111111111111111) >= tempCount and getPlayerMoney(cid) >= (tempCount * 2) then
doPlayerRemoveItem(cid, 111111111111111111111111111111111111111111111111111111111111111111111111111, tempCount)
doPlayerRemoveMoney(cid, (tempCount * 2))
doPlayerAddPremiumDays(cid, tempCount)
selfSay("Thank you for your patronage!", cid)
else
selfSay("You don't have the required resources to trade for " .. xmsg[cid] .. " premium days.", cid)
end
talkState[talkUser] = 0
else
selfSay("Sorry? I don't understand.", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())