feat(client/vehicleproperties): add fixVehicle parameter (#392)

This commit is contained in:
Jellyton
2023-08-14 17:40:35 -07:00
committed by GitHub
parent a97b9ba054
commit 0c072ef4f7
2 changed files with 20 additions and 11 deletions

View File

@@ -281,13 +281,16 @@ end
---@param vehicle number
---@param props VehicleProperties
---@param fixVehicle? boolean Fix the vehicle after props have been set. Usually required when adding extras.
---@return boolean?
function lib.setVehicleProperties(vehicle, props)
if not DoesEntityExist(vehicle) then error(("Unable to set vehicle properties for '%s' (entity does not exist)"):
format(vehicle))
function lib.setVehicleProperties(vehicle, props, fixVehicle)
if not DoesEntityExist(vehicle) then
error(("Unable to set vehicle properties for '%s' (entity does not exist)"):
format(vehicle))
end
if NetworkGetEntityIsNetworked(vehicle) and NetworkGetEntityOwner(vehicle) ~= cache.playerId then error((
if NetworkGetEntityIsNetworked(vehicle) and NetworkGetEntityOwner(vehicle) ~= cache.playerId then
error((
"Unable to set vehicle properties for '%s' (client is not entity owner)"):format(vehicle))
end
@@ -297,6 +300,12 @@ function lib.setVehicleProperties(vehicle, props)
SetVehicleModKit(vehicle, 0)
SetVehicleAutoRepairDisabled(vehicle, true)
if props.extras then
for id, disable in pairs(props.extras) do
SetVehicleExtra(vehicle, tonumber(id) --[[@as number]], disable == 1)
end
end
if props.plate then
SetVehicleNumberPlateText(vehicle, props.plate)
end
@@ -385,12 +394,6 @@ function lib.setVehicleProperties(vehicle, props)
end
end
if props.extras then
for id, disable in pairs(props.extras) do
SetVehicleExtra(vehicle, tonumber(id) --[[@as number]], disable == 1)
end
end
if props.windows then
for i = 1, #props.windows do
RemoveVehicleWindow(vehicle, props.windows[i])
@@ -634,5 +637,9 @@ function lib.setVehicleProperties(vehicle, props)
SetDriftTyresEnabled(vehicle, true)
end
if fixVehicle then
SetVehicleFixed(vehicle)
end
return true
end