Advertisement
mycosis

Computercraft - Total RF

May 30th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. rednetSide = "bottom"
  2. monitorSide = "back"
  3. reactorArray = {"BigReactors-Reactor_0","BigReactors-Reactor_1","BigReactors-Reactor_2","BigReactors-Reactor_3"}
  4. turbineArray = {"BigReactors-Turbine_0","BigReactors-Turbine_1","BigReactors-Turbine_2","BigReactors-Turbine_3"}
  5. reactorWrap = {}
  6. turbineWrap = {}
  7.  
  8. -- Rednet
  9. rednet.close(rednetSide)
  10. rednet.open(rednetSide)
  11.  
  12. -- Wrap peripherals
  13. mon = peripheral.wrap(monitorSide)
  14. for i, turbine in ipairs(turbineArray) do -- Wrap turbine
  15.   turbineWrap[i] = peripheral.wrap(turbine)
  16. end
  17. for r, reactor in ipairs(reactorArray) do -- Wrap reactor
  18.   reactorWrap[r] = peripheral.wrap(reactor)
  19. end
  20.  
  21. function setMonColor(color)
  22.  mon.setTextColor(color)
  23. end
  24.  
  25. -- Console clear
  26. term.clear()
  27. term.setCursorPos(1,1)
  28. term.write("Running total RF monitor.")
  29.  
  30. -- While loop
  31. while true do
  32.     mon.setCursorPos(1,1)
  33.     mon.setTextScale(4)
  34.     mon.setTextColor(colors.gray)
  35.     mon.clear()
  36.  
  37.     rfTick = 0 -- Check for turbine activity
  38.     turbineActive = false
  39.     for key, wrapped in ipairs(turbineWrap) do
  40.       rfTick = rfTick + wrapped.getEnergyProducedLastTick()
  41.       if(turbineActive == false and wrapped.getActive() == true) then
  42.         turbineActive = true
  43.       end
  44.     end
  45.  
  46.     reactorActive = false -- Check for reactor activity
  47.     for key, wrapped in ipairs(reactorWrap) do
  48.       if(reactorActive == false and wrapped.getActive() == true) then
  49.         reactorActive  = true
  50.       end
  51.     end
  52.    
  53.     if(reactorActive == true and rfTick < 20000) then -- Backup generators to get AE going
  54.         rednet.send(21,"redstoneOn")
  55.         rednet.send(22,"redstoneOn")
  56.         setMonColor(colors.orange)
  57.     else
  58.         rednet.send(21,"redstoneOff")
  59.         rednet.send(22,"redstoneOff")
  60.     end
  61.    
  62.     if(reactorActive == true and turbineActive == true and rfTick > 0) then
  63.         setMonColor(colors.green)
  64.     end
  65.    
  66.     mon.write(string.format("%07d", rfTick))
  67.     mon.write(" RF")
  68.     sleep(60)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement