setVehicleSpawnData
Definition
-- @/lua/ge/extensions/core/multiSpawn.lua:684
local function setVehicleSpawnData(group, amount) -- parses and sets the vehicle data from the spawn group
if not group or not group[1] then
log('W', logTag, 'Vehicle group is empty!')
return
end
local spawnData = {}
local groupCopy = deepcopy(group)
groupCopy = fitGroup(groupCopy, amount)
for i, options in ipairs(groupCopy) do
if options[1] then -- old array format
options = {model = options[1], config = options[2], color1 = options[3], color2 = options[4], color3 = options[5]}
end
local modelData = core_vehicles.getModel(options.model)
if modelData and next(modelData) then
if not options.config or options.config == 'base' then
options.config = modelData.model.default_pc
end
local paints = modelData.model.paints or {}
local oldColorKeys = {'color1', 'color2', 'color3'}
local paintKeys = {'paint', 'paint2', 'paint3'}
local paintNameKeys = {'paintName', 'paintName2', 'paintName3'}
for j, color in ipairs(oldColorKeys) do -- convert old colors to paints
if options[color] then
local values = stringToTable(options[color])
if values[4] then
options[paintKeys[j]] = createVehiclePaint({x = values[1], y = values[2], z = values[3], w = values[4]})
end
end
options[color] = nil
end
if options.randomPaints or options.paintName == '(Random)' or options.paintName2 == '(Random)' or options.paintName3 == '(Random)' then -- some backwards compatibility
local randomPaints = core_vehiclePaints.getRandomPaints(options.model, options.config)
if randomPaints and randomPaints.paintName1 then
log('I', logTag, string.format('Applying random paints for this vehicle: %s', options.model or ''))
options.paintName = randomPaints.paintName1
options.paintName2 = randomPaints.paintName2
options.paintName3 = randomPaints.paintName3
else
log('W', logTag, string.format('Failed to get random paints for vehicle: %s (config: %s), using default paints', options.model or '', options.config or ''))
options.paintName = modelData.model.defaultPaintName1 or 'White'
options.paintName2 = modelData.model.defaultPaintName2 or modelData.model.defaultPaintName1 or 'White'
options.paintName3 = modelData.model.defaultPaintName3 or modelData.model.defaultPaintName1 or 'White'
end
end
for j, pName in ipairs(paintNameKeys) do
local pKey = paintKeys[j]
if options[pName] and not options[pKey] then
options[pKey] = paints[options[pName]] -- gets actual paint data from the paint name
end
end
spawnData[i] = options
else
log('E', logTag, string.format('Vehicle model not found: %s', options.model or ''))
spawnData[i] = deepcopy(defaultOptions)
end
end
return spawnData
end
Callers
@/lua/ge/extensions/core/multiSpawn.lua
log('I', logTag, string.format('Spawning vehicle group with %d vehicles: %s', amount, options.name or ''))
return spawnProcessedGroup(setVehicleSpawnData(group, amount), options) -- returns unique group id
end