Server Uptime?
#8

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;
}
Reply


Messages In This Thread
Fixed - by Tekto - 31.10.2010, 20:49
Re: Server Uptime? - by The_Moddler - 31.10.2010, 20:51
Re: Server Uptime? - by Tekto - 31.10.2010, 20:56
Re: Server Uptime? - by Miguel - 31.10.2010, 21:14
Re: Server Uptime? - by Tekto - 31.10.2010, 21:32
Re: Server Uptime? - by Miguel - 31.10.2010, 21:39
Re: Server Uptime? - by WillyP - 31.10.2010, 21:39
Re: Server Uptime? - by Lenny the Cup - 31.10.2010, 21:54
Re: Server Uptime? - by Miguel - 31.10.2010, 21:59
Re: Server Uptime? - by The_Moddler - 31.10.2010, 22:11

Forum Jump:


Users browsing this thread: 1 Guest(s)