Server's Uptime & Players last online time - 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: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Server's Uptime & Players last online time (
/showthread.php?tid=273052)
Server's Uptime & Players last online time -
Luis- - 31.07.2011
Hello, I have two questions to ask.
1) How would I save the server's uptime since its last restart and show it within a command.
2) How would I save players last online time within mysql.
~ Thanks, Luis.
Re: Server's Uptime & Players last online time -
Lorenc_ - 31.07.2011
Check out Eclipse, that gamemode has it in SQLite I suppose, a little converting and checking can help out
Re: Server's Uptime & Players last online time -
Luis- - 31.07.2011
I'll give it a go, thanks Lorenc.
Re: Server's Uptime & Players last online time -
iLinx - 31.07.2011
1) Save a unix time stamp in OnGameModeInit in a variable and then to get the uptime just get the current timestamp and subtract the startup timestamp from it, and you'll get the uptime in seconds (give or take 1 or 2 seconds).
2) Just create a MySQL query that saves their time when they logout on OnPlayerDisconnect using, again - best way a unix timestamp, since it is easy to convert it into different time formats.
Re: Server's Uptime & Players last online time -
Luis- - 31.07.2011
Thanks iLinx but I am wondering how I use unix timestamps, I have never used them before.
Re: Server's Uptime & Players last online time -
dowster - 31.07.2011
A unix timestamp is the seconds from January 1970 i believe, so it's basically like a stopwatch, that hasn't stopped.
Re: Server's Uptime & Players last online time -
iLinx - 31.07.2011
Quote:
Originally Posted by -Luis
Thanks iLinx but I am wondering how I use unix timestamps, I have never used them before.
|
https://sampwiki.blast.hk/wiki/Gettime
Gettime() (without parameters) returns a unix time stamp.
For example, assume you have a variable which stores the time the server started up on, @1312130588. Right now it's 1312137588 when you call the uptime function. The difference is 7000 seconds between the two (when you subtract the current timestamp from the startup timestamp, the current will always be larger so you subtract it first). Once you have the difference its a matter of converting the difference in seconds to a more readable number (ie h,m,s) using the division and modulus operators.
Re: Server's Uptime & Players last online time -
Calgon - 31.07.2011
https://sampforum.blast.hk/showthread.php?tid=254915
A tutorial I made
specifically to explain unix timestamps, not hard to find.