local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
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
--[[Edit]]--
local per = 90 -- percentege that will be sent to player
--[[functions]]--
function getPoints(cid)
local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
local value = 0
if(res:getID() ~= -1) then
value = res:getDataInt("premium_points")
res:free()
end
return value
end
function transfer(from,to,amount,perc) --percent equal the amount that will be tranferred
local pid = (getAccountIdByName(string.lower(to)))
local player = getAccountIdByName(string.lower(getCreatureName(from)))
db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` - '"..amount.."' WHERE `id` = '"..player.."' ;")
db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` + '"..math.floor(amount * (perc/100)).."' WHERE `id` = '"..pid.."' ;")
end
function greetCallback(cid)
Topic[cid] = 0
return true
end
--[[Script start]]--
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and Topic[cid] ~= 1 and Topic[cid] ~= 2 then
selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
Topic[cid] = 1
elseif Topic[cid] == 1 then
if not tonumber(msg) then
selfSay("You must type the amount of points, try again!",cid)
else
msg = math.floor(math.abs(msg))
t= {}
if tonumber(msg) > getPoints(cid) then
return selfSay("You only have "..getPoints(cid)..", try again!",cid)
end
table.insert(t,msg)
table.insert(t,math.floor(msg * (per/100)))
selfSay("To who this will be transfered? Remember that the comission is {".. 100-per.."%}, so you will just transfer {"..math.floor(msg * (per/100)).."} points, and {"..msg - math.floor(msg * (per/100)).."} points will go to me.",cid)
Topic[cid] = 2
end
elseif Topic[cid] == 2 then
if getPoints(cid) < t[2] then
selfSay("You only have "..getPoints(cid)..", try again!",cid)
Topic[cid] = 1
return true
end
if getAccountIdByName(msg) > 0 then
transfer(cid,msg,t[1],per)
selfSay("You have successfuly transfered "..t[2].." points to "..msg..".",cid)
Topic[cid] = 0
else
selfSay("Player doesnt exist, try again!",cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())