Advertisement
mycosis

Computercraft - Turbine info

May 28th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. rednet.close("bottom")
  2. rednet.open("bottom")
  3. mon = peripheral.wrap("top")
  4. monHeader = " Turbine No. ##HEADERNUM##"
  5. rednetTurbine = "BigReactors-Turbine_##MACHINENUM##"
  6.  
  7. -- Wrap turbine
  8. turbine = peripheral.wrap(rednetTurbine)
  9.  
  10. -- Write monitor text colors
  11. function writeRed(text)
  12.     mon.setTextColor(colors.red)
  13.     mon.write(text)
  14.     mon.setTextColor(colors.white)
  15. end
  16. function writeGreen(text)
  17.     mon.setTextColor(colors.green)
  18.     mon.write(text)
  19.     mon.setTextColor(colors.white)
  20. end
  21. function writeOrange(text)
  22.     mon.setTextColor(colors.orange)
  23.     mon.write(text)
  24.     mon.setTextColor(colors.white)
  25. end
  26.  
  27. function resetScreen()
  28.     mon.setBackgroundColor(colors.black)
  29.     mon.setTextColor(colors.white)
  30.     mon.clear()
  31.     mon.setCursorPos(1,2)
  32.     mon.write(monHeader)
  33.     mon.setCursorPos(2,4)
  34. end
  35.  
  36. function nextWriteLine()
  37.     local cX,cY = mon.getCursorPos()
  38.     mon.setCursorPos(2,cY+1)
  39. end
  40.  
  41. function numberRound(number)
  42.     local High = math.ceil(number) - number
  43.     if High >= .5 then
  44.         return math.ceil(number)
  45.     else
  46.         return math.floor(number)
  47.     end
  48. end
  49.  
  50. term.setCursorPos(1,1)
  51. term.clear()
  52. term.write("Running monitor")
  53.  
  54. while true do
  55.     resetScreen()
  56.    
  57.     -- Active
  58.     mon.write("Active: ")
  59.     if(turbine.getActive() == true) then
  60.         writeGreen("true")
  61.     else
  62.         writeOrange("false")
  63.     end
  64.     nextWriteLine()
  65.    
  66.     -- Induction coils
  67.     mon.write("Ind. coils: ")
  68.     if(turbine.getInductorEngaged() == true) then
  69.         writeGreen("true")
  70.     else
  71.         writeOrange("false")
  72.     end
  73.     nextWriteLine()
  74.    
  75.     -- Rotor speed
  76.     mon.write("Rotor speed: ")
  77.     local rotorSpeed = turbine.getRotorSpeed()
  78.     if(rotorSpeed > 1810) then
  79.         writeRed(numberRound(rotorSpeed))
  80.     elseif(rotorSpeed < 1780 and rotorSpeed > 0) then
  81.         writeOrange(numberRound(rotorSpeed))
  82.     elseif(rotorSpeed >= 1780 and rotorSpeed <= 1810) then
  83.         writeGreen(numberRound(rotorSpeed))
  84.     else
  85.         mon.write(numberRound(rotorSpeed))
  86.     end
  87.     mon.write(" RPM")
  88.     nextWriteLine()
  89.    
  90.     -- Energy/tick
  91.     mon.write("Energy/tick: ")
  92.     mon.write(numberRound(turbine.getEnergyProducedLastTick()))
  93.     mon.write(" RF")
  94.     nextWriteLine()
  95.    
  96.     -- Energy stored
  97.     mon.write("Energy stored: ")
  98.     mon.write(numberRound(turbine.getEnergyStored()))
  99.     mon.write(" RF")
  100.     nextWriteLine()
  101.    
  102.     -- Fluid rate
  103.     mon.write("Fluid flow: ")
  104.     mon.write(numberRound(turbine.getFluidFlowRate()))
  105.     mon.write(" mb")
  106.    
  107.     sleep(5)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement