Advertisement
JoshBoshGames

Reactor Control Software

Jan 4th, 2021 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- Reactor Control Software
  2. -- V 1.0.0
  3.  
  4. --First time configuration
  5. if not fs.exists("ReactorControl.cfg") then
  6.     print("Configuration file not found, creating new configuration file")
  7.     Writes={}
  8.    
  9.     --Selecting Reactor Peripheral
  10.     print("Peripherals Found:")
  11.     AllPeripherals = peripheral.getNames()
  12.     for i in ipairs(AllPeripherals) do
  13.         print("["..i.."] "..AllPeripherals[i])
  14.     end
  15.     print("Please enter the the position of the reactor (BigReactors-Reactor_n)")
  16.     ReactorName = AllPeripherals[tonumber(read())]
  17.     print(ReactorName)
  18.    
  19.     --Writing To Config
  20.     config = fs.open("ReactorControl.cfg","w")
  21.     config.writeLine(ReactorName)
  22.    
  23.     config.close()
  24.     print("If you ever need to change these settings, delete ReactorControl.cfg")
  25. end
  26.  
  27. --Reading Config
  28. config=fs.open("ReactorControl.cfg","r")
  29. ReactorName = config.readLine()
  30.  
  31. config.close()
  32.  
  33. --Wrapping Reactor
  34. print("Reactor Name: "..ReactorName)
  35. reactor = peripheral.wrap(ReactorName)
  36.  
  37. --Monitoring Loop
  38. while true do
  39.     EnergyStats=reactor.getEnergyStats()
  40.    
  41.     FillPercentage= (EnergyStats.energyStored / EnergyStats.energyCapacity)*100
  42.    
  43.     reactor.setAllControlRodLevels(math.min(FillPercentage+10,100))
  44.    
  45.     term.clear()
  46.     print("Energy Stored: "..EnergyStats.energyStored)
  47.     print("Energy Capacity: "..EnergyStats.energyCapacity)
  48.     print("Current Generation: "..EnergyStats.energyProducedLastTick.."RF/t")
  49.     print("Control Rod Level: "..math.min(FillPercentage+10,100))
  50.     os.sleep(0.1)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement