SA-MP Forums Archive
Server restart command in a loop - 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)
+--- Thread: Server restart command in a loop (/showthread.php?tid=547246)



Server restart command in a loop - Jhony_Blaze - 21.11.2014

Hey, so I got this /restart command, but when I execute it in the server, it won't restart it, it just enters in a loop and shows only the message for the players. Here is the code. Please help me with it.


Код:
COMMAND:restart(playerid, params[])
{
	// Setup local variables
	new Msg[128];

	// Send the command to all admins so they can see it
	SendAdminText(playerid, "/restart", params);

	// Check if the player has logged in
	if (APlayerData[playerid][LoggedIn] == true)
	{
		// Check if the player's admin-level is at least 5
		if (APlayerData[playerid][PlayerLevel] >= 5)
		{

           // Let everyone know that the server will be restarted in "RestartTime" minutes (provided by the admin)
           SendClientMessageToAll(-1, "* The server will be going down for Scheduled Maintenance, Estimated Downtime: 1-3 Minutes.");
           SendClientMessageToAll(-1, "We will be going down to do some maintenance on the server/script, we will be back online shortly.");
           format(Msg, 128, "Server restart in 30 seconds!", RestartTime);
           GameTextForAll(Msg, 5000, 3);
           SendClientMessageToAll(0xA0A0A0, Msg);
           // Start the next timer which warns the players again every minute
   	       SetTimer("Timer_Restart", 30000, false);

		}
		else
		    return 0;
	}
	else
	    return 0;

	// Let the server know that this was a valid command
	return 1;
}

forward Timer_Restart();
public Timer_Restart()
{
	// Setup local variables
	new Msg[128];

	// Decrease the RestartTime by one minute
	RestartTime--;

	// Let everyone know that the server will be restarted in 2 minutes
    format(Msg, 128, "Server restart in 30 seconds!", RestartTime);
	GameTextForAll(Msg, 5000, 3);
	SendClientMessageToAll(0xA0A0A0, Msg);

	// Do different things based on the remaining time
	switch (RestartTime)
	{
		case 1: // One minute left
		{
			// Change the hostname of the server and change the RCON-password to something weird
			SendRconCommand("hostname Pending Restart");
			SendRconCommand("password loafkagakggoagka");
		}
		case 0:
		{
			// Let everyone know that the server is kicking all players before restarting
			GameTextForAll("Server restarting:Kicking all players!", 5000, 3);

			// Start the next timer that will restart the server
			SetTimer("Timer_Restart_Reboot", 30000, false);
		}
	}
}

forward Timer_Restart_Reboot();
public Timer_Restart_Reboot()
{
	new HostCommand[128];

	// Restart the server
	SendRconCommand("gmx");
	// Change the hostname and password again
	format(HostCommand, 128, "hostname %s", GameModeName);
	SendRconCommand(HostCommand);
	SendRconCommand("password 0");

	return 1;
}



Re: Server restart command in a loop - Jhony_Blaze - 21.11.2014

69 views (seeing this 69 a lot lately lol ) there is no one that could help me ?


Re: Server restart command in a loop - UltraScripter - 21.11.2014

You Can Use
Код:
 /rcon gmx
instead


Re: Server restart command in a loop - Jhony_Blaze - 21.11.2014

Can you explain more deeply ?


Re: Server restart command in a loop - UltraScripter - 21.11.2014

every samp server allready have restart command
login as admin
and type /rcon gmx
/rcon gmx will restart you'r Server ! .


Re: Server restart command in a loop - AndySedeyn - 21.11.2014

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
every samp server allready have restart command
login as admin
and type /rcon gmx
/rcon gmx will restart you'r Server ! .
Which I do not recommend using for obvious reasons.
https://sampforum.blast.hk/showthread.php?tid=250121

Unless you use:
http://forum.sa-mp.com/showthread.ph...07#post1176007

The best way to restart a server is by kicking all the players before sending the rcon command just as you did in the example code.

There are quite a few mistakes in your script.
  1. You are nowhere assigning a value to "RestartTime"
  2. You are formatting a message where it says that the Restart time will be around 30 seconds and yet, you are decreasing it by a minute in the Timer function.