Advertisement
RlonRyan

RR|Reactor

Jul 24th, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local react = peripheral.find("BigReactors-Reactor")
  2.  
  3. function getReactor()
  4.   react = peripheral.find("BigReactors-Reactor")
  5. end
  6.  
  7. function output(text, color)
  8.   color = color or colors.white
  9.   term.setTextColor(color)
  10.   write(text)
  11. end
  12.  
  13. function outputBool(b)
  14.   if (b) then
  15.     output("true", colors.green)
  16.   else
  17.     output("false", colors.red)
  18.   end
  19. end
  20.  
  21. function outputPower(p)
  22.   f = p / 100000
  23.   if (f >= 50) then
  24.     output(tostring(p) .. "rf", colors.green)
  25.   elseif (f >= 25) then
  26.     output(tostring(p) .. "rf", colors.yellow)
  27.   else
  28.     output(tostring(p) .. "rf", colors.red)
  29.   end
  30. end
  31.  
  32. function outputFill(f)
  33.   f = f * 100
  34.   if (f >= 50) then
  35.     output(tostring(f) .. "%", colors.green)
  36.   elseif (f >= 25) then
  37.     output(tostring(f) .. "%", colors.yellow)
  38.   else
  39.     output(tostring(f) .. "%", colors.red)
  40.   end
  41. end
  42.  
  43. function printInfo()
  44.   term.clear()
  45.   term.setCursorPos(1, 1)
  46.   output("Reactor Controller")
  47.   output("\n")
  48.   output("==================")
  49.   output("\n")
  50.  
  51.   output("Connected: ")
  52.   outputBool(react.getConnected())
  53.   output("\n")
  54.  
  55.   output("Active: ")
  56.   outputBool(react.getActive())
  57.   output("\n")
  58.  
  59.   output("Fuel: ")
  60.   outputFill(react.getFuelAmount() / react.getFuelAmountMax())
  61.   output("\n")
  62.  
  63.   output("Power: ")
  64.   outputPower(react.getEnergyStored())
  65.   output("\n")
  66.  
  67.   output("Fill: ")
  68.   outputFill(react.getEnergyStored() / 10000000)
  69.   output("\n")
  70. end
  71.  
  72. function power()
  73.   if (react.getActive() and (react.getEnergyStored() / 100000 > 90)) then
  74.     react.setActive(false)
  75.   elseif (react.getEnergyStored() / 100000 < 25) then
  76.     react.setActive(true)
  77.   end
  78. end
  79.  
  80. function run()
  81.   getReactor()
  82.   while react do
  83.     power()
  84.     printInfo()
  85.     sleep(0.5)
  86.   end
  87.   term.clear()
  88.   term.setCursorPos(1,1)
  89.   print("Reactor Connection Lost!")
  90. end
  91.  
  92. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement