Advertisement
Silasko

Reactor

May 7th, 2022 (edited)
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. function start()
  2.     reactor = peripheral.wrap("back")
  3.     maxim = reactor.getEnergyCapacity()
  4.     while true do
  5.         local current = reactor.getEnergyStored()
  6.         if (current <= (maxim*0.2)) then
  7.             refill()
  8.         end
  9.         sleep(5)  
  10.     end
  11.  
  12. end
  13.  
  14. function refill()
  15.     while true do
  16.         local current = reactor.getEnergyStored()
  17.         reactor.setActive(true)
  18.         print("Activating Reactor...")
  19.         if (current <= (maxim*0.99)) then
  20.            sleep(5)
  21.         else reactor.setActive(false)
  22.             print("Refill complete, deactivating reactor...")
  23.             start()
  24.         end  
  25.     end
  26. end
  27.    
  28.  
  29. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement