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(lib/spawn): retrieve vehicle type #651

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 13 additions & 9 deletions modules/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,7 @@ if isServer then
coords = vec4(pedCoords.x, pedCoords.y, pedCoords.z, GetEntityHeading(source))
end

local vehicleType = exports.qbx_core:GetVehiclesByHash(model).type
if not vehicleType then
local tempVehicle = CreateVehicle(model, 0, 0, -200, 0, true, true)
while not DoesEntityExist(tempVehicle) do Wait(0) end

vehicleType = GetVehicleType(tempVehicle)
DeleteEntity(tempVehicle)
end

local vehicleType = exports.qbx_core:GetVehiclesByHash(model)?.type or lib.callback.await('qbx_core:client:getVehicleType', math.random(#GetPlayers()), model)
local attempts = 0

local veh, netId
Expand Down Expand Up @@ -347,6 +339,18 @@ if isServer then
return netId, veh
end
else
---@param model number|string
---@return string
lib.callback.register('qbx_core:client:getVehicleType', function(model)
model = lib.requestModel(model)
local coords = GetEntityCoords(cache.ped)
local tempVehicle = CreateVehicle(model, coords.x, coords.y, coords.z - 20.0, 0, false, false)
SetModelAsNoLongerNeeded(model)
local type = GetVehicleType(tempVehicle)
DeleteEntity(tempVehicle)
return type
end)

---@class LibDrawTextParams
---@field text string
---@field scale? integer default: `0.35`
Expand Down
Loading