Skip to content

Commit

Permalink
feat(client/vehicleproperties): add fixVehicle parameter (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
jellyton255 authored Aug 15, 2023
1 parent a97b9ba commit 0c072ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion package/client/resource/vehicleProperties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface VehicleProperties {
fuelLevel: number;
oilLevel: number;
dirtLevel: number;
paintType1: number;
paintType2: number;
color1: number | [number, number, number];
color2: number | [number, number, number];
pearlescentColor: number;
Expand Down Expand Up @@ -90,5 +92,5 @@ interface VehicleProperties {
export const getVehicleProperties = (vehicle: number): VehicleProperties =>
exports.ox_lib.getVehicleProperties(vehicle);

export const setVehicleProperties = (vehicle: number, props: Partial<VehicleProperties>): boolean =>
export const setVehicleProperties = (vehicle: number, props: Partial<VehicleProperties>, fixVehicle?: boolean): boolean =>
exports.ox_lib.setVehicleProperties(vehicle, props);
27 changes: 17 additions & 10 deletions resource/vehicleProperties/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -634,5 +637,9 @@ function lib.setVehicleProperties(vehicle, props)
SetDriftTyresEnabled(vehicle, true)
end

if fixVehicle then
SetVehicleFixed(vehicle)
end

return true
end

0 comments on commit 0c072ef

Please sign in to comment.