GE Lua Documentation

Press F to search!

setVehicleObject

Definition


-- @/lua/ge/spawn.lua:538

local function setVehicleObject(veh, options)
  --dump{'setVehicleObject: ', veh, options}
  if not veh then
    log('E', logTag, 'setVehicleObject Failed, no vehicle provided.')
    return
  end

  veh.JBeam = options.model

  local pc = ''
  if type(options.config) == 'string' then
    pc = options.config
  elseif type(options.config) == 'table' then
    pc = serialize(options.config)
  end
  veh.partConfig = pc

  local paint = options.paint
  if paint then
    veh.color = ColorF(paint.baseColor[1], paint.baseColor[2], paint.baseColor[3], paint.baseColor[4]):asLinear4F()
  end

  local paint2 = options.paint2
  if paint2 then
    veh.colorPalette0 = ColorF(paint2.baseColor[1], paint2.baseColor[2], paint2.baseColor[3], paint2.baseColor[4]):asLinear4F()
  end

  local paint3 = options.paint3
  if paint3 then
    veh.colorPalette1 = ColorF(paint3.baseColor[1], paint3.baseColor[2], paint3.baseColor[3], paint3.baseColor[4]):asLinear4F()
  end
  local paints = {paint, paint2, paint3}
  veh:setMetallicPaintData(paints)
  veh.paints = serialize(paints)

  local pos = options.pos
  local rot = options.rot

  -- TODO the rotation by 180 degrees needs to happen before the other rotation. The order might still be wrong in some places
  rot = quat(0,0,1,0) * rot -- rotate 180 degrees
  local activeVehicle = true
  if not veh.spawnObjectWithPosRot then
    log('E', '', 'Unable to spawn vehicle, wrong Scene object returned?')
    return
  end
  veh:spawnObjectWithPosRot(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w, activeVehicle)
  if options.centeredPosition then
    centerVehicle(veh, pos, rot)
  end
  local missionGroup = scenetree.MissionGroup
  if not missionGroup then
    log('E', logTag, 'MissionGroup does not exist')
    return
  end
  missionGroup:addObject(veh.obj)

  -- do not save vehicles that are spawned via this function with the level
  veh.canSave = false

  -- add it to the group 'SpawnedVehicles'
  local vehGroup = scenetree.SpawnedVehicles
  if not vehGroup then
    vehGroup = createObject('SimGroup')
    if vehGroup then
      vehGroup:registerObject('SpawnedVehicles')
      vehGroup.canSave = false
      missionGroup:addObject(vehGroup.obj)
    end
  else
    vehGroup:addObject(veh.obj)
  end
  if options.safeSpawn == true or options.safeSpawn == nil then
    setSafePosition(veh, nil, nil, nil, true)
  end
end

Callers

@/lua/ge/extensions/scenario/scenarios.lua
      -- We perform a 180 rotation (quat(0,0,1,0) * rot) here to undo the 180 rotation that will happen in
      -- spawn.lua setVehicleObject() by default
      for vehicleName, vehicleData in pairs(scenario.multiseatDeletedVehicles or {}) do
@/lua/ge/extensions/core/vehicles.lua
  end
  spawn.setVehicleObject(otherVeh, options)
  finalizeSpawn(options, otherVeh)
@/lua/ge/extensions/editor/gen/exp_meshexplorer.lua
                    end
                    spawn.setVehicleObject(scenetree.findObjectById(id), options)
                end
@/lua/ge/spawn.lua
  options.cling = options.cling ~= false
  setVehicleObject(veh, options)
  return veh