Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = {}
- util.AddNetworkString("ASAP.PingServer")
- util.AddNetworkString("ASAP.RestartWarning")
- config.Time = 900 -- time before server restarts after the command is ran in seconds
- config.Delay = 10 -- time before the restart is executed after running the command (45 minutes default)
- function restart_server()
- end
- function force_restart()
- if timer.Exists("restart") then
- timer.Adjust("restart", config.Time, 1, function()
- restart_server()
- end)
- else
- timer.Create("restart", config.Time, 1, function()
- restart_server()
- end)
- end
- end
- hook.Add("PlayerInitialSpawn", "ASAP.PingServer", function(ply)
- net.Start("ASAP.PingServer")
- net.Send(ply)
- end)
- net.Receive("ASAP.PingServer", function(l, ply)
- timer.Simple(3, function()
- net.Start("ASAP.PingServer")
- net.Send(ply)
- end)
- end)
- concommand.Add("cancel_restart", function()
- if CLIENT then return end
- SetGlobalInt("Restart", -1)
- net.Start("ASAP.RestartWarning")
- net.WriteBool(false)
- net.Broadcast()
- end)
- concommand.Add("restart_server", function(ply)
- if CLIENT then return end
- SetGlobalInt("Restart", CurTime() + config.Delay)
- net.Start("ASAP.RestartWarning")
- net.WriteBool(true)
- net.Broadcast()
- timer.Simple(config.Delay, function()
- force_restart()
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement