GE Lua Documentation

Press F to search!

fillVehicleSpawnOptionDefaults

Definition


-- @/lua/ge/ge_utils.lua:1049

function fillVehicleSpawnOptionDefaults(modelName, opt)
  local model = core_vehicles.getModel(modelName)

  if not opt then
    opt = {}
  end
  -- log('I', 'vehicle', 'spawnFilldefaults: opt Before = '..dumps(opt))
  local config
  if type(opt.config) == 'string' then
    if string.endswith(opt.config, '.pc') then
      local configName = string.match(opt.config, "([^./]*).pc")
      if model.configs[configName] then
        config = model.configs[configName] or {}
        opt.config = configName
      else
        config = jsonReadFile(opt.config)
        if not config then
          local potentialPath = "vehicles/"..modelName.."/"..opt.config
          config = jsonReadFile(potentialPath)
          if config then
            opt.config = potentialPath
          else
            log("E", "", "Unable to recognize opt.config "..dumps(opt.config).." for vehicle "..dumps(modelName))
            config = {}
          end
        end
      end
    else
      config = model.configs[opt.config] or {}
    end
  else
    config = opt.config or {}
  end

  opt.model = opt.model or modelName

  local isColor4 = function(color)
    local components = stringToTable(color)
    local countNumericEntries = 0
    for _,v in ipairs(components) do
      if type(tonumber(v)) == 'number' then
        countNumericEntries = countNumericEntries + 1
      end
    end
    return countNumericEntries == #components
  end

  local color4StringToPaint = function(colorStr)
    local components = stringToTable(colorStr)
    local paint = createVehiclePaint({x = tonumber(components[1]), y = tonumber(components[2]), z = tonumber(components[3]), w = tonumber(components[4])})
    return paint
  end
  if opt.color and type(opt.color) == 'string' then
    if not opt.paintName and not isColor4(opt.color) then
      opt.paintName = opt.color
    else
      opt.paint = color4StringToPaint(opt.color)
    end
  end

  if opt.color2 and type(opt.color2) == 'string' then
    if not opt.paintName2 and not isColor4(opt.color2) then
      opt.paintName2 = opt.color2
    else
      opt.paint2 = color4StringToPaint(opt.color2)
    end
  end

  if opt.color3 and type(opt.color3) == 'string' then
    if not opt.paintName3 and not isColor4(opt.color3) then
      opt.paintName3 = opt.color3
    else
      opt.paint3 = color4StringToPaint(opt.color3)
    end
  end

  local modelPaints = model.model.paints
  if modelPaints then
    if not opt.paint then
      if not opt.paintName then
        opt.paintName = config.defaultPaintName1
      end

      if opt.paintName and type(opt.paintName) == 'string' then
        opt.paint = modelPaints[opt.paintName] or modelPaints[config.defaultPaintName1]
      end
    end

    if not opt.paint2 then
     if not opt.paintName2 then
        opt.paintName2 = config.defaultPaintName2
      end

      if opt.paintName2 and type(opt.paintName2) == 'string' then
        opt.paint2 = modelPaints[opt.paintName2] or modelPaints[config.defaultPaintName2]
      end
    end

    if not opt.paint3 then
     if not opt.paintName3 then
        opt.paintName3 = config.defaultPaintName3
      end

      if opt.paintName3 and type(opt.paintName3) == 'string' then
        opt.paint3 = modelPaints[opt.paintName3] or modelPaints[config.defaultPaintName3]
      end
    end
  end

  if not opt.paint and config then
    opt.paint = config.defaultPaint
  end

  if not opt.paint then
    opt.paint = model.model.defaultPaint
  end

  if not opt.config then
    opt.config = 'vehicles/' .. modelName .. '/' .. model.model.default_pc .. '.pc'
  elseif type(opt.config) == 'string' and not string.find(opt.config, '.pc') and FS:fileExists('/vehicles/' .. modelName .. '/' .. opt.config .. '.pc') then
    opt.config = 'vehicles/' .. modelName .. '/' .. opt.config .. '.pc'
  end
  -- log('I', 'vehicle', 'spawnFilldefaults: opt After = '..dumps(opt))
  return opt
end

Callers

@/lua/ge/ge_utils.lua
  --                      Look for comment "IMPORTANT Sanitizing the entire parts config data" in the function
  local options = fillVehicleSpawnOptionDefaults(model, opt)
  if options.paint then
@/lua/ge/extensions/editor/trafficManager.lua
      local spawnOptions = {config = vehSelector.config, paintName = vehSelector.paintName}
      spawnOptions = fillVehicleSpawnOptionDefaults(vehSelector.model, spawnOptions)
      spawnOptions.autoEnterVehicle = false
      local spawnOptions = {config = signSelector.config}
      spawnOptions = fillVehicleSpawnOptionDefaults(signSelector.model, spawnOptions)
      spawnOptions.autoEnterVehicle = false
@/lua/ge/extensions/scenario/quickRace.lua
  vehicle.rot = rot
  vehicle = fillVehicleSpawnOptionDefaults(vehicle.model, vehicle)
  local veh = core_vehicles.spawnNewVehicle(vehicle.model, vehicle)