skypop

CC Alarm

Aug 24th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Alarm
  2. -- by SukaiPoppuGo
  3. --
  4. -- Emmet un message d'alerte dans le chat (message privé) à une heure donnée en temps local
  5. -- Require mod PeripheralPlusOne
  6. -- Optional mod Plethora (display on a sign as cheap monitor)
  7. --
  8.  
  9. -------------------------------------------
  10. -- Pause on boot
  11. print("init")
  12. sleep(os.clock()<2 and 2-os.clock() or 0)
  13. print("run")
  14.  
  15. -------------------------------------------
  16. -- PARAMS
  17. -- Définit l'heure où doit sonner l'alarme. Temps en heure décimale
  18. local alarm = 2 + (55/60)
  19. -- Nom du joueur à qui est destiné le message
  20. local player = "Votre nom ici"
  21. -- Contenu du message
  22. local message = "Reboot dans 5min"
  23.  
  24. assert(peripheral.find("chatBox"),"chatBox introuvable")
  25.  
  26. repeat
  27.     local h = os.time("local")
  28.     local diff = h < alarm and alarm - h or 24 - h + alarm
  29.     local delay = os.startTimer(diff * 60 * 60)
  30.    
  31.     repeat
  32.         local t = os.time("local")
  33.        
  34.         term.setCursorPos(1,1)
  35.         term.clear()
  36.         local sTime = textutils.formatTime(t,true)
  37.         local sAlarm = textutils.formatTime(h+diff-t, true)
  38.                
  39.         print(" time:",sTime)
  40.         print("alarm:",sAlarm)
  41.        
  42.         --Monitor du pauvre
  43.         local monitor = peripheral.find("minecraft:sign")
  44.         if monitor then
  45.             monitor.setSignText("","§ltime: "..sTime,"§lalarm: "..sAlarm)
  46.         end
  47.        
  48.         local tick = os.startTimer(20)
  49.         local e,p
  50.         repeat
  51.             e,p = os.pullEventRaw()
  52.             if e == "terminate" then
  53.                 local monitor = peripheral.find("minecraft:sign")
  54.                 if monitor then
  55.                     monitor.setSignText("","§4§lTerminated")
  56.                 end
  57.                 printError("Terminated")
  58.                 return
  59.             end
  60.         until e == "timer" and p == tick
  61.     until e == "timer" and p == delay
  62.    
  63.     print("Alarm")
  64.     local chatBox = peripheral.find("chatBox")
  65.     assert("chatBox","chatBox introuvable")
  66.     chatBox.tell(player,message)
  67.     sleep(20)
  68. until false
Advertisement
Add Comment
Please, Sign In to add comment