Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vehicle spawning #234

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading