Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------
- -- Alarm, 5 min countdown for command computer
- -- by SukaiPoppuGo
- --
- -- Usage: Alarm 4 55
- -- set the alarm at 4h55, for a countdown until 5h00
- local alarmH, alarmM = ...
- local alarm = tonumber(alarmH) + (tonumber(alarmM)/60)
- print("Alarm set at:", alarm, "(", alarmH.."h"..alarmM, ")")
- -- Formate un nombre de secondes en durée lisible
- local function timeStr(sec)
- local d = math.floor(sec/86400) --24*60*60 sec
- local h = math.floor(sec/3600)%24 -- 60x60 sec
- local m = math.floor(sec/60)%60 -- 60sec
- local s = math.floor(sec%60) --Reste
- local str = ""
- if d>0 then str = d>1 and d.." days " or "1 day " end
- if h>0 then str = str..h.."h" end
- if m>0 then str = str..(m>9 and m or "0"..m) end
- if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
- return str
- end
- local function delayUpdate()
- local h = os.time("local")
- print("Start delay at", textutils.formatTime( h, true ) )
- if h > alarm then
- return (24 - h + alarm) * 60 * 60 -- conversion en nombre de secondes
- else
- return (alarm - h) * 60 * 60
- end
- end
- repeat
- local delay = os.startTimer(delayUpdate())
- print("Delay:", timeStr(delay))
- os.pullEvent("timer")
- for i=5,0,-1 do
- local message = string.format("§c§lReboot du serveur dans %s min", i)
- commands.say(message)
- print("Say:", message)
- print("at", textutils.formatTime( os.time("local"), true ) )
- sleep(60)
- end
- until false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement