From c6742eeae934b8c5ae3b44cf8d75a505356d7aff Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 31 Jul 2023 11:00:07 +1000 Subject: [PATCH] refactor(client/vehicleProperties): driftTyres and window tweaks + some notes about setting props from server. --- .../resource/vehicleProperties/index.ts | 1 + resource/vehicleProperties/client.lua | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package/client/resource/vehicleProperties/index.ts b/package/client/resource/vehicleProperties/index.ts index 3209564..3b64090 100644 --- a/package/client/resource/vehicleProperties/index.ts +++ b/package/client/resource/vehicleProperties/index.ts @@ -84,6 +84,7 @@ interface VehicleProperties { frontBumper: boolean; rearBumper: boolean; bulletProofTyres: boolean; + driftTyres: boolean; } export const getVehicleProperties = (vehicle: number): VehicleProperties => diff --git a/resource/vehicleProperties/client.lua b/resource/vehicleProperties/client.lua index c46e63f..5f7c9d3 100644 --- a/resource/vehicleProperties/client.lua +++ b/resource/vehicleProperties/client.lua @@ -82,7 +82,10 @@ if cache.game == 'redm' then return end ---@field doors? number[] ---@field tyres? table ---@field bulletProofTyres? boolean +---@field driftTyres? boolean +---@deprecated +---Not recommended. Entity owners can change rapidly and sporadically. RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data) local timeout = 100 while not NetworkDoesEntityExistWithNetworkId(netid) and timeout > 0 do @@ -94,6 +97,21 @@ RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data) end end) +--[[ Alternative to NetEvent - disabled (at least for now?) +AddStateBagChangeHandler('setVehicleProperties', '', function(bagName, _, value) + if not value or not GetEntityFromStateBagName then return end + + local entity = GetEntityFromStateBagName(bagName) + local networked = not bagName:find('localEntity') + + if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end + + if lib.setVehicleProperties(entity, value) then + Entity(entity).state:set('setVehicleProperties', nil, true) + end +end) +]] + ---@param vehicle number ---@return VehicleProperties? function lib.getVehicleProperties(vehicle) @@ -134,6 +152,8 @@ function lib.getVehicleProperties(vehicle) local windows = 0 for i = 0, 7 do + RollUpWindow(vehicle, i) + if not IsVehicleWindowIntact(vehicle, i) then windows += 1 damage.windows[windows] = i @@ -243,6 +263,7 @@ function lib.getVehicleProperties(vehicle) doors = damage.doors, tyres = damage.tyres, bulletProofTyres = GetVehicleTyresCanBurst(vehicle), + driftTyres = GetDriftTyresEnabled(vehicle), -- no setters? -- leftHeadlight = GetIsLeftVehicleHeadlightDamaged(vehicle), -- rightHeadlight = GetIsRightVehicleHeadlightDamaged(vehicle), @@ -362,7 +383,7 @@ function lib.setVehicleProperties(vehicle, props) if props.windows then for i = 1, #props.windows do - SmashVehicleWindow(vehicle, props.windows[i]) + RemoveVehicleWindow(vehicle, props.windows[i]) end end @@ -599,5 +620,9 @@ function lib.setVehicleProperties(vehicle, props) SetVehicleTyresCanBurst(vehicle, props.bulletProofTyres) end + if props.driftTyres then + SetDriftTyresEnabled(vehicle, true) + end + return true end