Skip to content

Commit

Permalink
fix: vehicle spawning & bridge vehicle properties
Browse files Browse the repository at this point in the history
* converting properties between qb/ox representations for vehicle

* wait for onesync to select vehicle owner

* removed print
  • Loading branch information
Manason committed Nov 12, 2023
1 parent 2c0014f commit 62f0172
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
92 changes: 90 additions & 2 deletions bridge/qb/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,98 @@ functions.GetVehicleLabel = GetVehicleDisplayName
functions.SpawnClear = IsVehicleSpawnClear

---@deprecated use lib.getVehicleProperties from ox_lib
functions.GetVehicleProperties = lib.getVehicleProperties
function functions.GetVehicleProperties(vehicle)
local props = lib.getVehicleProperties(vehicle)
if not props then return end

local tireHealth = {}
for i = 0, 3 do
tireHealth[i] = GetVehicleWheelHealth(vehicle, i)
end

local tireBurstState = {}
local tireBurstCompletely = {}

for i = 0, 7 do
local damage = props.damage.tyres[i]
tireBurstState[i] = damage == 1 or damage == 2
tireBurstCompletely[i] = damage == 2
end

local windowStatus = {}
for i = 0, 7 do
windowStatus[i] = IsVehicleWindowIntact(vehicle, i)
end

local doorStatus = {}
for i = 0, 5 do
doorStatus[i] = IsVehicleDoorDamaged(vehicle, i) == 1
end

-- qb properties not in ox
props.tireHealth = tireHealth
props.tireBurstState = tireBurstState
props.tireBurstCompletely = tireBurstCompletely
props.windowStatus = windowStatus
props.doorStatus = doorStatus
props.headlightColor = GetVehicleHeadlightsColour(vehicle)
props.modKit17 = props.modNitrous
props.modKit19 = props.modSubwoofer
props.modKit21 = props.modHydraulics
props.modKit47 = props.modDoorR
props.modKit49 = props.modLightbar
props.liveryRoof = props.modRoofLivery

return props
end

---@deprecated use lib.setVehicleProperties from ox_lib
functions.SetVehicleProperties = lib.setVehicleProperties
function functions.SetVehicleProperties(vehicle, props)
if props.tireHealth and not props.tyres then
for wheelIndex, health in pairs(props.tireHealth) do
SetVehicleWheelHealth(vehicle, wheelIndex, health)
end
end
if props.headlightColor then
SetVehicleHeadlightsColour(vehicle, props.headlightColor)
end

local tyres = {}
for i = 0, 7 do
tyres[i] = props.tireBurstCompletely[i] and 2 or props.tireBurstState[i] and 1 or nil
end

local windows = {}
local numWindowsDamaged = 0
for i, isDamaged in pairs(props.windowStatus) do
if isDamaged then
numWindowsDamaged += 1
windows[numWindowsDamaged] = i
end
end

local doors = {}
local numDoorsDamaged = 0
for i, isDamaged in pairs(props.doorStatus) do
if isDamaged then
numDoorsDamaged += 1
doors[numDoorsDamaged] = i
end
end

-- qb properties converted to ox
props.modNitrous = props.modNitrous or props.modKit17
props.modSubwoofer = props.modSubwoofer or props.modKit17
props.modHydraulics = props.modHydraulics or props.props.modKit21
props.modDoorR = props.modDoorR or props.modKit47
props.modLightbar = props.modLightbar or props.modKit49
props.modRoofLivery = props.modRoofLivery or props.liveryRoof
props.tyres = props.tyres or #tyres > 0 and tyres or nil
props.windows = props.windows or numWindowsDamaged > 0 and windows or nil
props.doors = props.doors or numDoorsDamaged > 0 and doors or nil

return lib.setVehicleProperties(vehicle, props)
end

---@deprecated use lib.requestNamedPtfxAsset from ox_lib
functions.LoadParticleDictionary = lib.requestNamedPtfxAsset
Expand Down
3 changes: 3 additions & 0 deletions modules/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ if isServer then
end

if warp then SetPedIntoVehicle(ped, veh, -1) end
lib.waitFor(function()
if NetworkGetEntityOwner(veh) ~= -1 then return true end
end, 5000)
Entity(veh).state:set('initVehicle', true, true)
return NetworkGetNetworkIdFromEntity(veh)
end
Expand Down

0 comments on commit 62f0172

Please sign in to comment.