mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
refactor(client/vehicleProperties): driftTyres and window tweaks
+ some notes about setting props from server.
This commit is contained in:
@@ -84,6 +84,7 @@ interface VehicleProperties {
|
|||||||
frontBumper: boolean;
|
frontBumper: boolean;
|
||||||
rearBumper: boolean;
|
rearBumper: boolean;
|
||||||
bulletProofTyres: boolean;
|
bulletProofTyres: boolean;
|
||||||
|
driftTyres: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getVehicleProperties = (vehicle: number): VehicleProperties =>
|
export const getVehicleProperties = (vehicle: number): VehicleProperties =>
|
||||||
|
|||||||
@@ -82,7 +82,10 @@ if cache.game == 'redm' then return end
|
|||||||
---@field doors? number[]
|
---@field doors? number[]
|
||||||
---@field tyres? table<number | string, 1 | 2>
|
---@field tyres? table<number | string, 1 | 2>
|
||||||
---@field bulletProofTyres? boolean
|
---@field bulletProofTyres? boolean
|
||||||
|
---@field driftTyres? boolean
|
||||||
|
|
||||||
|
---@deprecated
|
||||||
|
---Not recommended. Entity owners can change rapidly and sporadically.
|
||||||
RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data)
|
RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data)
|
||||||
local timeout = 100
|
local timeout = 100
|
||||||
while not NetworkDoesEntityExistWithNetworkId(netid) and timeout > 0 do
|
while not NetworkDoesEntityExistWithNetworkId(netid) and timeout > 0 do
|
||||||
@@ -94,6 +97,21 @@ RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data)
|
|||||||
end
|
end
|
||||||
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
|
---@param vehicle number
|
||||||
---@return VehicleProperties?
|
---@return VehicleProperties?
|
||||||
function lib.getVehicleProperties(vehicle)
|
function lib.getVehicleProperties(vehicle)
|
||||||
@@ -134,6 +152,8 @@ function lib.getVehicleProperties(vehicle)
|
|||||||
local windows = 0
|
local windows = 0
|
||||||
|
|
||||||
for i = 0, 7 do
|
for i = 0, 7 do
|
||||||
|
RollUpWindow(vehicle, i)
|
||||||
|
|
||||||
if not IsVehicleWindowIntact(vehicle, i) then
|
if not IsVehicleWindowIntact(vehicle, i) then
|
||||||
windows += 1
|
windows += 1
|
||||||
damage.windows[windows] = i
|
damage.windows[windows] = i
|
||||||
@@ -243,6 +263,7 @@ function lib.getVehicleProperties(vehicle)
|
|||||||
doors = damage.doors,
|
doors = damage.doors,
|
||||||
tyres = damage.tyres,
|
tyres = damage.tyres,
|
||||||
bulletProofTyres = GetVehicleTyresCanBurst(vehicle),
|
bulletProofTyres = GetVehicleTyresCanBurst(vehicle),
|
||||||
|
driftTyres = GetDriftTyresEnabled(vehicle),
|
||||||
-- no setters?
|
-- no setters?
|
||||||
-- leftHeadlight = GetIsLeftVehicleHeadlightDamaged(vehicle),
|
-- leftHeadlight = GetIsLeftVehicleHeadlightDamaged(vehicle),
|
||||||
-- rightHeadlight = GetIsRightVehicleHeadlightDamaged(vehicle),
|
-- rightHeadlight = GetIsRightVehicleHeadlightDamaged(vehicle),
|
||||||
@@ -362,7 +383,7 @@ function lib.setVehicleProperties(vehicle, props)
|
|||||||
|
|
||||||
if props.windows then
|
if props.windows then
|
||||||
for i = 1, #props.windows do
|
for i = 1, #props.windows do
|
||||||
SmashVehicleWindow(vehicle, props.windows[i])
|
RemoveVehicleWindow(vehicle, props.windows[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -599,5 +620,9 @@ function lib.setVehicleProperties(vehicle, props)
|
|||||||
SetVehicleTyresCanBurst(vehicle, props.bulletProofTyres)
|
SetVehicleTyresCanBurst(vehicle, props.bulletProofTyres)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if props.driftTyres then
|
||||||
|
SetDriftTyresEnabled(vehicle, true)
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user