• 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 get storage MySQL query

Kahras

Member
Joined
Aug 6, 2012
Messages
101
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?
 
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.
 
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
 
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")
 
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?
 
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 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>
 
Back
Top