• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua + SQL - one simple questin how get value

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello, I have these lines in globalevent script:
Code:
local ns_query =[[ SELECT id FROM players WHERE account_id !=1 AND players.town_id > 5 ]]

function onStartup(_time)
    local player = db.getResult(ns_query)
    if player:getID() ~= -1 then
        repeat                    
            db.executeQuery("UPDATE `players` SET `health` = 4000 WHERE `id` = " .. player[0])

player[0] and player don't work, how can I send id there?
 
Hello, I have these lines in globalevent script:
Code:
local ns_query =[[ SELECT id FROM players WHERE account_id !=1 AND players.town_id > 5 ]]

function onStartup(_time)
    local player = db.getResult(ns_query)
    if player:getID() ~= -1 then
        repeat                   
            db.executeQuery("UPDATE `players` SET `health` = 4000 WHERE `id` = " .. player[0])

player[0] and player don't work, how can I send id there?

Have you tried with db.storeQuery instead of db.getResult?
 
The same error:
Code:
attempt to index local 'player' (a number value)

Tried with something like: result.getDataInt(player, "column") ?? Notice this is an getDataInt. Idk if something like getDataString exist, explore!
 
Do you mean
Code:
local ns_query =[[ SELECT id FROM players WHERE account_id !=1 AND players.town_id > 5 ]]
     function onStartup(_time)
     local player = db.getResult(ns_query)
     if player:getID() ~= -1 then
          repeat
          result.getDataInt(player,"UPDATE `players` SET `health` = 4000")
?

error: attempt to index local 'player' (a number value)
 
Do you mean
Code:
local ns_query =[[ SELECT id FROM players WHERE account_id !=1 AND players.town_id > 5 ]]
     function onStartup(_time)
     local player = db.getResult(ns_query)
     if player:getID() ~= -1 then
          repeat
          result.getDataInt(player,"UPDATE `players` SET `health` = 4000")
?

error: attempt to index local 'player' (a number value)

No, you do not put the query inside there, that one is only to get result from the selected row in your other query.
result.getDataInt(player,"name")

player is the variable of the query you have, and "name" is the column to get from the table.
Idk if this works with db.getResult as you use, but I'm sure it works with db.storeQuery
 
Well, tried with:
Code:
local ns_query =[[ SELECT id FROM players WHERE account_id !=1 AND players.town_id > 5 ]]
function onStartup(_time)
    local player = db.storeQuery(ns_query)
    if player:getID() ~= -1 then
        repeat                  
            x = result.getDataInt(player,"id")
            db.executeQuery("UPDATE `players` SET `health` = 4000 WHERE `id` = " .. x)

error: attempt to index local 'player' (a number value)

What's wrong?
 
What exactly are you trying to do? Why don't you use getPlayersOnline() to get the players you want, add it to a loop and get the guid?
 
Back
Top