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

Lua TFS 0.4 - Graduation system, storage for 5 best players

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
Hello friends, I need a script that when the server starts, it will check which are the 05 players that have the highest value of storage 1030.
For exemample:
Teste 1 has storage 1030, value 500
Teste 2 has storage 1030, value 450
Teste 3 has storage 1030, value 300


Assuming they are the players with the highest storage 1030, when the server stats, i want to the player Teste 1, receives a storage 887, value 1.
The player test 2, receives storage 887, value 2
The player test 3, receives storage 887, value 3.

Tkx!
 
Lua:
local storage = 1030
local high_value = 887
local top_n = 5
function onStartup()
    local score = 1
    local highscore = db.storeQuery("SELECT player_id FROM `player_storage` WHERE player_storage.key = '" .. storage .. "' and value > 0 ORDER BY value DESC LIMIT "..  top_n .. ";")
    db.query("DELETE FROM player_storage WHERE player_storage.key = '" .. high_value .. "';")
    if result.getNumber(highscore, "player_id") then
            local pl_id = result.getNumber(highscore, "player_id")
            db.query(MESSAGE_STATUS_CONSOLE_BLUE,"INSERT INTO player_storage(player_id, key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
            score = score + 1
            while(result:next(highscore)) do
                local pl_id = result.getNumber(highscore, "player_id")
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "number " .. score .. ":" .. pl_id)
                db.query("INSERT INTO player_storage(player_id,  key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
                score = score + 1
        end
    end
end
 
Last edited:
Lua:
local storage = 1030
local high_value = 887
function onStartup()
    local score = 1
    local highscore = db.storeQuery("SELECT player_id FROM `player_storage` WHERE player_storage.key = '" .. storage .. "' and value > 0 ORDER BY value DESC LIMIT 3;")
    db.query("DELETE FROM player_storage WHERE player_storage.key = '" .. high_value .. "';")
    if result.getNumber(highscore, "player_id") then
            local pl_id = result.getNumber(highscore, "player_id")
            db.query(MESSAGE_STATUS_CONSOLE_BLUE,"INSERT INTO player_storage(player_id, player_storage.key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
            score = score + 1
            while(result:next(highscore)) do
                local pl_id = result.getNumber(highscore, "player_id")
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "number " .. score .. ":" .. pl_id)
                db.query("INSERT INTO player_storage(player_id,  player_storage.key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
                score = score + 1
        end
    end
end

i got this erros:

SQLITE ERROR: near ".": syntax error (INSERT INTO player_storage(player_id, player_storage.key, value) VALUES (31, 887, 1);)
SQLITE ERROR: near ".": syntax error (INSERT INTO player_storage(player_id, player_storage.key, value) VALUES (68, 887, 2);)
 
Well, I would delete. player_storage. from it. You could, if you wanted to figure it out on your own, open up your database and look in the player_storage table. You will see 3 values that can be put in: player_id, key, value. or something simular. What ever that 2nd one "key" is named that is what you need to change it too instead of player_storage.key
 
Well, I would delete. player_storage. from it. You could, if you wanted to figure it out on your own, open up your database and look in the player_storage table. You will see 3 values that can be put in: player_id, key, value. or something simular. What ever that 2nd one "key" is named that is what you need to change it too instead of player_storage.key
thx a lot!
 
Back
Top