Advertisement
xX-AAAAAAAAAA-Xx

Untitled

Aug 17th, 2024 (edited)
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. -- Countdown to every 4 hours after 2 AM
  2. -- Display "Time Until Server Restart" (hh:mm:ss) on a single 2x2 screen
  3.  
  4. -- Wrap the single 2x2 screen on top
  5. local screen = peripheral.wrap("top")
  6.  
  7. -- Function to format time as hh:mm:ss
  8. function formatTime(seconds)
  9.     local hours = math.floor(seconds / 3600)
  10.     local minutes = math.floor((seconds % 3600) / 60)
  11.     local secs = seconds % 60
  12.     return string.format("%02d:%02d:%02d", hours, minutes, secs)
  13. end
  14.  
  15. -- Function to calculate seconds until next interval
  16. function getSecondsUntilNextInterval()
  17.     local currentHour = os.time("UTC") % 24 -- Get current hour from 0 to 23
  18.     local intervals = {4, 10, 18, 22} -- Interval hours
  19.  
  20.     -- Find the next interval
  21.     local nextIntervalHour = intervals[1]
  22.     for _, hour in ipairs(intervals) do
  23.         if currentHour < hour then
  24.             nextIntervalHour = hour
  25.             break
  26.         end
  27.     end
  28.  
  29.     -- Calculate the number of hours until the next interval
  30.     local hoursUntilNextInterval = (nextIntervalHour - currentHour + 24) % 24
  31.     local secondsUntilNextInterval = hoursUntilNextInterval * 3600
  32.  
  33.     return secondsUntilNextInterval
  34. end
  35.  
  36. -- Function to clear the screen
  37. function clearScreen()
  38.     screen.clear()
  39.     screen.setCursorPos(1, 1)
  40. end
  41.  
  42. -- Function to display text on the 2x2 screen
  43. function displayOnScreen(text)
  44.     clearScreen()
  45.     screen.write(text)
  46. end
  47.  
  48. -- Main loop to update the countdown
  49. while true do
  50.     local secondsRemaining = getSecondsUntilNextInterval()
  51.     local timeFormatted = formatTime(secondsRemaining)
  52.    
  53.     -- Display the countdown
  54.     displayOnScreen("Time Until Server Restart: " .. timeFormatted)
  55.  
  56.     -- Update every second
  57.     sleep(0.1)
  58. end
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement