XxLen_KagaminexX

Computercraft Reactor Monitor

Aug 12th, 2016 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. while true do
  2.   local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
  3.   local reactor2 = peripheral.wrap("BigReactors-Reactor_1")
  4.   local mon = peripheral.wrap("monitor_1")
  5.  
  6.   local length = 20
  7.    
  8.   mon.clear()
  9.  
  10.   mon.setCursorPos(1,1)
  11.   mon.setTextColor(colors.red)
  12.   mon.write("[Reactor 1]")
  13.  
  14.   local fuelAmt1 = reactor1.getFuelAmount()
  15.   local wastAmt1 = reactor1.getWasteAmount()
  16.  
  17.   local graphFuel1 = math.floor(fuelAmt1 * length / (fuelAmt1 + wastAmt1))
  18.   local percentFuel1 = math.floor(fuelAmt1 * 100 / (fuelAmt1 + wastAmt1))
  19.  
  20.   -- REACTOR 1
  21.  
  22.   mon.setCursorPos(1,2)
  23.   mon.setTextColor(colors.white)
  24.   mon.write("[")
  25.   mon.setTextColor(colors.lime)
  26.   for i = 1, graphFuel1, 1 do
  27.     mon.write("=")
  28.   end
  29.  
  30.   mon.setTextColor(colors.red)
  31.   for i = 1, (length - graphFuel1), 1 do
  32.     mon.write("=")
  33.   end
  34.  
  35.   mon.setTextColor(colors.white)
  36.   mon.write("] ")
  37.   mon.write(percentFuel1)
  38.   mon.write("%")
  39.  
  40.   -- REACTOR 2
  41.  
  42.   mon.setCursorPos(1,4)
  43.   mon.setTextColor(colors.red)
  44.   mon.write("[Reactor 2]")
  45.   mon.setCursorPos(1,5)
  46.   mon.setTextColor(colors.white)
  47.   mon.write("[")  
  48.  
  49.   local fuelAmt2 = reactor2.getFuelAmount()
  50.   local wastAmt2 = reactor2.getWasteAmount()
  51.  
  52.   local graphFuel2 = math.floor(fuelAmt2 * length / (fuelAmt2 + wastAmt2))
  53.   local percentFuel2 = math.floor(fuelAmt2 * 100 / (fuelAmt2 + wastAmt2))    
  54.  
  55.   mon.setTextColor(colors.lime)
  56.   for i = 1, graphFuel2, 1 do
  57.     mon.write("=")
  58.   end
  59.  
  60.   mon.setTextColor(colors.red)
  61.   for i = 1, (length - graphFuel2), 1 do
  62.     mon.write("=")
  63.   end
  64.  
  65.   mon.setTextColor(colors.white)
  66.   mon.write("] ")
  67.   mon.write(percentFuel2)
  68.   mon.write("%")
  69.  
  70.   -- ALERTS
  71.   if percentFuel1 < 50.0 then
  72.     mon.setCursorPos(1,8)
  73.     mon.setTextColor(colors.red)
  74.     mon.write("REACTOR 1 : fuel low!")
  75.   end
  76.  
  77.   if percentFuel2 < 50.0 then
  78.     mon.setCursorPos(1,9)
  79.     mon.setTextColor(colors.red)
  80.     mon.write("REACTOR 2 : fuel low!")
  81.   end
  82.  
  83.   sleep(10)
  84. end
Add Comment
Please, Sign In to add comment