Advertisement
jakendrick3

Reactor Control V1

Feb 11th, 2016
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2. monX, monY = mon.getSize()
  3.  
  4. reactor = peripheral.find("BigReactors-Reactor")
  5.  
  6. running = true
  7. sumSelect = true
  8. auto = false
  9.  
  10. while running == true do
  11.  
  12. reactorInfo = {
  13.   active = reactor.getActive(),
  14.   power = reactor.getEnergyStored(),
  15.   ftemp = reactor.getFuelTemperature(),
  16.   ctemp = reactor.getCasingTemperature(),
  17.   fuel = reactor.getFuelAmount(),
  18.   waste = reactor.getWasteAmount(),
  19.   fuelMax = reactor.getFuelAmountMax(),
  20.   powerPerTick = reactor.getEnergyProducedLastTick(),
  21.   reactivity = reactor.getFuelReactivity()
  22. }
  23.  
  24. mon.setBackgroundColor(colors.black)
  25. mon.setTextColor(colors.white)
  26. mon.setCursorPos(1, 1)
  27. mon.clear()
  28.  
  29. function flip()
  30.   if mon.getBackgroundColor() == colors.blue then
  31.     mon.setBackgroundColor(colors.green)
  32.   elseif mon.getBackgroundColor() == colors.green then
  33.     mon.setBackgroundColor(colors.blue)
  34.   else
  35.     mon.setBackgroundColor(colors.blue)
  36.   end
  37. end
  38.  
  39. function newLine()
  40.   tempX, tempY = mon.getCursorPos()
  41.   mon.setCursorPos(1, tempY + 1)
  42. end
  43.  
  44. if sumSelect == true then
  45.   per = reactorInfo.power / 10000000
  46. elseif sumSelect == false then
  47.   per = reactorInfo.fuel / reactorInfo.fuelMax
  48. end
  49.  
  50. if auto then
  51.   per2 = reactorInfo.power / 10000000
  52.   if per2 <= 0.2 then
  53.     reactor.setActive(true)
  54.   elseif per2 >= 0.5 then
  55.     reactor.setActive(false)
  56.   end
  57. end
  58.  
  59. toTen = 1
  60.  
  61. if per < 0.15 then
  62.   toTen = 1
  63. elseif per < 0.25 and per >= 0.15 then
  64.   toTen = 2
  65. elseif per < 0.35 and per >= 0.25 then
  66.   toTen = 3
  67. elseif per < 0.45 and per >= 0.35 then
  68.   toTen = 4
  69. elseif per < 0.55 and per >= 0.45 then
  70.   toTen = 5
  71. elseif per < 0.65 and per >= 0.55 then
  72.   toTen = 6
  73. elseif per < 0.75 and per >= 0.65 then
  74.   toTen = 7
  75. elseif per < 0.85 and per >= 0.75 then
  76.   toTen = 8
  77. elseif per < 0.95 and per >= 0.85 then
  78.   toTen = 9
  79. elseif per >= 0.95 then
  80.   toTen = 10
  81. end
  82.  
  83. mon.setBackgroundColor(colors.black)
  84. mon.setCursorPos(1, monY)
  85. mon.write("Summary: ")
  86.  
  87. if sumSelect == true then  
  88.   mon.setBackgroundColor(colors.green)
  89.   mon.write(string.rep(" ", toTen))
  90.   mon.setBackgroundColor(colors.red)
  91.   mon.write(string.rep(" ", 10 - toTen))
  92. elseif sumSelect == false then
  93.   mon.setBackgroundColor(colors.yellow)
  94.   mon.write(string.rep(" ", toTen))
  95.   mon.setBackgroundColor(colors.gray)
  96.   mon.write(string.rep(" ", 10 - toTen))
  97. end
  98. mon.setCursorPos(monX - 3, monY)
  99. mon.setBackgroundColor(colors.green)
  100. mon.write("()")
  101.  
  102. mon.setCursorPos(1, 1)
  103. flip()
  104.  
  105. mon.write("Reactor Active: "..tostring(reactorInfo.active))
  106. flip()
  107. newLine()
  108. mon.write("Power Level: "..reactorInfo.power.."/1000000")
  109. flip()
  110. newLine()
  111. mon.write("Fuel Level: "..reactorInfo.fuel.."/"..reactorInfo.fuelMax)
  112. flip()
  113. newLine()
  114. mon.write("Waste Level: "..reactorInfo.waste)
  115. flip()
  116. newLine()
  117. mon.write("Casing Temperature: "..reactorInfo.ctemp)
  118. flip()
  119. newLine()
  120. mon.write("Fuel Temperature: "..reactorInfo.ftemp)
  121.  
  122. text = "Toggle Power"
  123. newX, newY = 1
  124. newX = math.ceil((monX - string.len(text)) / 2)
  125. newY = math.ceil((monY - 1) / 2 + 3)
  126. if reactorInfo.active and not auto then
  127.   mon.setBackgroundColor(colors.green)
  128. elseif not reactorInfo.active then
  129.   mon.setBackgroundColor(colors.red)
  130. elseif reactorInfo.active and auto then
  131.   mon.setBackgroundColor(colors.blue)
  132. end
  133.  
  134. mon.setCursorPos(newX, newY)
  135. mon.write(text)
  136.  
  137. tempXX, tempYY = mon.getCursorPos()
  138. mon.setCursorPos(tempXX + 2, tempYY)
  139. if auto then
  140.   mon.setBackgroundColor(colors.blue)
  141. else
  142.   mon.setBackgroundColor(colors.gray)
  143. end
  144. mon.write("Auto")
  145.  
  146. mon.setBackgroundColor(colors.black)
  147.  
  148. timer = os.startTimer(3)
  149. event = {os.pullEvent()}
  150.  
  151. if event[1] == "monitor_touch" then
  152.   if (event[3] == monX - 3 or event[3] == monX - 2) and event[4] == monY then
  153.     sumSelect = not sumSelect
  154.   elseif event[3] >= newX and event[3] < newX + #text and event[4] == newY then
  155.     reactor.setActive(not reactorInfo.active)
  156.   elseif event[3] >= tempXX + 2 and event[3] < tempXX + 6 and event[4] == newY then
  157.     auto = not auto
  158.   end
  159. end
  160. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement