Advertisement
skypop

CC Alarm (command computer)

Sep 9th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. --------------------
  2. -- Alarm, 5 min countdown for command computer
  3. -- by SukaiPoppuGo
  4. --
  5.  
  6. -- Usage: Alarm 4 55
  7. -- set the alarm at 4h55, for a countdown until 5h00
  8. local alarmH, alarmM = ...
  9.  
  10. local alarm = tonumber(alarmH) + (tonumber(alarmM)/60)
  11.  
  12. print("Alarm set at:", alarm, "(", alarmH.."h"..alarmM, ")")
  13.  
  14. -- Formate un nombre de secondes en durée lisible
  15. local function timeStr(sec)
  16.     local d = math.floor(sec/86400) --24*60*60 sec
  17.     local h = math.floor(sec/3600)%24 -- 60x60 sec
  18.     local m = math.floor(sec/60)%60 -- 60sec
  19.     local s = math.floor(sec%60) --Reste
  20.     local str = ""
  21.     if d>0 then str = d>1 and d.." days " or "1 day " end
  22.     if h>0 then str = str..h.."h" end
  23.     if m>0 then str = str..(m>9 and m or "0"..m) end
  24.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  25.     return str
  26. end
  27.  
  28. local function delayUpdate()
  29.     local h = os.time("local")
  30.     print("Start delay at", textutils.formatTime( h, true ) )
  31.    
  32.     if h > alarm then
  33.         return (24 - h + alarm) * 60 * 60 -- conversion en nombre de secondes
  34.     else
  35.         return (alarm - h) * 60 * 60
  36.     end
  37. end
  38.        
  39. repeat
  40.     local delay = os.startTimer(delayUpdate())
  41.     print("Delay:", timeStr(delay))
  42.     os.pullEvent("timer")
  43.     for i=5,0,-1 do
  44.         local message = string.format("§c§lReboot du serveur dans %s min", i)
  45.         commands.say(message)
  46.         print("Say:", message)
  47.         print("at", textutils.formatTime( os.time("local"), true ) )
  48.         sleep(60)
  49.     end
  50. until false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement