Advertisement
Terminator_NL

Mekanism fission reactor script

Jan 18th, 2024 (edited)
1,265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. -- This function is required because the handle
  2. -- to the fusion reactor can return nil after creation
  3. function attempt(fun_name, if_true_do, if_false_do)
  4.     reactor = peripheral.find("fissionReactorLogicAdapter")
  5.     if reactor == nil or reactor[fun_name] == nil then
  6.         status, result = pcall(if_false_do)
  7.         return result
  8.     end
  9.     status, result = pcall(reactor[fun_name])
  10.     return if_true_do(result)
  11. end
  12.  
  13.  
  14. while not peripheral.find("fissionReactorLogicAdapter") do
  15.     sleep(1)
  16.     print("Waiting for reactor to come online...")
  17. end
  18.  
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. print("Script is active.")
  22.  
  23. -- Steam percentage
  24. target_level = 0.9
  25.  
  26. -- Coolant percentage
  27. min_coolant = 0.9
  28.  
  29. while true do
  30.     -- We assume the worst possible state
  31.     steam_level = attempt("getHeatedCoolantFilledPercentage", function(level) return level end, function() return 0 end)
  32.     coolant_level = attempt("getCoolantFilledPercentage", function(level) return level end, function() return 0 end)
  33.     damage_level = attempt("getDamagePercent", function(damage) return damage end, function() return 100 end)
  34.     waste_level = attempt("getWasteFilledPercentage",function(level) return level end, function() return 100 end)
  35.     redstone_allowed = rs.getInput("front")
  36.    
  37.     should_run = steam_level < target_level and waste_level <= 0 and redstone_allowed and coolant_level > min_coolant and damage_level <= 0
  38.  
  39.     current_state = attempt("getStatus", function(status) return status end, function() return true end)
  40.    
  41.     term.setCursorPos(1,2)
  42.     term.clearLine()
  43.     if current_state ~= should_run then
  44.         if should_run then
  45.             attempt("activate", function(v) return nil end, function() return nil end)
  46.             term.write("Switched reactor status: on")
  47.         else
  48.             attempt("scram", function(v) return nil end, function() return nil end)
  49.             term.write("Switched reactor status: off")
  50.         end
  51.     else
  52.         term.write("Reactor is currently " .. (current_state and "running" or "stopped"))
  53.     end
  54.     sleep(1)
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement