31.10.2010, 21:54
There's no need to use a timer, just store the startup time in a variable and count the amount of seconds since last.
pawn Код:
new StartTime;
// Put this line in OnGameModeInit:
StartTime = gettime();
// Put this function somewhere in the script and call it while formating a string (Example: format(string, sizeof(string), "The server has been online for %s.", GetUptime());
stock GetUptime()
{ // Thanks to JernejL @ sa-mp.scripting for the maths
new Result[45],
Remaining = gettime()-StartTime,
Time[4];
Time[0] = Remaining % 60; // Seconds
Remaining /= 60;
Time[1] = Remaining % 60; // Minutes
Remaining /= 60;
Time[2] = Remaining % 24; // Hours
Remaining /= 24;
Time[3] = Remaining; // Days
if(Time[3])
format(Result, 45, "%d days, %d hours, %d minutes and %d seconds", Time[3], Time[2], Time[1], Time[0]);
else if(Time[2])
format(Result, 45, "%d hours, %d minutes and %d seconds", Time[2], Time[1], Time[0]);
else if(Time[1])
format(Result, 45, "%d minutes and %d seconds", Time[1], Time[0]);
else
format(Result, 45, "%d seconds", Time[0]);
return Result;
}