Advertisement
Umaler

WarpDrive EnanReactor settings setter

Feb 24th, 2025 (edited)
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | Gaming | 0 0
  1. component   = require("component")
  2. string      = require("string")
  3. table       = require("table")
  4.  
  5. -- Utilities
  6.  
  7. function toBoolean(str)
  8.     if type(str) == 'boolean' then
  9.         return str
  10.     elseif str ~= nil then
  11.         return string.lower(str)
  12.     else
  13.         return false
  14.     end
  15. end
  16.  
  17. function removeValues(tab)
  18.     result={}
  19.     for k, _ in pairs(tab) do
  20.         table.insert(result, k)
  21.     end
  22.     return result
  23. end
  24.  
  25. function applyToAll(tab, func)
  26.     for _, v in ipairs(tab) do
  27.         func(v)
  28.     end
  29. end
  30.  
  31. -- Main code
  32.  
  33. function applyConfig(config)
  34.     function getWithDefault(key, default)
  35.         if config[key] ~= nil then
  36.             return config[key]
  37.         else
  38.             return default
  39.         end
  40.     end
  41.  
  42.     function addrsToProxy(t)
  43.         result = {}
  44.         for _, v in ipairs(t) do
  45.             table.insert(result, component.proxy(v))
  46.         end
  47.         return result
  48.     end
  49.  
  50.     -- Set default values if they aren't presented
  51.     config.orate    = getWithDefault('orate',  50000000)
  52.     config.omode    = getWithDefault('omode', 'above')
  53.     config.elevel   = getWithDefault('elevel', 60000)
  54.     config.stab     = getWithDefault('stab',   100)
  55.     config.on       = toBoolean(getWithDefault('on',     true))
  56.  
  57.     cores = addrsToProxy(removeValues(component.list('warpdriveEnanReactorCore')))
  58.     function applyToCores(func)
  59.         applyToAll(cores, func)
  60.     end
  61.  
  62.     -- Set the rate/threshold
  63.     applyToCores(
  64.         function(core)
  65.             if config.omode == 'rate' then
  66.                 core.releaseRate(config.orate)
  67.             else
  68.                 core.releaseAbove(config.orate)
  69.             end
  70.         end
  71.     )
  72.  
  73.     applyToCores(
  74.         function(core)
  75.             core.stabilizerEnergy(config.elevel)
  76.         end
  77.     )
  78.  
  79.     applyToCores(
  80.         function(core)
  81.             core.instabilityTarget(100 - config.stab)
  82.         end
  83.     )
  84.  
  85.     applyToCores(
  86.         function(core)
  87.             core.enable(config.on)
  88.         end
  89.     )
  90.  
  91. end
  92.  
  93. settings = {
  94.     orate  = 50000000,  --reactor output rate
  95.     omode  = 'above', --reactor output mode
  96.     elevel = 10000,  --laser energy level
  97.     stab   = 2,      --reactor target stability
  98.     on     = true    --on/off
  99. }
  100.  
  101. applyConfig(settings)
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement