VE Lua Documentation

Press F to search!

setAllowedIgnitionLevels

Definition


-- @/lua/vehicle/electrics.lua:712

local function setAllowedIgnitionLevels(newAllowedIgnitionLevels)
  if #newAllowedIgnitionLevels <= 0 then --make sure that we always have at least one allowed ignition level
    newAllowedIgnitionLevels = {0}
  --print warning
  end
  allowedIgnitionLevels = newAllowedIgnitionLevels
  allowedIgnitionLevelsLookup = {}
  for _, level in ipairs(newAllowedIgnitionLevels) do
    allowedIgnitionLevelsLookup[level] = true
  end

  ignitionLevelSanitization = {[0] = 0, [1] = 1, [2] = 2, [3] = 3}

  for i = 0, 3, 1 do --for every possible ignition level
    if not allowedIgnitionLevelsLookup[i] then --check if it's currently allowed
      for j = min(i + 1, 3), 3, 1 do --if not, first try to find anything _higher_ that is allowed
        if allowedIgnitionLevelsLookup[j] then
          ignitionLevelSanitization[i] = j
          break
        end
      end

      if not allowedIgnitionLevelsLookup[i] then --if we couldn't find anything higher allowed
        for j = max(i - 1, 0), 0, -1 do --try to find anything lower that is allowed...
          if allowedIgnitionLevelsLookup[j] then
            ignitionLevelSanitization[i] = j
            break
          end
        end
      end
    end
  end
end

Callers

@/lua/vehicle/electrics.lua

  setAllowedIgnitionLevels(jbeamData.allowedIgnitionLevels or {0, 1, 2, 3}) --read allowed ignition levels from jbeam or use all of them by default