mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
refactor(client/vehicleProperties): driftTyres and window tweaks
+ some notes about setting props from server.
This commit is contained in:
@@ -82,7 +82,10 @@ if cache.game == 'redm' then return end
|
||||
---@field doors? number[]
|
||||
---@field tyres? table<number | string, 1 | 2>
|
||||
---@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
|
||||
|
||||
Reference in New Issue
Block a user