Server's Uptime & Players last online time
#1

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.
Reply
#2

Check out Eclipse, that gamemode has it in SQLite I suppose, a little converting and checking can help out
Reply
#3

I'll give it a go, thanks Lorenc.
Reply
#4

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.
Reply
#5

Thanks iLinx but I am wondering how I use unix timestamps, I have never used them before.
Reply
#6

A unix timestamp is the seconds from January 1970 i believe, so it's basically like a stopwatch, that hasn't stopped.
Reply
#7

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.
Reply
#8

https://sampforum.blast.hk/showthread.php?tid=254915

A tutorial I made specifically to explain unix timestamps, not hard to find.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)