mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
feat: es_extended - basic Onesync infinity support
This commit is contained in:
@@ -403,23 +403,14 @@ function ESX.UI.ShowInventoryItemNotification(add, item, count)
|
||||
end
|
||||
|
||||
function ESX.Game.GetPedMugshot(ped, transparent)
|
||||
if DoesEntityExist(ped) then
|
||||
local mugshot
|
||||
if not DoesEntityExist(ped) then return end
|
||||
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)
|
||||
|
||||
if transparent then
|
||||
mugshot = RegisterPedheadshotTransparent(ped)
|
||||
else
|
||||
mugshot = RegisterPedheadshot(ped)
|
||||
end
|
||||
|
||||
while not IsPedheadshotReady(mugshot) do
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
return mugshot, GetPedheadshotTxdString(mugshot)
|
||||
else
|
||||
return
|
||||
while not IsPedheadshotReady(mugshot) do
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
return mugshot, GetPedheadshotTxdString(mugshot)
|
||||
end
|
||||
|
||||
function ESX.Game.Teleport(entity, coords, cb)
|
||||
@@ -442,18 +433,34 @@ function ESX.Game.Teleport(entity, coords, cb)
|
||||
end
|
||||
|
||||
function ESX.Game.SpawnObject(object, coords, cb, networked)
|
||||
local model = type(object) == 'number' and object or GetHashKey(object)
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
networked = networked == nil and true or networked
|
||||
if networked then
|
||||
ESX.TriggerServerCallback('esx:Onesync:SpawnObject', function(NetworkID)
|
||||
if cb then
|
||||
local obj = NetworkGetEntityFromNetworkId(NetworkID)
|
||||
local Tries = 0
|
||||
while not DoesEntityExist(obj) do
|
||||
Wait(0)
|
||||
Tries += 1
|
||||
if Tries > 250 then
|
||||
break
|
||||
end
|
||||
end
|
||||
cb(obj)
|
||||
end
|
||||
end, object, coords, 0.0)
|
||||
else
|
||||
local model = type(object) == 'number' and object or GetHashKey(object)
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
CreateThread(function()
|
||||
ESX.Streaming.RequestModel(model)
|
||||
|
||||
CreateThread(function()
|
||||
ESX.Streaming.RequestModel(model)
|
||||
|
||||
local obj = CreateObject(model, vector.xyz, networked, false, true)
|
||||
if cb then
|
||||
cb(obj)
|
||||
end
|
||||
end)
|
||||
local obj = CreateObject(model, vector.xyz, networked, false, true)
|
||||
if cb then
|
||||
cb(obj)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.Game.SpawnLocalObject(object, coords, cb)
|
||||
@@ -461,7 +468,7 @@ function ESX.Game.SpawnLocalObject(object, coords, cb)
|
||||
end
|
||||
|
||||
function ESX.Game.DeleteVehicle(vehicle)
|
||||
SetEntityAsMissionEntity(vehicle, false, true)
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
DeleteVehicle(vehicle)
|
||||
end
|
||||
|
||||
@@ -474,30 +481,59 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
|
||||
local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
networked = networked == nil and true or networked
|
||||
CreateThread(function()
|
||||
ESX.Streaming.RequestModel(model)
|
||||
if networked then
|
||||
local isAutomobile = IsThisModelACar(model)
|
||||
if isAutomobile ~= false then isAutomobile = true end
|
||||
ESX.TriggerServerCallback('esx:Onesync:SpawnVehicle', function(NetID)
|
||||
print("Spawned Vehicle: " .. NetID)
|
||||
if NetID then
|
||||
Wait(250)
|
||||
local vehicle = NetworkGetEntityFromNetworkId(NetID)
|
||||
local Tries = 0
|
||||
while not DoesEntityExist(vehicle) do
|
||||
Wait(0)
|
||||
Tries += 1
|
||||
if Tries > 300 then
|
||||
break
|
||||
end
|
||||
end
|
||||
print("Spawned Vehicle: " .. vehicle)
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleNeedsToBeHotwired(vehicle, false)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetVehRadioStation(vehicle, 'OFF')
|
||||
if cb then
|
||||
cb(vehicle)
|
||||
end
|
||||
end
|
||||
end, vehicle, coords, heading, isAutomobile)
|
||||
else
|
||||
CreateThread(function()
|
||||
ESX.Streaming.RequestModel(model)
|
||||
|
||||
local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false)
|
||||
local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false)
|
||||
|
||||
if networked then
|
||||
local id = NetworkGetNetworkIdFromEntity(vehicle)
|
||||
SetNetworkIdCanMigrate(id, true)
|
||||
SetEntityAsMissionEntity(vehicle, true, false)
|
||||
end
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleNeedsToBeHotwired(vehicle, false)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetVehRadioStation(vehicle, 'OFF')
|
||||
if networked then
|
||||
local id = NetworkGetNetworkIdFromEntity(vehicle)
|
||||
SetNetworkIdCanMigrate(id, true)
|
||||
SetEntityAsMissionEntity(vehicle, true, false)
|
||||
end
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleNeedsToBeHotwired(vehicle, false)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetVehRadioStation(vehicle, 'OFF')
|
||||
|
||||
RequestCollisionAtCoord(vector.xyz)
|
||||
while not HasCollisionLoadedAroundEntity(vehicle) do
|
||||
Wait(0)
|
||||
end
|
||||
RequestCollisionAtCoord(vector.xyz)
|
||||
while not HasCollisionLoadedAroundEntity(vehicle) do
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
if cb then
|
||||
cb(vehicle)
|
||||
end
|
||||
end)
|
||||
if cb then
|
||||
cb(vehicle)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.Game.SpawnLocalVehicle(vehicle, coords, heading, cb)
|
||||
@@ -549,6 +585,7 @@ function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
|
||||
return players
|
||||
end
|
||||
|
||||
|
||||
function ESX.Game.GetClosestObject(coords, modelFilter)
|
||||
return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter)
|
||||
end
|
||||
@@ -665,7 +702,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
|
||||
|
||||
for extraId = 0, 12 do
|
||||
if DoesExtraExist(vehicle, extraId) then
|
||||
local state = IsVehicleExtraTurnedOn(vehicle, extraId) == 1
|
||||
local state = IsVehicleExtraTurnedOn(vehicle, extraId)
|
||||
extras[tostring(extraId)] = state
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,15 +25,14 @@ local function getNearbyPlayers(source, closest, distance, ignore)
|
||||
local coords = GetEntityCoords(entity)
|
||||
|
||||
if not closest then
|
||||
local dist = #(source - coords)
|
||||
local dist = #(xPlayer.source - coords)
|
||||
if dist <= distance then
|
||||
count += 1
|
||||
result[count] = {id = xPlayer.source, ped = entity, coords = coords, dist = dist}
|
||||
result[count] = {id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist}
|
||||
end
|
||||
else
|
||||
local dist = #(source - coords)
|
||||
if dist <= (result.dist or distance) then
|
||||
result = {id = xPlayer.source, ped = entity, coords = coords, dist = dist}
|
||||
local dist = #(xPlayer.source - coords)
|
||||
result = {id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist} if dist <= (result.dist or distance) then
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -60,12 +59,13 @@ end
|
||||
---@param coords vector3|table
|
||||
---@param heading number
|
||||
---@param cb function
|
||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, cb)
|
||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile)
|
||||
if type(model) == 'string' then model = GetHashKey(model) end
|
||||
CreateThread(function()
|
||||
local entity = Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading)
|
||||
while not DoesEntityExist(entity) do Wait(50) end
|
||||
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
if type(autoMobile) ~= 'boolean' then
|
||||
return
|
||||
end
|
||||
local entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true)
|
||||
-- Sometimes peds can spawn in the vehicle
|
||||
local ped = GetPedInVehicleSeat(entity, -1)
|
||||
if ped > 0 then
|
||||
@@ -77,22 +77,32 @@ function ESX.OneSync.SpawnVehicle(model, coords, heading, cb)
|
||||
end
|
||||
end
|
||||
end
|
||||
print('Spawned vehicle: ' .. entity)
|
||||
local tries = 0
|
||||
while not DoesEntityExist(entity) do
|
||||
Wait(0)
|
||||
tries = tries + 1
|
||||
if tries > 250 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
cb(entity)
|
||||
end)
|
||||
print(DoesEntityExist(entity) and NetworkGetNetworkIdFromEntity(entity) or false)
|
||||
return DoesEntityExist(entity) and NetworkGetNetworkIdFromEntity(entity) or false
|
||||
end
|
||||
|
||||
---@param model number|string
|
||||
---@param coords vector3|table
|
||||
---@param heading number
|
||||
---@param cb function
|
||||
function ESX.OneSync.SpawnObject(model, coords, heading, cb)
|
||||
function ESX.OneSync.SpawnObject(model, coords, heading)
|
||||
if type(model) == 'string' then model = GetHashKey(model) end
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
CreateThread(function()
|
||||
local entity = CreateObject(model, coords, true, true)
|
||||
while not DoesEntityExist(entity) do Wait(50) end
|
||||
SetEntityHeading(entity, heading)
|
||||
cb(entity)
|
||||
return DoesEntityExist(entity) and NetworkGetNetworkIdFromEntity(entity) or false
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -105,7 +115,7 @@ function ESX.OneSync.SpawnPed(model, coords, heading, cb)
|
||||
CreateThread(function()
|
||||
local entity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, true, true)
|
||||
while not DoesEntityExist(entity) do Wait(50) end
|
||||
cb(entity)
|
||||
return entity
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -118,7 +128,7 @@ function ESX.OneSync.SpawnPedInVehicle(model, vehicle, seat, cb)
|
||||
CreateThread(function()
|
||||
local entity = CreatePedInsideVehicle(vehicle, 1, model, seat, true, true)
|
||||
while not DoesEntityExist(entity) do Wait(50) end
|
||||
cb(entity)
|
||||
return entity
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -130,7 +140,7 @@ local function getNearbyEntities(entities, coords, modelFilter, maxDistance, isP
|
||||
if not modelFilter or modelFilter[GetEntityModel(entity)] then
|
||||
local entityCoords = GetEntityCoords(entity)
|
||||
if not maxDistance or #(coords - entityCoords) <= maxDistance then
|
||||
nearbyEntities[#nearbyEntities+1] = {entity=entity, coords=entityCoords}
|
||||
nearbyEntities[#nearbyEntities+1] = NetworkGetNetworkIdFromEntity(entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -178,7 +188,7 @@ local function getClosestEntity(entities, coords, modelFilter, isPed)
|
||||
end
|
||||
end
|
||||
end
|
||||
return closestEntity, distance, closestCoords
|
||||
return NetworkGetNetworkIdFromEntity(closestEntity), distance, closestCoords
|
||||
end
|
||||
|
||||
---@param coords vector3
|
||||
@@ -201,3 +211,9 @@ end
|
||||
function ESX.OneSync.GetClosestVehicle(coords, modelFilter)
|
||||
return getClosestEntity(GetAllVehicles(), coords, modelFilter)
|
||||
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