Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. local config = {}
  2. util.AddNetworkString("ASAP.PingServer")
  3. util.AddNetworkString("ASAP.RestartWarning")
  4. config.Time = 900 -- time before server restarts after the command is ran in seconds
  5. config.Delay = 10 -- time before the restart is executed after running the command (45 minutes default)
  6.  
  7. function restart_server()
  8.  
  9. end
  10.  
  11. function force_restart()
  12. if timer.Exists("restart") then
  13. timer.Adjust("restart", config.Time, 1, function()
  14. restart_server()
  15. end)
  16. else
  17. timer.Create("restart", config.Time, 1, function()
  18. restart_server()
  19. end)
  20. end
  21. end
  22.  
  23. hook.Add("PlayerInitialSpawn", "ASAP.PingServer", function(ply)
  24. net.Start("ASAP.PingServer")
  25. net.Send(ply)
  26. end)
  27.  
  28. net.Receive("ASAP.PingServer", function(l, ply)
  29. timer.Simple(3, function()
  30. net.Start("ASAP.PingServer")
  31. net.Send(ply)
  32. end)
  33. end)
  34.  
  35. concommand.Add("cancel_restart", function()
  36. if CLIENT then return end
  37. SetGlobalInt("Restart", -1)
  38. net.Start("ASAP.RestartWarning")
  39. net.WriteBool(false)
  40. net.Broadcast()
  41. end)
  42.  
  43. concommand.Add("restart_server", function(ply)
  44. if CLIENT then return end
  45. SetGlobalInt("Restart", CurTime() + config.Delay)
  46. net.Start("ASAP.RestartWarning")
  47. net.WriteBool(true)
  48. net.Broadcast()
  49.  
  50. timer.Simple(config.Delay, function()
  51. force_restart()
  52. end)
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement