Saving online time with a MySQL event - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (
https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Saving online time with a MySQL event (
/showthread.php?tid=647540)
Saving online time with a MySQL event -
dicknyson - 06.01.2018
I was just about to create a timer to update all online players' online time in a MySQL table every 5 minutes, but then I thought... would a MySQL event be better? Something like:
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 1 SECOND DO
UPDATE users SET onlinetime = onlinetime + 1 WHERE online = 1;
Or to decrease the amount of load, even:
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 60 SECOND DO
UPDATE users SET onlinetime = onlinetime + 60 WHERE online = 1;
Would it be slow/inefficient for MySQL to search through potentially thousands of rows for online players?
Or perhaps I could have a separate table that adds a row for users when they come online in-game, and deletes the row when they disconnect, and have the event update if their ID exists in that table? What do you think?
Edit: obviously, when a player disconnects their online time will be saved from the gamemode.
Re: Saving online time with a MySQL event -
iLearner - 06.01.2018
Do it within pawn, and save it when player leaves the server.
Re: Saving online time with a MySQL event -
Abagail - 07.01.2018
Do you
need the amount of time through MySQL, out of the game server?