nissa1234to

Reactor 2

Oct 26th, 2025 (edited)
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. local reactorName = "BiggerReactors_Reactor_1"
  2. local maxTemp = 2200
  3. local minTemp = 1800
  4.  
  5. local turbineName = "BiggerReactors_Turbine_0"
  6. local targetRPM = 1800
  7. local stepSize = 10
  8.  
  9. local checkInterval = 0.1
  10.  
  11. local mon = peripheral.wrap("monitor_2")
  12. term.redirect(mon)
  13.  
  14. local reactor = peripheral.wrap(reactorName)
  15. if not reactor then
  16.   error("Reactor not found: " .. reactorName)
  17. end
  18.  
  19. local turbine = peripheral.wrap(turbineName)
  20. if not turbine then
  21.   error("Turbine not found: " .. turbineName)
  22. end
  23.  
  24. while true do
  25.   local rodPercent = 100 * math.max(reactor.getCasingTemperature() - minTemp, 0) / (maxTemp - minTemp)
  26.   reactor.setAllControlRodLevels(rodPercent)
  27.  
  28.   local rpm = turbine.rotor().RPM()
  29.  
  30.   if rpm > targetRPM then
  31.     turbine.fluidTank().setNominalFlowRate(turbine.fluidTank().nominalFlowRate() - stepSize)
  32.   else
  33.     turbine.fluidTank().setNominalFlowRate(turbine.fluidTank().nominalFlowRate() + stepSize)
  34.   end  
  35.  
  36.   if turbine.battery().stored() / turbine.battery().capacity() < 0.2 then
  37.     if not reactor.active() then
  38.       reactor.setActive(true)
  39.       print("Reactor ON")
  40.     end
  41.   elseif turbine.battery().stored() / turbine.battery().capacity() > 0.8 then
  42.     if reactor.active() then
  43.       reactor.setActive(false)
  44.       print("Reactor OFF")
  45.     end
  46.   end
  47.  
  48.   term.clear()
  49.   term.setCursorPos(1,1)
  50.  
  51.   print("Temperature: " .. math.floor(reactor.fuelTemperature()))
  52.   print("Rods: " .. math.floor(reactor.getControlRod(0).level()))
  53.   sleep(checkInterval)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment