27.12.2013, 16:34
Use 1388150620 as a reference. Get a new reference everytime you want to know the uptime and compare it to the very first one you got (just substract). If you want your uptime in hours and minutes, you would have to do the math with that substraction, there are a few tutorials that cover how to do that.
This is an example:
P.D: gettime returns an unix timestamp... https://sampwiki.blast.hk/wiki/gettime
This is an example:
pawn Код:
enum eDateTimeInfo
{
day, month, year, hours, minutes, seconds
};
new gVeryFirstTimestamp = 0; // This will be a reference.
new gWhenDidItStart[eDateTimeInfo]; // This will be an actual date-time.
public OnGameModeInit()
{
gVeryFirstTimestamp = gettime();
getdate(gWhenDidItStart[year], gWhenDidItStart[month], gWhenDidItStart[day]);
gettime(gWhenDidItStart[hours], gWhenDidItStart[minutes], gWhenDidItStart[seconds]);
// You could store these variables in a file and just load it everytime the server starts
return 1;
}
// Your IRC command:
new string[128];
new uptime = gettime() - gVeryFirstTimestamp;
format(string, sizeof(string), "The server has been up for %i seconds.", uptime);
// IRC message.
format(string, sizeof(string), "It's been up since %02i/%02i/%i at %02i:%02i", gWhenDidItStart[day], gWhenDidItStart[month], gWhenDidItStart[year],
gWhenDidItStart[hours], gWhenDidItStart[minutes]);
// IRC message.