Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. screen = peripheral.wrap("monitor_55")
  2. screen.setTextScale(1.5)
  3. r = peripheral.wrap("back")
  4. r.chargeReactor()
  5.  
  6. local m = peripheral.wrap("monitor_54") --Monitor wrapping
  7. m.setTextScale(1)
  8. local bState = true --Variables for storing state of button
  9. local bState1 = true
  10. --Toggle
  11. function drawButton(state,pos,mo) --arguments : State: true/false, pos:{x,y}, mo:monitor index in m
  12. local mon = m --get monitor to be used
  13. local txt = "" --ON/OFF text to be used later, declared here so accessable in entire function
  14. mon.setCursorPos(pos[1],pos[2]) --setting cursorPos to pos argument
  15. if state then
  16. mon.setBackgroundColor(colors.green) --if state is true, set background to green and txt to ON
  17. txt = "ON"
  18. else
  19. mon.setBackgroundColor(colors.red) --if state is false, set background to red and txt to OFF
  20. txt = "OFF"
  21. end
  22. mon.write(string.rep(" ",5)) --draw " " with background colour set before
  23. mon.setCursorPos(pos[1]+1,pos[2]) --Go back to pos and move right by 1
  24. mon.write(txt) --write txt so it is centered
  25. end
  26.  
  27. while true do
  28. screen.clear()
  29. screen.setCursorPos(1,1)
  30. screen.setTextColor(colors.white)
  31. info = r.getReactorInfo()
  32.  
  33. -- Reactor Main Status
  34.  
  35. status = info["status"]
  36. screen.write("Draconic Reactor Status: ")
  37. if status == "online" then
  38. screen.setTextColor(colors.green)
  39. screen.write("Online")
  40. elseif (status == "stopping") then
  41. screen.setTextColor(colors.lime)
  42. screen.write("Stopping")
  43. elseif (status == "charging") then
  44. screen.setTextColor(colors.lightBlue)
  45. screen.write("Charging")
  46. elseif (status == "charged") then
  47. screen.setTextColor(colors.blue)
  48. screen.write("Charged")
  49. r.activateReactor()
  50. elseif (status == "offline") then
  51. screen.setTextColor(colors.red)
  52. screen.write("Offline")
  53.  
  54. end
  55.  
  56. -- Reactor Output
  57.  
  58. screen.setCursorPos(1,2)
  59. screen.setTextColor(colors.white)
  60. gen = info["generationRate"]
  61. screen.write("Gross Energy: ")
  62. screen.setTextColor(colors.green)
  63. screen.write(gen.. " RF/t")
  64.  
  65. -- Reactor Temperature
  66.  
  67. screen.setCursorPos(1,3)
  68. temp = info["temperature"]
  69. screen.setTextColor(colors.white)
  70. screen.write("Temperature: ")
  71. if (temp <= 6000) then
  72. screen.setTextColor(colors.blue)
  73. screen.write(temp)
  74. elseif (temp >= 7000) then
  75. screen.setTextColor(colors.red)
  76. screen.write(temp)
  77. else
  78. screen.setTextColor(colors.yellow)
  79. screen.write(temp.. " C.")
  80. end
  81.  
  82. -- Containment Field Strength
  83.  
  84. screen.setCursorPos(1,4)
  85. screen.setTextColor(colors.white)
  86. field = info["fieldStrength"]
  87. fieldi = info["fieldDrainRate"]
  88. screen.write("Field Strength: ")
  89. maxField = info["maxFieldStrength"]
  90. screen.setTextColor(colors.green)
  91. local fieldr = math.ceil(((field/maxField)*10000)-0.49999)/100
  92. screen.write(fieldr.. "%")
  93.  
  94. -- Energy Saturation
  95.  
  96. screen.setCursorPos(1,5)
  97. screen.setTextColor(colors.white)
  98. maxSat = info["maxEnergySaturation"]
  99. sat = info["energySaturation"]
  100. screen.write("Energy Saturation: ")
  101. screen.setTextColor(colors.green)
  102. local satr = math.ceil(((sat/maxSat)*10000)-0.49999)/100
  103. screen.write(satr.." % ")
  104.  
  105. -- Fuel Conversion rate/ Consumed
  106.  
  107. screen.setCursorPos(1,6)
  108. screen.setTextColor(colors.white)
  109. fuel = info["fuelConversion"]
  110. fuelRate = info["fuelConversionRate"]
  111. maxFuel = info["maxFuelConversion"]
  112. screen.write("Fuel Converted: ")
  113. screen.setTextColor(colors.green)
  114. local rate = math.ceil(((fuel/maxFuel)*10000)-0.4999)/100
  115. screen.write(rate.. " % ")
  116.  
  117. -- Net Output
  118. screen.setCursorPos(1,7)
  119. screen.setTextColor(colors.white)
  120. screen.write("Current Output: ")
  121. screen.setTextColor(colors.green)
  122. local out = (gen-fieldi)
  123. screen.write(out.. " Rf/t")
  124.  
  125. -- Reactor Emergency Code
  126. local d = (field/maxField)
  127. local e = (sat/maxSat)
  128.  
  129.  
  130. --if ((status == "charging" and d = 0) or status == "stopping") then redstone.setAnalogOutput("right", 9)
  131. local red = math.ceil(((1-d)*15))
  132. redstone.setAnalogOutput("right", red)
  133. sleep(0.1)
  134.  
  135. -- Redstone Input for Shutdown
  136. if redstone.getInput("left") == true then
  137. r.stopReactor()
  138. end
  139.  
  140. if (status == "online" and (d <= 0.10 or e <= 0.10)) then
  141. r.stopReactor()
  142. screen.clear()
  143. screen.setCursorPos(1,1)
  144. screen.setTextColor(colors.red)
  145. screen.setTextScale(2)
  146. screen.write("Commencing Emergency!")
  147. screen.setCursorPos(1,3)
  148. screen.write("Shutting down...")
  149. sleep(8)
  150. screen.setTextScale(1.5)
  151.  
  152. end
  153.  
  154. m.setBackgroundColor(colors.black) --Clearing monitor
  155. m.clear()
  156. drawButton(bState,{1,1},1) --Draw buttons using function above at different places, with state set to
  157. os.startTimer(0.25) --start 0.25 second timer, so script listens for monitor touch event for 0.25 seconds before
  158. while true do --updating buttons again
  159. evt = {os.pullEvent()} --Loop pulling events until "timer" or "monitor_touch" event is found
  160. if evt[1] == "timer" then
  161. break --If timer event found, break out of the while true loop on line 31
  162. elseif evt[1] == "monitor_touch" then
  163. local monT = evt[2] --if monitor touch event found, set variables to monitor name, x and y
  164. local x = evt[3]
  165. local y = evt[4]
  166. if monT == "monitor_54" then --if monitor found is on top face
  167. if x>=2 and x<=6 and y==3 then --if x and y found are within the coloured box of the button
  168. bState = not bState --set bState to oposite of what it current is (true to false, false to true)
  169. if bState then
  170. r.activateReactor()
  171. else
  172. r.stopReactor()
  173. end
  174. break --break out of loop to update buttons instantly
  175. elseif x>=2 and x<=6 and y==4 then --same thing for other button
  176. bState1 = not bState1
  177. break
  178.  
  179. end
  180. end --A million end's
  181. end
  182. end
  183.  
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement