mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 00:01:22 +00:00
New function for server vehicle spawning
This commit is contained in:
+27
-3
@@ -220,7 +220,8 @@ function QBCore.Functions.SpawnVehicle(source, model, coords, warp)
|
||||
local ped = GetPlayerPed(source)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
if not coords then coords = GetEntityCoords(ped) end
|
||||
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true)
|
||||
local heading = coords.w and coords.w or 0.0
|
||||
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, true)
|
||||
while not DoesEntityExist(veh) do Wait(0) end
|
||||
if warp then
|
||||
while GetVehiclePedIsIn(ped) ~= veh do
|
||||
@@ -241,11 +242,34 @@ end
|
||||
---@param coords vector
|
||||
---@param warp boolean
|
||||
---@return number
|
||||
function QBCore.Functions.CreateVehicle(source, model, coords, warp)
|
||||
function QBCore.Functions.CreateAutomobile(source, model, coords, warp)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end
|
||||
local heading = coords.w and coords.w or 0.0
|
||||
local CreateAutomobile = `CREATE_AUTOMOBILE`
|
||||
local veh = Citizen.InvokeNative(CreateAutomobile, model, coords, coords.w, true, true)
|
||||
local veh = Citizen.InvokeNative(CreateAutomobile, model, coords, heading, true, true)
|
||||
while not DoesEntityExist(veh) do Wait(0) end
|
||||
if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end
|
||||
return veh
|
||||
end
|
||||
|
||||
--- New & more reliable server side native for creating vehicles
|
||||
---comment
|
||||
---@param source any
|
||||
---@param model any
|
||||
---@param vehtype any
|
||||
-- The appropriate vehicle type for the model info.
|
||||
-- Can be one of automobile, bike, boat, heli, plane, submarine, trailer, and (potentially), train.
|
||||
-- This should be the same type as the type field in vehicles.meta.
|
||||
---@param coords vector
|
||||
---@param warp boolean
|
||||
---@return number
|
||||
function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
vehtype = type(vehtype) == 'string' and tostring(vehtype) or vehtype
|
||||
if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end
|
||||
local heading = coords.w and coords.w or 0.0
|
||||
local veh = CreateVehicleServerSetter(model, vehtype, coords, heading)
|
||||
while not DoesEntityExist(veh) do Wait(0) end
|
||||
if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end
|
||||
return veh
|
||||
|
||||
Reference in New Issue
Block a user