/*
This is a code snippet I decided to make while I was waiting for the mail to arrive.
The title is pretty self-explanatory.
*/
var
Seconds = 0;Minutes = 0;Hours = 0 // Global Variables for Seconds, Minutes, and Hours.
world
New()
..()
Uptime() // Run the Uptime() procedure. Which is initialized at runtime.
proc/Uptime()
world << "[Seconds]:[Minutes]:[Hours]" // Displays the server uptime.
if(Seconds >= 60) {Minutes += 1;Seconds = 0} // If your seconds variable value is above or is 60. Then add + 1 to the Minutes, then return Seconds to 0.
if(Minutes >= 60) {Hours += 1;Minutes = 0}
Seconds ++ // ++ the Seconds variable so the counter doesn't stop.
spawn(10) Uptime() // Every ten server ticks call Uptime()
/*
Just an FWI. For those of you who don't know how long a tick is I'll tell you.
1 Tick = 1/10th of a second.
10 Ticks = 1 Second.
600 Ticks = 1 Minute.
3600 Ticks = 1 Hour.
QUOTE Popisfizzy:
FYI, 60 minutes * 60 seconds = 3600 seconds.
*/
ID:195020
Jul 28 2011, 5:57 am (Edited on Jul 29 2011, 12:34 am)
|
|
Jul 28 2011, 5:16 pm
|
|
This is pretty terrible. You're also pretty wrong. 6000 ticks = 1 hour? lolol
|
In response to Popisfizzy
|
|
Yeah, I stayed up all night, then made that an didn't double check the math. Thanks BTW.
|
That's one approach. The other is already done for you!
It's been ages since I've had BYOND installed, so bear with me, but... mob/verb/uptime() world.time tracks how many ticks have passed server side since the world was first started. The clock will pause (usually) when all clients disconnect as BYOND deliberately doesn't continue running the world when there are no clients connected -- this would apply using your version too. To get a more accurate count even when the server was clear of all players but still running, you'd either have to run it in DreamDaemon using the option that keeps the world running, or base it off of world.realtime instead (accepting the inaccuracy of that value). Remember, divide world.time or world.realtime by 10 to get seconds from ticks. Finally, bear in mind that using single-precision floating point (like BYOND does, or at least did last time I checked), you will only be able to have 16,777,215 ticks before the clock becomes inaccurate -- which is approximately 466 hours. I'd be very impressed by a BYOND game with that kind of uptime, though! |