Need help about code
#1

Hello guys, I have one problem. I am working on one mode so I made a classic "clock".
But I want that when the time is 00 and minutes 00 my server restar on just few seconds.
I tried with this but it doesn't work.
Код:
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;
}
Reply
#2

Server is repead restartin while there is 00 minutes
Myb. I need to add seconds, but there is a lot of errors if i do that.
Reply
#3

Do not use on player update. Use timer. Why you need to restart the server at 0:00?

Variable:
Код:
static timerRestart;
OnGameModeInit:
Код:
timerRestart = SetTimer("RestartCheck", 2000, true);
OnGameModeExit:
Код:
KillTimer(timerRestart);
Код:
forward RestartCheck();
public RestartCheck() {
        // your code
}
Reply
#4

Quote:
Originally Posted by xMoBi
Посмотреть сообщение
Do not use on player update. Use timer. Why you need to restart the server at 0:00?
Thnaks for suggestion
I want to make sure that server will be fresh.
Mby. I can make timer for server restart on 3 or 4 hours, what do you think ?
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=654663

Restarting the server at midnight every day can be quite achievable with the plugin.

pawn Код:
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);
It will get the timestamp at midnight of the next day and will subtract the current timestamp. The difference will be in seconds from the plugin so we multiply by 1000 to get milliseconds.

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.
Reply
#6

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=654663

Restarting the server at midnight every day can be quite achievable with the plugin.

pawn Код:
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);
It will get the timestamp at midnight of the next day and will subtract the current timestamp. The difference will be in seconds from the plugin so we multiply by 1000 to get milliseconds.

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.
Thanks man this is so helpful
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)