Restart countdown

I was wandering if it was possible if someone could make an addon or script that counts down from 30 seconds for a server restart.
Players on my server can get very frustrated when the restart Just happens. Is there a way it can be made so it counts down when a command is typed, and it restarts when it gets to 0 automatically?

P.S The server is DarkRP

Thanks,
Jonny

What kinda server restart?

A map change or full SRCDS restart?

Just a restart that restarts all files, say, if a new addon is installed, it will restart so the addon can then be shown, I guess thats a full SRCDS restart?

Also, The countdown shows up like this…

(THE TOP ONE, NOT PAYDAY ONE)

But the writing would say: Server restart in 30 seconds
Then every second, another one of those comes up, so it would look like

Server restart in 30 seconds
1 second later
Server restart in 29 seconds
all the way to 0, which is when server restarts

Sorry for the long wait, I had to do something.
Put in lua/autorun/restart.lua
Type dorestart in console to perform the restart, and edit the CONFIG table to your likings.

[lua]

if( SERVER )then
local ADMIN, SUPERADMIN = 1, 2;

/* EDIT BELOW THIS AREA */

local CONFIG = {

	Access		= ADMIN,	// Make it so only admins can run the command. Give people admin/superadmin with settings/users.txt
	TimeToWait	= 25,		// Make it wait 25 minutes until it restarts
	Increments = { .5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 23, 24, 24.5 }, // When should we display a notification that the server is restarting
	
};

/* EDIT ABOVE THIS AREA */

local function Thiink( ... )
	
	if( !_G[ "ServerRestart" ] || !_G[ "ServerRestart" ].Enabled )then error( "Tried to restart the server by accident?" ); return; end
	if( _G[ "ServerRestart" ].IncQue == 0 )then game.ConsoleCommand( "changelevel " .. game.GetMap() ); return; end
	
	// If we didn't notify the player yet, send them a notification in TimeToWait - Increments[ #Increments ], else do LastIncrement - CurrentIncrement
	local Delay = ( _G[ "ServerRestart" ].IncQue == #CONFIG.Increments )and( CONFIG.TimeToWait - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] ) or ( CONFIG.Increments[ _G[ "ServerRestart" ].IncQue + 1 ] - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] );
	
	timer.Create( "ShowRestartNotifications", Delay * 60, 1, function( ... )
		NotifyAll( 1, 3, "Server restart in " .. CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] .. " minutes!" );
		_G[ "ServerRestart" ].IncQue = _G[ "ServerRestart" ].IncQue - 1;
		Thiink();
	end );
	
end

concommand.Add( "dorestart", function( ply, cmd, args )
	
	if( !NotifyAll )then
		print( "The person that requested this script wanted it for DarkRP. Sorry :[" );
		return;
	end
	
	if( IsValid( ply ) && ((CONFIG.Access == ADMIN && ply:IsAdmin()) || (CONFIG.Access == SUPERADMIN && ply:IsSuperAdmin())) )then
		
		if( _G[ "ServerRestart" ] && _G[ "ServerRestart" ].Enabled )then
			ply:ChatPrint( "A server restart is already in progress!" );
			return;
		end
		
		_G[ "ServerRestart" ] = {
			Enabled		= true,
			IncQue		= #CONFIG.Increments,
			Length		= CONFIG.TimeToWait * 60,
			Date		= os.time() + CONFIG.TimeToWait * 60,
			EDate		= CurTime() + CONFIG.TimeToWait * 60,
		};
		
		NotifyAll( 1, 3, "Server restart in " .. CONFIG.TimeToWait .. " minutes!" );
		Thiink();
		
	end
	
end );

end
[/lua]

thank you!
I added you on steam btw!

P.S I create restart.lua yes?

Yea. Make sure you make restart.lua inside lua/autorun

And, I want to make it for OWNER and HEAD ADMIN rank, Do i just check out what there TEAM_ name is in shared.lua for gamemode?
Meaning, Owner would be TEAM_OWNER

[lua]
if( SERVER )then

/* EDIT BELOW THIS AREA */

local CONFIG = {

    TimeToWait  = 25,       // Make it wait 25 minutes until it restarts
    Increments = { .5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 23, 24, 24.5 }, // When should we display a notification that the server is restarting
    
};

/* EDIT ABOVE THIS AREA */

local function Thiink( ... )
     
    if( !_G[ "ServerRestart" ] || !_G[ "ServerRestart" ].Enabled )then error( "Tried to restart the server by accident?" ); return; end
    if( _G[ "ServerRestart" ].IncQue == 0 )then game.ConsoleCommand( "changelevel " .. game.GetMap() ); return; end
     
    // If we didn't notify the player yet, send them a notification in TimeToWait - Increments[ #Increments ], else do LastIncrement - CurrentIncrement
    local Delay = ( _G[ "ServerRestart" ].IncQue == #CONFIG.Increments )and( CONFIG.TimeToWait - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] ) or ( CONFIG.Increments[ _G[ "ServerRestart" ].IncQue + 1 ] - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] );
     
    timer.Create( "ShowRestartNotifications", Delay * 60, 1, function( ... )
        NotifyAll( 1, 3, "Server restart in " .. CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] .. " minutes!" );
        _G[ "ServerRestart" ].IncQue = _G[ "ServerRestart" ].IncQue - 1;
        Thiink();
    end );
     
