Xixili

Purge Countdown Monitor

Aug 29th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. local bCable = "back" -- Side of your bundled Cable
  2. local monitor = peripheral.wrap( "left" )
  3. local timers = { -- Format: {"Starting Mins","Starting Secs",Function to run when done}
  4. {"10","00",function() rs.setBundledOutput("back", colours.red)end},
  5. {"5","00",function() rs.setBundledOutput("back", colours.green) end}
  6. }
  7.  
  8. --# Returns tTime in a xx:xx format
  9. local function formatTime(tTime)
  10. return tTime[1]..":"..tTime[2]
  11. end
  12.  
  13. --# Decrements each timer
  14. local function updateTime()
  15. local allDone = true
  16. for i = 1, #timers do
  17. if timers[i][2] == "00" then
  18. if tonumber(timers[i][1]) > 0 then
  19. timers[i][2] = "59"
  20. timers[i][1] = tostring(tonumber(timers[i][1]) - 1)
  21. allDone = false
  22. elseif type(timers[i][3]) == "function" and not timers[i][4] then
  23. timers[i][4] = true
  24. timers[i][3]()
  25. end
  26. else
  27. timers[i][2] = tostring(tonumber(timers[i][2]) - 1)
  28. if tonumber(timers[i][2]) < 10 then
  29. timers[i][2] = "0"..(tonumber(timers[i][2]))
  30. end
  31. allDone = false
  32. end
  33. end
  34. return not allDone --# Returns 'true' if at least one timer counted down, false if all timers have finished
  35. end
  36.  
  37. --# Prints time to monitor
  38. local function printTime()
  39. monitor.setCursorPos(1,6)
  40. monitor.clearLine()
  41. monitor.write(" T MINUS "..formatTime(timers[1]).." MINUTES")
  42. monitor.setCursorPos(1,10)
  43. monitor.clearLine()
  44. monitor.write(" T MINUS "..formatTime(timers[2]).." MINUTES")
  45. end
  46.  
  47. -- ######################
  48. -- ##
  49. -- ######################
  50.  
  51. monitor.setCursorPos(1, 1)
  52. monitor.setBackgroundColor(colors.black)
  53. monitor.clear()
  54.  
  55. monitor.setTextColor(colors.red)
  56. monitor.setBackgroundColor(colors.black)
  57. monitor.setTextScale(1.5)
  58. monitor.setCursorPos(1, 3)
  59. monitor.write(" DANGER")
  60. monitor.setTextColor(colors.red)
  61. monitor.setBackgroundColor(colors.black)
  62. monitor.setCursorPos(1, 4)
  63. monitor.write(" EMERGENCY DESTRUCTION SYSTEM")
  64. monitor.setTextColor(colors.yellow)
  65. monitor.setBackgroundColor(colors.black)
  66. monitor.setCursorPos(1, 5)
  67. monitor.write(" ON ACTIVATION IT WILL DETONATE IN")
  68. monitor.setTextColor(colors.red)
  69. monitor.setBackgroundColor(colors.black)
  70. monitor.setCursorPos(1, 6)
  71. monitor.write(" T MINUS 10:00 MINUTES")
  72.  
  73. monitor.setTextColor(colors.red)
  74. monitor.setBackgroundColor(colors.black)
  75. monitor.setCursorPos(1, 8)
  76. monitor.write(" FAILSAFE WARNING")
  77. monitor.setTextColor(colors.yellow)
  78. monitor.setBackgroundColor(colors.black)
  79. monitor.setCursorPos(1, 9)
  80. monitor.write(" CUT-OFF SYSTEM WILL NOT OPERATE AFTER")
  81. monitor.setTextColor(colors.red)
  82. monitor.setBackgroundColor(colors.black)
  83. monitor.setCursorPos(1, 10)
  84. monitor.write(" T MINUS 5:00 MINUTES")
  85.  
  86. while true do
  87.  
  88. os.pullEvent("redstone")
  89. if rs.getInput("right") then
  90. rs.setBundledOutput("back", colours.black+colours.orange+colours.white)
  91. local timerID = os.startTimer(1)
  92. while true do
  93. local event = { os.pullEvent() }
  94. if event[1] == "timer" and event[2] == timerID then
  95. if not updateTime() then break end --# Stops when all functions have reached 0:00
  96. printTime()
  97. timerID = os.startTimer(1)
  98. elseif event[1] == "redstone" and rs.getInput("bottom") and tonumber(timers[2][1]..timers[2][2]) > 0 then
  99. os.reboot(1)
  100. end
  101. end
  102. end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment