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

AAC Gesior 1.5 Power Gamers / Online Stats

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,741
Solutions
7
Reaction score
542
Location
Canada
Distro: TFS 1.5
ACC: Gesior2012

So far everything is working okay but I am having one problem with online time since "online" column has been removed from players table.
You can see from the code "--" commented out below which line I'm talking about. I know it's not as simple as switching online -> players_online since it also displays player ID now instead of just a 1/0.

@Gesior.pl - Do you have an update released for this that I'm not finding by search?
Update: Its also only updating XP counts when players log out.

Version 1
Code:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
        db.query("UPDATE `players` SET `onlinetime7`=players.onlinetime6, `onlinetime6`=players.onlinetime5, `onlinetime5`=players.onlinetime4, `onlinetime4`=players.onlinetime3, `onlinetime3`=players.onlinetime2, `onlinetime2`=players.onlinetime1, `onlinetime1`=players.onlinetimetoday, `onlinetimetoday`=0;")
    end
    --db.query("UPDATE `players` SET `onlinetimetoday`=players.onlinetimetoday+60, `onlinetimeall`=players.onlinetimeall+60 WHERE `online` = 1;")
    return TRUE
end

Version 2
Code:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `onlinetime7`=`onlinetime6`, `onlinetime6`=`onlinetime5`, `onlinetime5`=`onlinetime4`, `onlinetime4`=`onlinetime3`, `onlinetime3`=`onlinetime2`, `onlinetime2`=`onlinetime1`, `onlinetime1`=`onlinetimetoday`, `onlinetimetoday`=0;")
        db.query("UPDATE `players` SET `exphist7`=`exphist6`, `exphist6`=`exphist5`, `exphist5`=`exphist4`, `exphist4`=`exphist3`, `exphist3`=`exphist2`, `exphist2`=`exphist1`, `exphist1`=`experience`-`exphist_lastexp`, `exphist_lastexp`=`experience`;")
    end
    --db.query("UPDATE `players` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60 WHERE `online` = 1;")
    return TRUE
end
 
Last edited:
Update: Its also only updating XP counts when players log out.
Exp counter is based on experience column, which is saved by TFS, when it saves player.

Whole idea of that system was to not store any value 'per player', as it would lag with 1000 online. All operations are based on MySQL data and can be processed without any data from running OTS.
If you got 50k players in database and 1000 online in game, you can remove that Lua script, write same SQLs in PHP and run them by CRON - that way it won't lag OTS.
Do you have an update released for this that I'm not finding by search?
Try this:
Lua:
db.query("UPDATE `players` INNER JOIN `players_online` ON `players_online`.`player_id` = `players`.`id` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60")
with INNER JOIN it should only update players listed in players_online table.
 
Exp counter is based on experience column, which is saved by TFS, when it saves player.

Whole idea of that system was to not store any value 'per player', as it would lag with 1000 online. All operations are based on MySQL data and can be processed without any data from running OTS.
If you got 50k players in database and 1000 online in game, you can remove that Lua script, write same SQLs in PHP and run them by CRON - that way it won't lag OTS.

Try this:
Lua:
db.query("UPDATE `players` INNER JOIN `players_online` ON `players_online`.`player_id` = `players`.`id` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60")
with INNER JOIN it should only update players listed in players_online table.

Thank you so much @Gesior.pl for the update; going to test now. (Works for adding +1 minute to online players per execute)

Would I also do the same with the exp query as it only logs players exp when I log out.
Then if I reboot the server, it seems to wipe xp table info.

Speaking of these ones:
Code:
db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
        db.query("UPDATE `players` SET `onlinetime7`=players.onlinetime6, `onlinetime6`=players.onlinetime5, `onlinetime5`=players.onlinetime4, `onlinetime4`=players.onlinetime3, `onlinetime3`=players.onlinetime2, `onlinetime2`=players.onlinetime1, `onlinetime1`=players.onlinetimetoday, `onlinetimetoday`=0;")

This is my current config:

Global Event:
Code:
<globalevent name="ExpHistory" interval="60000" script="powergamers.lua"/>

Script:
Code:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
        db.query("UPDATE `players` SET `onlinetime7`=players.onlinetime6, `onlinetime6`=players.onlinetime5, `onlinetime5`=players.onlinetime4, `onlinetime4`=players.onlinetime3, `onlinetime3`=players.onlinetime2, `onlinetime2`=players.onlinetime1, `onlinetime1`=players.onlinetimetoday, `onlinetimetoday`=0;")
    end
    db.query("UPDATE `players` INNER JOIN `players_online` ON `players_online`.`player_id` = `players`.`id` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60")
    return TRUE
end

Edit: Slight Issue, every time the script executes it adds to a new day.
1661330499550.png
 
Last edited:
Would I also do the same with the exp query as it only logs players exp when I log out.
To store 'current exp of player' you got to send query to database. One for each player. With 200 online it would be 200 queries. On popular OTS it can make some lag.

After chatting on Discord we found out 2 problems:
  • Extrodus was using TFS 0.x database structure with global_storage table without unique key, every setGlobalStorageValueDB added new row to table with key 23456
  • if you are using otservbr, there is different setGlobalStorageValueDB implementation, which returns string, not number, in this case you got to update if:
Lua:
if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
to:
Lua:
if (tonumber(os.date("%d")) ~= tonumber(getGlobalStorageValueDB(23456))) then

TFS 1.x and otservbr compatible function:
Lua:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= tonumber(getGlobalStorageValueDB(23456))) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
        db.query("UPDATE `players` SET `onlinetime7`=players.onlinetime6, `onlinetime6`=players.onlinetime5, `onlinetime5`=players.onlinetime4, `onlinetime4`=players.onlinetime3, `onlinetime3`=players.onlinetime2, `onlinetime2`=players.onlinetime1, `onlinetime1`=players.onlinetimetoday, `onlinetimetoday`=0;")
    end
    db.query("UPDATE `players` INNER JOIN `players_online` ON `players_online`.`player_id` = `players`.`id` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60")

    return true
end

In case of TFS 1.x you got to add global_storage table and functions getGlobalStorageValueDB and setGlobalStorageValueDB. You can get them there:
 
Back
Top