end
 
concommand.Add( "dorestart", function( ply, cmd, args )
     
    if( !NotifyAll )then
        print( "The person that requested this script wanted it for DarkRP. Sorry :[" );
        return;
    end
     
    if( IsValid( ply ) && (ply:Team() == TEAM_OWNER || ply:Team() == TEAM_HEAD_ADMIN) )then
         
        if( _G[ "ServerRestart" ] && _G[ "ServerRestart" ].Enabled )then
            ply:ChatPrint( "A server restart is already in progress!" );
            return;
        end
         
        _G[ "ServerRestart" ] = {
            Enabled     = true,
            IncQue      = #CONFIG.Increments,
            Length      = CONFIG.TimeToWait * 60,
            Date        = os.time() + CONFIG.TimeToWait * 60,
            EDate       = CurTime() + CONFIG.TimeToWait * 60,
        };
         
        NotifyAll( 1, 3, "Server restart in " .. CONFIG.TimeToWait .. " minutes!" );
        Thiink();
         
    end
     
end );

end
[/lua]

Change the team names in line 37 to your liking, although I think you should give owners/head admins a rank in the users.txt so that they don’t have to be a specific job to restart the server.

They have a rank in the Evolve menu, we have ‘Guest, VIP, admin, Super admin, Head admin, Owner’
What I meant is, I want it so Head admin and Owner can only do the restart,

So this line…
Access = ADMIN, // Make it so only admins can run the command. Give people admin/superadmin with settings/users.txt

should be changed to

Access = OWNER, HEAD ADMIN // Make it so only owners or head admins can run the command. Give people admin/superadmin with settings/users.txt

?
I doubt thats correct, but yeah :S

I just tried it on the server and it didnt work :confused:

It just says
Unknown command “restartnow”
] rcon dorestart
The person that requested this script wanted it for DarkRP. Sorry :[

restartnow didnt work
so i did rcon restartnow
then this comes up… The person that requested this script wanted it for DarkRP. Sorry :[

(I tried the first one you did)

http://puu.sh/1t3Nl

What version of DarkRP are you running?

the latest

I think it uses GAMEMODE.NotifyAll now, not just NotifyAll

How would it look on the script?
(I’m shit at lua…)

[lua]
if( SERVER )then

/* EDIT BELOW THIS AREA */

local CONFIG = {

    TimeToWait  = 25,       // Make it wait 25 minutes until it restarts
    Increments = { .5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 23, 24, 24.5 }, // When should we display a notification that the server is restarting
     
};

/* EDIT ABOVE THIS AREA */

local function Thiink( ... )
      
    if( !_G[ "ServerRestart" ] || !_G[ "ServerRestart" ].Enabled )then error( "Tried to restart the server by accident?" ); return; end
    if( _G[ "ServerRestart" ].IncQue == 0 )then game.ConsoleCommand( "changelevel " .. game.GetMap() ); return; end
      
    // If we didn't notify the player yet, send them a notification in TimeToWait - Increments[ #Increments ], else do LastIncrement - CurrentIncrement
    local Delay = ( _G[ "ServerRestart" ].IncQue == #CONFIG.Increments )and( CONFIG.TimeToWait - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] ) or ( CONFIG.Increments[ _G[ "ServerRestart" ].IncQue + 1 ] - CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] );
      
    timer.Create( "ShowRestartNotifications", Delay * 60, 1, function( ... )
         GAMEMODE:NotifyAll( 1, 3, "Server restart in " .. CONFIG.Increments[ _G[ "ServerRestart" ].IncQue ] .. " minutes!" );
        _G[ "ServerRestart" ].IncQue = _G[ "ServerRestart" ].IncQue - 1;
        Thiink();
    end );
      
end
  
concommand.Add( "dorestart", function( ply, cmd, args )
      
    if( GAMEMODE.NotifyAll )then
        print( "The person that requested this script wanted it for DarkRP. Sorry :[" );
        return;
    end
      
    if( IsValid( ply ) && (ply:Team() == TEAM_OWNER || ply:Team() == TEAM_HEAD_ADMIN) )then
          
        if( _G[ "ServerRestart" ] && _G[ "ServerRestart" ].Enabled )then
            ply:ChatPrint( "A server restart is already in progress!" );
            return;
        end
          
        _G[ "ServerRestart" ] = {
            Enabled     = true,
            IncQue      = #CONFIG.Increments,
            Length      = CONFIG.TimeToWait * 60,
            Date        = os.time() + CONFIG.TimeToWait * 60,
            EDate       = CurTime() + CONFIG.TimeToWait * 60,
        };
          
        GAMEMODE:NotifyAll( 1, 3, "Server restart in " .. CONFIG.TimeToWait .. " minutes!" );
        Thiink();
          
    end
      
end );

end
[/lua]

Try that… and the command is ‘dorestart’ not restart now

I don’t want it for Jobs only who can do it, i want it so only head admins and owners can do the command :confused:
It’s evolve groups btw :confused:

bump

Just change it to what ever you need to
[lua]ply:Team() == TEAM_OWNER [/lua]

[lua]evovle.GetRanks(“admin”)[/lua]

How would it look like on the rest of the script? Can you show me please so I can just add it to my server? Thanks :confused: