function onSay(cid, words, param, channel)
if not param or param == '' then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Command requires parameters.\nUsage: ' .. words .. ' itemid, points (per item)')
end
param = string.explode(param, ',')
if #param ~= 2 then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Insufficient or too many parameters.\nUsage: ' .. words .. ' itemid, points (per item)')
end
param[1], param[2] = tonumber(param[1]), tonumber(param[2])
if not param[1] or not param[2] then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'One or more parameters are not numbers.')
end
local players, done, nplayers, npoints = db.getResult("SELECT `player_id` FROM `player_items` WHERE `itemtype` = " .. param[1] .. ";"), {}, 0, 0
if players:getID() ~= -1 then
repeat
local cur, get = players:getDataInt('player_id'), 0
if not isInArray(done, cur) then
table.insert(done, cur)
local player = getPlayerByGUID(cur)
if player then
get = getPlayerItemCount(player, param[1])
doPlayerRemoveItem(player, param[1], get)
else
local _get = db.getResult("SELECT SUM(`count`) as `count` FROM `player_items` WHERE `itemtype` = " .. param[1] .. " AND `player_id` = " .. cur .. ";")
get = _get:getDataInt('count')
_get:free()
db.executeQuery("DELETE FROM `player_items` WHERE `itemtype` = " .. param[1] .. " AND `player_id` = " .. cur .. ";")
end
local add, accid = param[2] * get, player and getPlayerAccountId(player)
if add > 0 then
if not accid then
local _get = db.getResult("SELECT `account_id` FROM `players` WHERE `id` = " .. cur .. ";")
accid = _get:getDataInt('account_id')
_get:free()
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You have received ' .. add .. ' premium points.')
end
db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. add .. " WHERE `id` = " .. accid .. ";")
npoints, nplayers = npoints + add, nplayers + 1
end
end
until not players:next()
players:free()
end
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'A total of ' .. nplayers .. ' player(s) have received ' .. npoints .. ' point(s).')
end