• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Adding premium points if player is offline command.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Hi everyone, well, here is a script to add points if player is online, it works like: /addpoints kito, 50 and it will add 50 points if you are online, but if you are offline, it wont do that, so I need help, can someone fix this script and make available to add points if player is offline too?

PHP:
 ‎function onSay(cid, words, param)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
return TRUE
end

local t = string.explode(param, ",")
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough params.")
return TRUE
end

local target = getPlayerByName(t[1])
if target ~= 0 then
doAddPoints(target, t[2])
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, target.." has received "..t[2].." premium points.")
doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_BLUE, "You have received "..t[2].." premium points.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player is offline or does not exist.")
end
return FALSE
end

Thanks.
 
Optimized script:
* use one SQL query to select player (from `players` table) and update points (in `accounts` table)
* send message if player doesnt exist (old script show error :> )
Script:
PHP:
  function onSay(cid, words, param)
        local t = string.explode(param, ",")
        if t[1] ~= nil and t[2] ~= nil then
                if(db.executeQuery("UPDATE `accounts`, `players` SET `accounts`.`premium_points` = `accounts`.`premium_points`+" .. t[2] .. " WHERE `players`.`name` = " .. db.escapeString(t[1]) .. " AND `players`.`account_id` = `accounts`.`id`;")) then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, t[1] .. " has received "..t[2].." premium points.")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Player with name " .. t[1] .. " doesn't exist.")
                end
        else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command Requires Two Params (name,points).")
        end
        return TRUE
end
not tested, but I think it should work
 
Back
Top