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

TFS 1.X+ SQL query option to former 'online' player column

E

Evil Puncker

Guest
hi guys, we used to have a 'online' column in players table, now we got the player_id in the players_online table, how do I make this query work with the new table?

db.query("UPDATE players SET onlinetimetoday=players.onlinetimetoday+60, onlinetimeall=players.onlinetimeall+60 WHERE online = 1;")

instead of "where online = 1;" I need the SQL equivalent of "where player_id is present in the players_online table"
 
Solution
This could be done differently than you're thinking because you already have the player_id, just use WHERE id = <PLAYERID HERE>;
If you're doing this through Lua and you have the player id, they're most likely online (otherwise how did you get it?)
Either way if you still need to check if they're online, just use Lua instead of trying to muck around with checking the table in SQL, in newer TFS versions you're able to construct a Player by using their GUID (the id you're talking about), so if you just do something like this, there's no need to check if they're online using an SQL statement:
Lua:
if Player(player_id) then
    db.asyncQuery("UPDATE `players` SET `onlinetimetoday` = `onlinetimetoday` + 60, `onlinetimeall` =...
This could be done differently than you're thinking because you already have the player_id, just use WHERE id = <PLAYERID HERE>;
If you're doing this through Lua and you have the player id, they're most likely online (otherwise how did you get it?)
Either way if you still need to check if they're online, just use Lua instead of trying to muck around with checking the table in SQL, in newer TFS versions you're able to construct a Player by using their GUID (the id you're talking about), so if you just do something like this, there's no need to check if they're online using an SQL statement:
Lua:
if Player(player_id) then
    db.asyncQuery("UPDATE `players` SET `onlinetimetoday` = `onlinetimetoday` + 60, `onlinetimeall` = `onlinetimeall` + 60 WHERE `id` = player_id;")
end
 
Solution
Back
Top