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 info = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `id` = '"..getPlayerGUID(cid).."'")
if(info:getID() == -1) then
return true
end
local premium_points = info:getDataInt("premium_points")
info:free()
local item_id = 2147
if(msgcontains(msg, 'change')) then
if(info > 0) then
selfSay('Do you want to exchange your '.. info ..' premium points into '.. info ..' diamonds?', cid)
talkState[talkUser] = 1
else
selfSay('You don\'t have any premium points, come back later.', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
doPlayerAddItem(cid, item_id, info)
db.executeQuery("UPDATE `accounts` SET `premium_points` = 0 WHERE `id` = '"..getPlayerGUID(cid).."'");
selfSay('Here you are.', cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then, bye.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())