Server Uptime? - 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 Uptime? (
/showthread.php?tid=187062)
Fixed -
Tekto - 31.10.2010
Hello there.
I have an question, how to make some system, that checks how long has been server up ?
Some timer or what ?
Please help.
Thanks.
Re: Server Uptime? -
The_Moddler - 31.10.2010
I have that on my server, it's pretty usefull.
I made it with a timer and variables..
You set te timer to one second, and you increase the variable, when the variable reached 60, you reset it to 0 and you add to the minutes variable, and the same with hours and days.
I hope you undertand
Re: Server Uptime? -
Tekto - 31.10.2010
Maybe you make some code ? Im not so pro
Re: Server Uptime? -
Miguel - 31.10.2010
pawn Код:
new
Hours,
Minutes,
Seconds;
public OnGameModeInit()
{
SetTimer("EverySecond", 1000, true);
return 1;
}
forward EverySecond();
public EverySecond()
{
Seconds ++;
if(Seconds > 59)
{
Minutes ++;
Seconds = 0;
}
if(Minutes > 59)
{
Hours ++;
Minutes = 0;
}
return 1;
}
As simple as that...
Re: Server Uptime? -
Tekto - 31.10.2010
And how can I display it ?
SOmething like SendClientMessage(playerid, COLOR_RED, " Server has been up for %s Hours and %s Minutes",Hours, Minutes");
Re: Server Uptime? -
Miguel - 31.10.2010
Use format():
pawn Код:
public OnPlayerSpawn(playerid) // example callback
{
new string[69];
format(string, sizeof(string), "This server has been up for %d hours, %d minutes and %d seconds.", Hours, Minutes, Seconds);
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
Re: Server Uptime? -
WillyP - 31.10.2010
pawn Код:
new string[80];
format(string, sizeof(string), "This server has been up for %d hours, %d minutes and %d seconds.", Hours, Minutes, Seconds);
SendClientMessage(playerid, YOURCOLOURHERE, string);
edit:
Miguel beat me
Re: Server Uptime? -
Lenny the Cup - 31.10.2010
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;
}
Re: Server Uptime? -
Miguel - 31.10.2010
Quote:
Originally Posted by Lenny the Cup
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; }
|
I never thought of that, thank you for sharing.
Re: Server Uptime? -
The_Moddler - 31.10.2010
Quote:
Originally Posted by Lenny the Cup
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; }
|
Hmmm, pretty difficult the maths.. thanks for sharing.