Advertisement
Alakazard12

reactor

Dec 24th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3.  
  4. local lower_thres = 1000000
  5. local upper_thres = 8000000
  6.  
  7. local function check()
  8. pcall(function()
  9. for address, componentType in component.list("br_reactor", true) do
  10. local reactor = component.proxy(address)
  11.  
  12. local max = reactor.getFuelAmountMax()
  13. local energy = reactor.getEnergyStored()
  14.  
  15. if energy < lower_thres then
  16. reactor.setActive(true)
  17. elseif energy > upper_thres then
  18. reactor.setActive(false)
  19. end
  20. end
  21. end)
  22. end
  23. local timer
  24.  
  25. function start()
  26. if timer then
  27. event.cancel(timer)
  28. end
  29. timer = event.timer(5, check, math.huge)
  30. end
  31.  
  32.  
  33.  
  34.  
  35. function stop()
  36. if timer then
  37. event.cancel(timer)
  38. timer = nil
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement