Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Countdown to every 4 hours after 2 AM
- -- Display "Time Until Server Restart" (hh:mm:ss) on a single 2x2 screen
- -- Wrap the single 2x2 screen on top
- local screen = peripheral.wrap("top")
- -- Function to format time as hh:mm:ss
- function formatTime(seconds)
- local hours = math.floor(seconds / 3600)
- local minutes = math.floor((seconds % 3600) / 60)
- local secs = seconds % 60
- return string.format("%02d:%02d:%02d", hours, minutes, secs)
- end
- -- Function to calculate seconds until next interval
- function getSecondsUntilNextInterval()
- local currentHour = os.time("UTC") % 24 -- Get current hour from 0 to 23
- local intervals = {4, 10, 18, 22} -- Interval hours
- -- Find the next interval
- local nextIntervalHour = intervals[1]
- for _, hour in ipairs(intervals) do
- if currentHour < hour then
- nextIntervalHour = hour
- break
- end
- end
- -- Calculate the number of hours until the next interval
- local hoursUntilNextInterval = (nextIntervalHour - currentHour + 24) % 24
- local secondsUntilNextInterval = hoursUntilNextInterval * 3600
- return secondsUntilNextInterval
- end
- -- Function to clear the screen
- function clearScreen()
- screen.clear()
- screen.setCursorPos(1, 1)
- end
- -- Function to display text on the 2x2 screen
- function displayOnScreen(text)
- clearScreen()
- screen.write(text)
- end
- -- Main loop to update the countdown
- while true do
- local secondsRemaining = getSecondsUntilNextInterval()
- local timeFormatted = formatTime(secondsRemaining)
- -- Display the countdown
- displayOnScreen("Time Until Server Restart: " .. timeFormatted)
- -- Update every second
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement