diff --git a/package/client/resource/vehicleProperties/index.ts b/package/client/resource/vehicleProperties/index.ts index 3b64090..39df432 100644 --- a/package/client/resource/vehicleProperties/index.ts +++ b/package/client/resource/vehicleProperties/index.ts @@ -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; @@ -90,5 +92,5 @@ interface VehicleProperties { export const getVehicleProperties = (vehicle: number): VehicleProperties => exports.ox_lib.getVehicleProperties(vehicle); -export const setVehicleProperties = (vehicle: number, props: Partial): boolean => +export const setVehicleProperties = (vehicle: number, props: Partial, fixVehicle?: boolean): boolean => exports.ox_lib.setVehicleProperties(vehicle, props); diff --git a/resource/vehicleProperties/client.lua b/resource/vehicleProperties/client.lua index 0445d19..e09a80d 100644 --- a/resource/vehicleProperties/client.lua +++ b/resource/vehicleProperties/client.lua @@ -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