mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
!refactor(es_extended): Correct Onesync Spawning
this will break any script currently using ESX.OneSync.SpawnVehicle but, its a needed change
This commit is contained in:
@@ -193,6 +193,18 @@ AddEventHandler('esx:restoreLoadout', function()
|
||||
end
|
||||
end)
|
||||
|
||||
AddStateBagChangeHandler('VehicleProperties', nil, function(bagName, key, value)
|
||||
if value then
|
||||
Wait(0)
|
||||
local NetId = tonumber(bagName:gsub('entity:', ''), 10)
|
||||
local Vehicle = NetworkGetEntityFromNetworkId(NetId)
|
||||
|
||||
if NetworkGetEntityOwner(Vehicle) == PlayerId() then
|
||||
ESX.Game.SetVehicleProperties(Vehicle, value)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:setAccountMoney')
|
||||
AddEventHandler('esx:setAccountMoney', function(account)
|
||||
for i=1, #(ESX.PlayerData.accounts) do
|
||||
|
||||
@@ -59,18 +59,22 @@ end
|
||||
---@param model number|string
|
||||
---@param coords vector3|table
|
||||
---@param heading number
|
||||
---@param autoMobile boolean
|
||||
---@param Properties table
|
||||
---@param cb function
|
||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb)
|
||||
if type(model) == 'string' then model = joaat(model) end
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
if type(autoMobile) ~= 'boolean' then
|
||||
return
|
||||
end
|
||||
CreateThread(function()
|
||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, Properties, cb)
|
||||
model = type(model) == 'string' and joaat(model) or model
|
||||
Properties = Properties or {}
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
if type(autoMobile) ~= 'boolean' then
|
||||
return
|
||||
end
|
||||
CreateThread(function()
|
||||
local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true)
|
||||
while not DoesEntityExist(Entity) do
|
||||
Wait(0)
|
||||
end
|
||||
Entity(Entity).state:set('VehicleProperties', Properties, true)
|
||||
local netID = NetworkGetNetworkIdFromEntity(Entity)
|
||||
cb(netID)
|
||||
end)
|
||||
@@ -197,16 +201,6 @@ function ESX.OneSync.GetClosestVehicle(coords, modelFilter)
|
||||
return getClosestEntity(GetAllVehicles(), coords, modelFilter)
|
||||
end
|
||||
|
||||
ESX.RegisterServerCallback("esx:Onesync:SpawnVehicle", function(source, cb, model, coords, heading, autoMobile)
|
||||
ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback("esx:Onesync:SpawnObject", function(source, cb, model, coords, heading)
|
||||
ESX.OneSync.SpawnObject(model, coords, heading, cb)
|
||||
end)
|
||||
|
||||
-- for k,v in pairs(ESX.OneSync) do
|
||||
-- ESX.RegisterServerCallback("esx:Onesync:"..k, function(source, cb, ...)
|
||||
-- cb(v(...))
|
||||
-- end)
|
||||
-- end
|
||||
Reference in New Issue
Block a user