Advertisement
Te-ki

CCRedstoneAlarm

Mar 11th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --CC Redstone Alarm by Teki
  2. local side = "back"
  3.  
  4. local tArgs = { ... }
  5.  
  6. local startActive = 0
  7. local redstoneState = "inactive"
  8.  
  9. local curTime = 0
  10. local hours = 0
  11. local minutes = 0
  12.  
  13. local startHour = 0
  14. local startMin = 0
  15. local endHour = 0
  16. local endMin = 0
  17.  
  18. if #tArgs > 4 then
  19.     startActive = tonumber(tArgs[5])
  20.     if startActive == 1 then
  21.         redstone.setOutput(side, true)
  22.     else
  23.         redstone.setOutput(side, false)
  24.     end
  25. end
  26.  
  27. if #tArgs > 3 then
  28.     startHour = tonumber(tArgs[1])
  29.     startMin = tonumber(tArgs[2])
  30.     endHour = tonumber(tArgs[3])
  31.     endMin = tonumber(tArgs[4])
  32. elseif #tArgs > 1 then
  33.     startHour = tonumber(tArgs[1])
  34.     endHour = tonumber(tArgs[2])
  35. else
  36.     print("Tape RedstoneAlarm <1> <2> <3> <4> <5>")
  37.     print("<1> : Heure de depart")
  38.     print("<2> : Minutes de depart")
  39.     print("<3> : Heure de fin")
  40.     print("<4> : Minutes de fin")
  41.     print("<5> : (0/1) Redstone Inactive/active au demarage")
  42.     return 0
  43. end
  44.  
  45. function getTime()
  46.     hours = http.get("http://www.timeapi.org/gmt/in+1+hour?format=%25H")
  47.     minutes = http.get("http://www.timeapi.org/gmt/in+1+hour?format=%25M")
  48. end
  49.  
  50. function activate()
  51.     if startActive == 1 then
  52.         redstone.setOutput(side, false)
  53.     else
  54.         redstone.setOutput(side, true)
  55.     end
  56. end
  57.  
  58. function deactivate()
  59.     if startActive == 1 then
  60.         redstone.setOutput(side, true)
  61.     else
  62.         redstone.setOutput(side, false)
  63.     end
  64. end
  65.  
  66. while true do
  67.     getTime()
  68.     if hours ~= nil and minutes ~= nil then
  69.         hours = tonumber(hours.readAll())
  70.         minutes = tonumber(minutes.readAll())
  71.        
  72.         if hours >= startHour and hours <= endHour then
  73.             if startHour ~= endHour then
  74.                 if hours == endHour and minutes < endMin then
  75.                     activate()
  76.                 elseif hours == startHour and minutes >= startMin then
  77.                     activate()
  78.                 elseif hours > startHour and hours < endHour then
  79.                     activate()
  80.                 else
  81.                     deactivate()
  82.                 end
  83.             else
  84.                 if minutes >= startMin and minutes < endMin then
  85.                     activate()
  86.                 else
  87.                     deactivate()
  88.                 end
  89.             end
  90.         else
  91.             deactivate()
  92.         end
  93.        
  94.         if redstone.getOutput(side) == true then
  95.             redstoneState = "active"
  96.         else
  97.             redstoneState = "inactive"
  98.         end
  99.        
  100.         print(hours .. ":" .. minutes .. " : Redstone is " .. redstoneState)
  101.     end
  102.     sleep(10)
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement