mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 02:01:31 +00:00
fix(es_extended): dont spawn vehicle if non-existant
This commit is contained in:
@@ -690,28 +690,33 @@ AddEventHandler("esx:freezePlayer", function(input)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("esx:GetVehicleType", function(Model, Request)
|
RegisterNetEvent("esx:GetVehicleType", function(Model, Request)
|
||||||
|
local ReturnedType = "automobile"
|
||||||
local Model = Model
|
local Model = Model
|
||||||
local VehicleType = GetVehicleClassFromName(Model)
|
local IsValidModel = IsModelInCdimage(Model)
|
||||||
local type = "automobile"
|
if IsValidModel == true or IsValidModel == 1 then
|
||||||
if VehicleType == 15 then
|
local VehicleType = GetVehicleClassFromName(Model)
|
||||||
type = "heli"
|
|
||||||
elseif VehicleType == 16 then
|
|
||||||
type = "plane"
|
|
||||||
elseif VehicleType == 14 then
|
|
||||||
type = "boat"
|
|
||||||
elseif VehicleType == 11 then
|
|
||||||
type = "trailer"
|
|
||||||
elseif VehicleType == 21 then
|
|
||||||
type = "train"
|
|
||||||
elseif VehicleType == 13 or VehicleType == 8 then
|
|
||||||
type = "bike"
|
|
||||||
end
|
|
||||||
if Model == `submersible` or Model == `submersible2` then
|
|
||||||
type = "submarine"
|
|
||||||
end
|
|
||||||
TriggerServerEvent("esx:ReturnVehicleType", type, Request)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
if VehicleType == 15 then
|
||||||
|
ReturnedType = "heli"
|
||||||
|
elseif VehicleType == 16 then
|
||||||
|
ReturnedType = "plane"
|
||||||
|
elseif VehicleType == 14 then
|
||||||
|
ReturnedType = "boat"
|
||||||
|
elseif VehicleType == 11 then
|
||||||
|
ReturnedType = "trailer"
|
||||||
|
elseif VehicleType == 21 then
|
||||||
|
ReturnedType = "train"
|
||||||
|
elseif VehicleType == 13 or VehicleType == 8 then
|
||||||
|
ReturnedType = "bike"
|
||||||
|
end
|
||||||
|
if Model == `submersible` or Model == `submersible2` then
|
||||||
|
ReturnedType = "submarine"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ReturnedType = false
|
||||||
|
end
|
||||||
|
TriggerServerEvent("esx:ReturnVehicleType", ReturnedType, Request)
|
||||||
|
end)
|
||||||
|
|
||||||
local DoNotUse = {
|
local DoNotUse = {
|
||||||
'essentialmode',
|
'essentialmode',
|
||||||
|
|||||||
@@ -61,23 +61,29 @@ end
|
|||||||
---@param heading number
|
---@param heading number
|
||||||
---@param Properties table
|
---@param Properties table
|
||||||
---@param cb function
|
---@param cb function
|
||||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, Properties, cb)
|
function ESX.OneSync.SpawnVehicle(model, coords, heading, Properties, cb)
|
||||||
model = type(model) == 'string' and joaat(model) or model
|
local veh_model = type(model) == 'string' and joaat(model) or model
|
||||||
Properties = Properties or {}
|
Properties = Properties or {}
|
||||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||||
TriggerClientEvent("esx:requestModel", -1, model)
|
TriggerClientEvent("esx:requestModel", -1, model)
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local xPlayer = ESX.OneSync.GetClosestPlayer(vector, 200)
|
local xPlayer = ESX.OneSync.GetClosestPlayer(vector, 300)
|
||||||
ESX.GetVehicleType(model, xPlayer.id, function(Type)
|
ESX.GetVehicleType(veh_model, xPlayer.id, function(Type)
|
||||||
local SpawnedEntity = CreateVehicleServerSetter(model, Type, vector, heading)
|
if Type then
|
||||||
Wait(250)
|
local SpawnedEntity = CreateVehicleServerSetter(veh_model, Type, vector, heading)
|
||||||
local NetworkId = NetworkGetNetworkIdFromEntity(SpawnedEntity)
|
local NetworkId = NetworkGetNetworkIdFromEntity(SpawnedEntity)
|
||||||
Properties.NetId = NetworkId
|
while not DoesEntityExist(SpawnedEntity) do
|
||||||
Entity(SpawnedEntity).state:set('VehicleProperties', Properties, true)
|
Wait(100)
|
||||||
cb(NetworkId)
|
end
|
||||||
end)
|
Properties.NetId = NetworkId
|
||||||
end)
|
Entity(SpawnedEntity).state:set('VehicleProperties', Properties, true)
|
||||||
end
|
cb(NetworkId)
|
||||||
|
else
|
||||||
|
print(('[^1ERROR^7] Tried to spawn invalid vehicle - ^5%s^7!'):format(model))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param model number|string
|
---@param model number|string
|
||||||
|
|||||||
Reference in New Issue
Block a user