Advertisement
moneybagsnz

Launch control monitor node

Jan 4th, 2023
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.08 KB | Gaming | 0 0
  1. -- Launch monitor prod
  2.  
  3. -- function timer
  4. function timerlaunch()
  5.   local mon = peripheral.find("monitor")
  6.   local nHours = tonumber(0)
  7.   nHours = nHours or 0
  8.   local nMinutes = tonumber(10)
  9.   nMinutes = nMinutes or 0
  10.   local nSeconds = tonumber(0)
  11.   nSeconds = nSeconds or 0
  12.   local totalTime = (nHours * 36000) + (nMinutes * 600) + (nSeconds * 10)
  13.   local hours, minutes, seconds, sHours, sMinutes, sSeconds, sTenths, countdownTimer, timer, _
  14.   if mon then
  15.     local x
  16.     for i = 1, #mon do
  17.       mon[i].setTextColor(colors.white)
  18.       mon[i].setBackgroundColor(colors.black)
  19.       mon[i].clear()
  20.       mon[i].setTextScale(1)
  21.       x = mon[i].getSize()
  22.       if x == 7 then      --# width = 1
  23.         mon[i].setTextScale(0.5)
  24.       elseif x == 18 then --# width = 2
  25.         mon[i].setTextScale(nHours < 10 and 2 or 1)
  26.       elseif x == 29 then --# width = 3
  27.         mon[i].setTextScale(3)
  28.       elseif x == 39 then --# width = 4
  29.         mon[i].setTextScale(4)
  30.       elseif x >= 50 then --# width = 5+
  31.         mon[i].setTextScale(5)
  32.       end
  33.     end
  34.   end
  35.   for i = totalTime, 0, -1 do
  36.     hours = totalTime > 35999 and math.floor(totalTime / 36000) or 0
  37.     sHours = tostring(hours)
  38.     minutes = totalTime > 599 and math.floor((totalTime - (hours * 36000)) / 600) or 0
  39.     sMinutes = minutes > 9 and tostring(minutes) or "0" .. tostring(minutes)
  40.     seconds = totalTime > 9 and math.floor((totalTime - ((hours * 36000) + (minutes * 600))) / 10) or 0
  41.     sSeconds = seconds > 9 and tostring(seconds) or "0" .. tostring(seconds)
  42.     sTenths = tostring(math.floor(totalTime - ((hours * 36000) + (minutes * 600) + (seconds * 10))))
  43.     term.setCursorPos(1, 1)
  44.     if totalTime == 0 and term.isColor() then term.setTextColor(colors.red) end
  45.     term.write(sHours .. ":" .. sMinutes .. ":" .. sSeconds .. ":" .. sTenths .. " ")
  46.     if mon then
  47.       for i = 1, #mon do
  48.         mon[i].setCursorPos(1, 2)
  49.         if totalTime == 0 and mon[i].isColor() then mon[i].setTextColor(colors.red) end
  50.         mon[i].write(sHours .. ":" .. sMinutes .. ":" .. sSeconds .. ":" .. sTenths .. " ")
  51.       end
  52.     end
  53.     if totalTime > 0 then
  54.       countdownTimer = os.startTimer(0.1)
  55.       repeat
  56.         _, timer = os.pullEvent("timer")
  57.         if timer == countdownTimer then
  58.           totalTime = totalTime - 1
  59.         end
  60.       until timer == countdownTimer
  61.     end
  62.   end
  63. end
  64. -- function end
  65. local mon = peripheral.find("monitor")
  66. mon.setTextScale(4)
  67. mon.clear()
  68. rednet.open("top")
  69. mon.setCursorPos(1,1)
  70. mon.write("Listening")
  71. mon.setCursorPos(1,2)
  72. mon.write("for signal")
  73. local id_1,int_check = rednet.receive()
  74. local id_2,handshake = rednet.receive()
  75. local id_3,startcount = rednet.receive()
  76. local phase2 = false
  77. repeat
  78.     if int_check == "ping" then
  79. --      rednet.send(senderId, "pong")
  80.     phase2 = true
  81.     else
  82.     mon.clear()
  83.     mon.setCursorPos(1,1)
  84.     mon.write("Countdown Timer")
  85.     mon.setTextColour(colours.red)
  86.     mon.setCursorPos(1,2)
  87.     mon.write("Aborted due to technical issues")
  88.     sleep(20)
  89.     os.reboot()
  90.   end
  91. until phase2 == true
  92. local phase3 = false
  93. repeat
  94.     if handshake == "1" then
  95.         mon.setCursorPos(1,1)
  96.         mon.write("Countdown Timer")
  97.         mon.setCursorPos(1,2)
  98.         mon.setTextColour(colours.green)
  99.         mon.write("Standby for launch")
  100.     phase3 = true
  101.     else
  102.     mon.clear()
  103.     mon.setCursorPos(1,1)
  104.     mon.write("Countdown Timer")
  105.     mon.setTextColour(colours.red)
  106.     mon.setCursorPos(1,2)
  107.     mon.write("Aborted due to technical issues")
  108.     sleep(20)
  109.     os.reboot()
  110.   end
  111. until phase3 == true
  112. local phase4 = false
  113. repeat
  114.     if startcount == "2" then
  115.         mon.clear()
  116.         timerlaunch()
  117.     phase4 = true
  118.         os.reboot()
  119.   else
  120.     mon.clear()
  121.     mon.setCursorPos(1,1)
  122.     mon.write("Countdown Timer")
  123.     mon.setTextColour(colours.red)
  124.     mon.setCursorPos(1,2)
  125.     mon.write("Aborted due to technical issues")
  126.     sleep(20)
  127.     os.reboot()
  128.   end
  129. until phase4 == true
  130. mon.clear()
  131. mon.setCursorPos(1,1)
  132. mon.write("Countdown Timer")
  133. mon.setTextColour(colours.green)
  134. mon.setCursorPos(1,2)
  135. mon.write("Completed")
  136. sleep(10)
  137. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement