Advertisement
TitanChase

Reactor.lua

Nov 7th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. shell.run("clear")
  2. local reactor = peripheral.wrap("BigReactors-Reactor_0")
  3. local monitor = peripheral.wrap("monitor_0")
  4. local factor = 0.5
  5. term.setTextColor(colors.blue)
  6. textutils.slowPrint("====Reactor Checking System====")
  7. textutils.slowPrint("========By DiscworldZA=========")
  8.  
  9. if reactor == nil then
  10.     textutils.slowPrint("No Reactor Found")
  11. end
  12.  
  13. if reactor.getConnected() then
  14.     term.setTextColor(colors.green)
  15.     textutils.slowPrint("Reactor Connected")
  16. end
  17.  
  18. local energyFactor
  19.  
  20. function checkActive()
  21.     energyFactor = reactor.getEnergyStored() / 10000000
  22.     term.setTextColor(colors.red)
  23.     textutils.slowPrint("Checking Status...")
  24.     sleep(1)
  25.     term.setTextColor(colors.white)
  26.     textutils.slowWrite("Reactor Status: ")
  27.     if reactor.getActive() then
  28.         term.setTextColor(colors.green)
  29.         textutils.slowPrint("On")
  30.     else
  31.         term.setTextColor(colors.red)
  32.         textutils.slowPrint("Off")
  33.     end
  34.     term.setTextColor(colors.white)
  35.     textutils.slowWrite("Energy Storage: ")
  36.     term.setTextColor(colors.blue)
  37.     textutils.slowPrint(reactor.getEnergyStored() .. " RF")
  38.    
  39.  
  40.     if  energyFactor < factor then
  41.         if not reactor.getActive() then
  42.             reactor.setActive(true)
  43.             term.setTextColor(colors.green)
  44.             textutils.slowPrint("Activating Reactor")
  45.         end
  46.     else
  47.         if reactor.getActive() then
  48.             reactor.setActive(false)
  49.             term.setTextColor(colors.red)
  50.         end
  51.     end
  52.     sleep(3)
  53. end
  54.  
  55. function printMonitor()
  56.     while true do
  57.         oldterm = term.redirect(monitor)
  58.         term.clear()
  59.         term.setCursorPos(1, 1)
  60.         term.setTextColor(colors.blue)
  61.         print("====Reactor Control====")
  62.         print("=====By DiscworldZA====")
  63.         write("Reactor:     ")
  64.         if reactor.getActive() then
  65.             term.setTextColor(colors.green)
  66.             print("On")
  67.         else
  68.             term.setTextColor(colors.red)
  69.             print("Off")
  70.         end
  71.  
  72.         term.setTextColor(colors.blue)
  73.         write("Power Level: ")
  74.         term.setTextColor(colors.red)
  75.         write(reactor.getEnergyStored())
  76.         term.setTextColor(colors.blue)
  77.         print(" RF")
  78.         term.redirect(oldterm)
  79.         sleep(1)
  80.     end
  81. end
  82.  
  83. function quitProgram()
  84.   local event, name = os.pullEvent("quit")
  85.   if name == "reactor" then
  86.     quit = true
  87.   end
  88. end
  89.  
  90. while true do
  91.   parallel.waitForAny(quitProgram, checkActive, printMonitor)
  92.  
  93.   if quit then
  94.     print("Quitting....")
  95.     break
  96.   end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement