• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua get storage MySQL query

Kahras

Member
Joined
Aug 6, 2012
Messages
97
Reaction score
7
Location
Warsaw
hello, help me write a mysql query -> players_storage which will return the player_id of one player with the largest storage 7777 value?
 

Ramon Bernardo

Well-Known Member
TFS Developer
Joined
Oct 7, 2018
Messages
137
Solutions
4
Reaction score
90
Try
SQL:
SELECT `player_id`
FROM `player_storage`
WHERE `key`= '7777'
ORDER BY `value` DESC
LIMIT 1;

I also recommend getting storage from players who are online and compare with the db.
 
OP
OP
K

Kahras

Member
Joined
Aug 6, 2012
Messages
97
Reaction score
7
Location
Warsaw
Try
SQL:
SELECT `player_id`
FROM `player_storage`
WHERE `key`= '7777'
ORDER BY `value` DESC
LIMIT 1;

I also recommend getting storage from players who are online and compare with the db.


htYEklS.png

How do I get the player_id value now?

Lua:
            local orderQuery = db.storeQuery("SELECT `player_id` FROM `player_storage` WHERE `key`= '17010' ORDER BY `value` DESC LIMIT 1;")
            print(orderQuery)
returns me the value 1
 

Gluttony

Member
Joined
Nov 4, 2022
Messages
18
Solutions
1
Reaction score
11
htYEklS.png

How do I get the player_id value now?

Lua:
            local orderQuery = db.storeQuery("SELECT `player_id` FROM `player_storage` WHERE `key`= '17010' ORDER BY `value` DESC LIMIT 1;")
            print(orderQuery)
returns me the value 1
result.getNumber(orderQuery, "player_id")
 
OP
OP
K

Kahras

Member
Joined
Aug 6, 2012
Messages
97
Reaction score
7
Location
Warsaw
omg I was convinced that there is a function that will return the name of the player by ID and I can't find it
is there such a function?
 

Roddet

Premium User
Support Team
Joined
May 1, 2013
Messages
772
Solutions
86
Reaction score
551
Location
Mex
Lua:
local queryResult = db.storeQuery("SELECT * FROM `player_storage` s INNER JOIN players p ON `s`.`player_id` = `p`.`id` WHERE `key`= '7777' ORDER BY `value` DESC LIMIT 1;")
if queryResult then
    local name = result.getString(queryResult, "name")
    local level = result.getNumber(queryResult, "level")
    local value = result.getNumber(queryResult, "value")

    print(name, value, level)
    result.free(queryResult)
end

You can index all rows from players and player_storage tables
If you only need the name, just change * to `p`.`name` and remove level var
 
OP
OP
K

Kahras

Member
Joined
Aug 6, 2012
Messages
97
Reaction score
7
Location
Warsaw
Lua:
local queryResult = db.storeQuery("SELECT * FROM `player_storage` s INNER JOIN players p ON `s`.`player_id` = `p`.`id` WHERE `key`= '7777' ORDER BY `value` DESC LIMIT 1;")
if queryResult then
    local name = result.getString(queryResult, "name")
    local level = result.getNumber(queryResult, "level")
    local value = result.getNumber(queryResult, "value")

    print(name, value, level)
    result.free(queryResult)
end

You can index all rows from players and player_storage tables
If you only need the name, just change * to `p`.`name` and remove level var


Lua:
local function checkNameSurvivalHigscores()
    local queryResult = db.storeQuery("SELECT * FROM `player_storage` s INNER JOIN players p ON `s`.`player_id` = `p`.`id` WHERE `key`= '7777' ORDER BY `value` DESC LIMIT 1;")
    if queryResult then
        local name = result.getString(queryResult, "name")
        result.free(queryResult)
        return name
    end
end

I created functions checkNameSurvivalHigscores()
print function and there is an error
Sorry, but I'm having trouble using mysql in Lua
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/survival/player_death.lua:eek:nPrepareDeath
data/creaturescripts/scripts/survival/player_death.lua:34: attempt to concatenate global 'value' (a nil value)
stack traceback:
[C]: in function '__concat'
data/creaturescripts/scripts/survival/player_death.lua:34: in function <data/creaturescripts/scripts/survival/player_death.lua:12>
 
Top