• 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!

Solved Command sql to add premium points

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
Hello folks, I'm trying make a command talkaction to give premium points to the target parameter
but I don't have any knowledge about the sql sintax
using the following command
Code:
/coins playername, amount
could someone help me ?
 
Solution
Try this:

Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end
   
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
   
    local split = param:split(",")
    local name = split[1]
    local points = tonumber(split[2])
   
    if not (points and name) then
        player:sendCancelMessage('You entered the params wrong. [Correct Format --> /coins playerName,amount]')
    return false
    end
   
    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        player:sendCancelMessage('Sorry, could not find account ID of player by the name of: "' .. name .. '".')
        return false
    end
   
    db.query("UPDATE...
I dont really understand your post. You are looking for a SQL query to execute to give coins?

Code:
UPDATE players SET coins = coins + 10  WHERE name = 'Raggaer';

Since I dont know your column name here is an example. Hope it helps
 
exactly, my column name is premium points :D
I'll try use this, thank you for the feed...
but seems that is missing something, I need get the account from the param 1 (player) to give the param 2 (amount) to the account of the param 1
 
Ah! Sorry for that!

Code:
UPDATE accounts AS T1, (SELECT account_id FROM players WHERE name = 'Raggaer') AS T2 SET T1.premium_points = T1.premium_points + 10 WHERE id = T2.account_id;

Hope it gives you an idea
 
i'm trying...
but..
Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    local split = param:split(",")
    local name = param[1]
    local param2 = split[2]
    local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if resultId == false then
        player:sendCancelMessage("A player with that name does not exist.")
        return false
    end
    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end
    local resultId = db.storeQuery("SELECT 1 FROM `accounts` WHERE `account_id` = " .. accountId)
   
    db.query("UPDATE `accounts` WHERE `account_id` = " .. accountId.. "SET `premium_points` = premium_points + " ..tonumber(param2))
    result.free(resultId)
    return false
end
 
I dont get your line 22.

Its been ages since I did some TFS scripting but what is the error you are facing? Perhaps a Support member can help you out =)

But remember you can achieve this in one query instead of two. =)
 
Try this:

Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end
   
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
   
    local split = param:split(",")
    local name = split[1]
    local points = tonumber(split[2])
   
    if not (points and name) then
        player:sendCancelMessage('You entered the params wrong. [Correct Format --> /coins playerName,amount]')
    return false
    end
   
    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        player:sendCancelMessage('Sorry, could not find account ID of player by the name of: "' .. name .. '".')
        return false
    end
   
    db.query("UPDATE accounts SET premium_points = premium_points+ " .. points .. " WHERE id = " .. accountId .. ";")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have added ' .. points .. ' coins to the player ' .. name .. '.')
    return false
end
 
Solution
Try this:

Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end
  
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
  
    local split = param:split(",")
    local name = split[1]
    local points = tonumber(split[2])
  
    if not (points and name) then
        player:sendCancelMessage('You entered the params wrong. [Correct Format --> /coins playerName,amount]')
    return false
    end
  
    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        player:sendCancelMessage('Sorry, could not find account ID of player by the name of: "' .. name .. '".')
        return false
    end
  
    db.query("UPDATE accounts SET premium_points = premium_points+ " .. points .. " WHERE id = " .. accountId .. ";")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have added ' .. points .. ' coins to the player ' .. name .. '.')
    return false
end
thank you very much,it worked!!! also I'll learn with this !!!
 
Back
Top