Advertisement
IHATEMICROWAVEOVEN

scheduled shutdown

Dec 12th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. -- constants
  2. local RunService = game:GetService("RunService")
  3. local SECS_IN_DAY = 86400
  4.  
  5. -- to customize
  6. local resetsPerDay = 3
  7. --local resetsPerDay = 512
  8. local warningTimes = {60*60, 20*60, 10*60, 5*60, 2*60, 60, 30}
  9. -- alerts occur at these times before the reset; has to be from greatets to least, and no repeating
  10.  
  11. local resetEvery = SECS_IN_DAY/resetsPerDay -- eg secs per reset
  12.  
  13.  
  14.  
  15.  
  16.  
  17. -- functions
  18. local function SendNotification(plr, text)
  19. if game.ReplicatedStorage:FindFirstChild("ChatEvent") then
  20. game.ReplicatedStorage:FindFirstChild("ChatEvent"):FireClient(plr, "Shutdown Warning", text, Color3.new(255/255, 255/255, 25/255), Color3.new(255/255, 255/255, 25/255), "", true, "")
  21. end
  22. end
  23.  
  24. local function convertToFormat(secsDisplay)
  25. local hrPart = "0"..math.floor(secsDisplay/3600)
  26. hrPart = string.sub(hrPart, string.len(hrPart)-1, string.len(hrPart))
  27. local minPart = "0"..(math.floor(secsDisplay/60)%60)
  28. minPart = string.sub(minPart, string.len(minPart)-1, string.len(minPart))
  29. local secsPart = "0"..(math.floor(secsDisplay)%60) -- this is my favorite part
  30. secsPart = string.sub(secsPart, string.len(secsPart)-1, string.len(secsPart))
  31.  
  32. return hrPart..":"..minPart..":"..secsPart
  33. end
  34.  
  35. local function updateDisplay(secsDisplay) -- arg: seconds to display
  36. script.Sign.SurfaceGui.TextLabel.Text =
  37. "Time Left Until Shutdown - "..convertToFormat(secsDisplay)
  38. end
  39.  
  40. local function warnThroughNotification(secsDisplay) -- arg: seconds to display
  41. local warning = convertToFormat(secsDisplay).." until shutdown"
  42. for i,v in pairs(game.Players:GetPlayers()) do
  43. SendNotification(v, warning)
  44. end
  45. end
  46.  
  47.  
  48.  
  49.  
  50. -- waiting and updating billboard
  51. local secondsLeft = resetEvery - (math.round(tick())%resetEvery)
  52. local shutdownTick = tick() + secondsLeft
  53. local warnI = 1
  54. while warningTimes[warnI] > secondsLeft do warnI+=1 end
  55.  
  56. while tick()<shutdownTick do
  57. updateDisplay(secondsLeft)
  58. if warnI<#warningTimes and warningTimes[warnI] >= secondsLeft then
  59. warnThroughNotification(secondsLeft)
  60. warnI+=1
  61. end
  62. task.wait(0.98)
  63. secondsLeft = resetEvery - (math.round(tick())%resetEvery)
  64. end
  65.  
  66.  
  67.  
  68.  
  69.  
  70. -- shutting down
  71. local funnyMessages = {
  72. "A Rapscalafin has wiped out EG",
  73. "kinghtgold12 touched the code",
  74. "GET OUT",
  75. "ar ar ar ar ar ar ar",
  76. "collect my pages hidden throughout the spawn"
  77. }
  78.  
  79. local shutdownMessage = "The server has shut down. Reason: "
  80.  
  81. if math.random(1,3)==1 then
  82. shutdownMessage = shutdownMessage..funnyMessages[math.random(1, #funnyMessages)]
  83. else
  84. shutdownMessage = shutdownMessage.."None"
  85. end
  86.  
  87. while true do
  88. for i,v in pairs(game.Players:GetPlayers()) do
  89. v:Kick(shutdownMessage)
  90. end
  91. task.wait(1)
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement