public OnPlayerUpdate( playerid ) { gettime( gametime,minutes); SetPlayerTime( playerid, gametime, minutes); if(gametime == 00 && minutes == 00 && gameday == 1 || gametime == 00 && minutes == 00 && gameday == 2 || gametime == 00 && minutes == 00 && gameday == 3 || gametime == 00 && minutes == 00 && gameday == 4 || gametime == 00 && minutes == 00 && gameday == 5 || gametime == 00 && minutes == 00 && gameday == 6 || gametime == 00 && minutes == 00 && gameday == 7) { SendRconCommand("gmx"); } gametime++; if(gametime == 0) { gameday ++; } if(gametime == 23 && minutes == 59 && gameday == 0) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Monday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 1) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Monday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 2) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Tuesday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 3) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Wednesday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 4) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Thursday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 5) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Friday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 6) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Saturday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } if(gametime == 23 && minutes == 59 && gameday == 7) { SendClientMessageToAll(COLOR_WHITE,"[NEXT GAME DAY] Sunday"); SendClientMessageToAll(COLOR_ADMIN,"[AUTO ADMIN] The server will restart in one minute to give it a nice fresh start and it will be closed one minute."); } return 1; }
static timerRestart;
timerRestart = SetTimer("RestartCheck", 2000, true);
KillTimer(timerRestart);
forward RestartCheck(); public RestartCheck() { // your code }
Do not use on player update. Use timer. Why you need to restart the server at 0:00?
|
new year, month, day, days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
getdate(year, month, day);
if (month == 2)
{
if (!(year & 3) && ((year % 25) || !(year & 15))) // leap year
{
days_in_month[1] = 29;
}
}
if (++day > days_in_month[month - 1]) // next day is new month?
{
day = 1;
if (++month > 12) // last day of year? Back to January of new year
{
month = 1;
year++;
}
}
new date_time[21];
format(date_time, sizeof date_time, "%d-%02d-%02dT00:00:00Z", year, month, day);
new Timestamp: timestamp_next_day, Timestamp: now = Now();
TimeParse(date_time, ISO6801_FULL_LOCAL, timestamp_next_day);
SetTimer("NextDayRestart", (_:timestamp_next_day - _:now) * 1000, false);
https://sampforum.blast.hk/showthread.php?tid=654663
Restarting the server at midnight every day can be quite achievable with the plugin. pawn Код:
NextDayRestart will be called at midnight, without repeating calculations and complicated stuff. But you need to execute the above code every time the server starts so it will set the timer correctly. The only thing I noticed is that Now() is off ~25 minutes from my local time. |