Hello.
Yesterday i installed a police vehicle pack, and put it into my server. I checked it out, and there is 4 liverys for the vehicle. But when you spawn the vehicle there is no livery, so you manually have to put 1 of the 4 on.
The thing i want to do, is somehow to get on 1 of the 4 liverys when i spawn the car, without deleting the liverys.
I have search on google, and looked through everything but i didn’t find anything that worked.
Just use the SetVehicleLivery() native. If you want to be a random between the first and the fourth one, do a math.random(1, 4) via Lua and have it set the vehicle’s livery to that number. Should be something like this:
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
local rnd = math.random(1, 4)
-- Car spawn stuff here (it needs to exist before executing the livery command)
SetVehicleLivery(veh, rnd)
You can expand this further without much effort to include job checks and whatnot as needed too.
Whatever resource handles the spawning of police vehicles. Find where it spawns the actual vehicle and just add the snippet I posted above. It’s likely they already have local assignments for the vehicle so you may want to replace mine for whatever is already used in the script to keep it uniform.
Hi again.
I have now done a bit of testing, and i think it works, but not for the vehicles i want.
If i use the garage, to spawn another vehicle, that has like 3 liveries it spawns with 1 livery on, but if i use the admin menu, it has another livery. So it works. But not for the cars i want.
I think the reason to this is, that other vehicles has all their liveries in the texture thing (.ytd)so it just picks number 1 out of all 3. But the vehicle i want to do it on, has all the liveries inside a .yft file.
Hope you understand me.
This is where i put the “script”
function TakeOutVehicle(vehicleInfo)
local coords = Config.Locations["vehicle"][currentGarage]
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
QBCore.Functions.SpawnVehicle(vehicleInfo, function(veh)
SetVehicleNumberPlateText(veh, "PLZI"..tostring(math.random(1000, 9999)))
SetEntityHeading(veh, coords.w)
SetVehicleLivery(veh, 1)
exports['LegacyFuel']:SetFuel(veh, 100.0)
closeMenuFull()
TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(veh))
TriggerServerEvent("inventory:server:addTrunkItems", GetVehicleNumberPlateText(veh), Config.CarItems)
SetVehicleEngineOn(veh, true, true)
end, coords, true)
end
Just an example. But what i think normal vehicles has in their .ytd file.
But my vehicle livery file thing is a yft file.
Might sound confusing, but hope you understand me.