improvement(esx): Replace entity iterator with GetGamePool natives

This commit is contained in:
Linden
2021-07-04 05:01:09 +10:00
parent e6c93505a2
commit ac5e7256de
+33 -25
View File
@@ -402,7 +402,6 @@ ESX.Game.SpawnVehicle = function(vehicle, coords, heading, cb, networked)
end
ESX.Game.SpawnLocalVehicle = function(vehicle, coords, heading, cb)
-- Why have 2 separate functions for this? Just call the other one with an extra param
ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, false)
end
@@ -413,20 +412,14 @@ ESX.Game.IsVehicleEmpty = function(vehicle)
return passengers == 0 and driverSeatFree
end
ESX.Game.GetObjects = function()
local objects = {}
for object in EnumerateObjects() do
table.insert(objects, object)
end
return objects
ESX.Game.GetObjects = function() -- Leave the function for compatibility
return GetGamePool('CObject')
end
ESX.Game.GetPeds = function(onlyOtherPeds)
local peds, myPed = {}, ESX.PlayerData.ped
for ped in EnumeratePeds() do
for ped in GetGamePool('CPed') do
if ((onlyOtherPeds and ped ~= myPed) or not onlyOtherPeds) then
table.insert(peds, ped)
end
@@ -435,14 +428,8 @@ ESX.Game.GetPeds = function(onlyOtherPeds)
return peds
end
ESX.Game.GetVehicles = function()
local vehicles = {}
for vehicle in EnumerateVehicles() do
table.insert(vehicles, vehicle)
end
return vehicles
ESX.Game.GetVehicles = function() -- Leave the function for compatibility
return GetGamePool('CVehicle')
end
ESX.Game.GetPlayers = function(onlyOtherPlayers, returnKeyValue, returnPeds)
@@ -463,13 +450,34 @@ ESX.Game.GetPlayers = function(onlyOtherPlayers, returnKeyValue, returnPeds)
return players
end
ESX.Game.GetClosestObject = function(coords, modelFilter) return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter) end
ESX.Game.GetClosestPed = function(coords, modelFilter) return ESX.Game.GetClosestEntity(ESX.Game.GetPeds(true), false, coords, modelFilter) end
ESX.Game.GetClosestPlayer = function(coords) return ESX.Game.GetClosestEntity(ESX.Game.GetPlayers(true, true), true, coords, nil) end
ESX.Game.GetClosestVehicle = function(coords, modelFilter) return ESX.Game.GetClosestEntity(ESX.Game.GetVehicles(), false, coords, modelFilter) end
ESX.Game.GetPlayersInArea = function(coords, maxDistance) return EnumerateEntitiesWithinDistance(ESX.Game.GetPlayers(true, true), true, coords, maxDistance) end
ESX.Game.GetVehiclesInArea = function(coords, maxDistance) return EnumerateEntitiesWithinDistance(ESX.Game.GetVehicles(), false, coords, maxDistance) end
ESX.Game.IsSpawnPointClear = function(coords, maxDistance) return #ESX.Game.GetVehiclesInArea(coords, maxDistance) == 0 end
ESX.Game.GetClosestObject = function(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter)
end
ESX.Game.GetClosestPed = function(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetPeds(true), false, coords, modelFilter)
end
ESX.Game.GetClosestPlayer = function(coords)
return ESX.Game.GetClosestEntity(ESX.Game.GetPlayers(true, true), true, coords, nil)
end
ESX.Game.GetClosestVehicle = function(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetVehicles(), false, coords, modelFilter)
end
ESX.Game.GetPlayersInArea = function(coords, maxDistance)
return EnumerateEntitiesWithinDistance(ESX.Game.GetPlayers(true, true), true, coords, maxDistance)
end
ESX.Game.GetVehiclesInArea = function(coords, maxDistance)
return EnumerateEntitiesWithinDistance(ESX.Game.GetVehicles(), false, coords, maxDistance)
end
ESX.Game.IsSpawnPointClear = function(coords, maxDistance)
return #ESX.Game.GetVehiclesInArea(coords, maxDistance) == 0
end
ESX.Game.GetClosestEntity = function(entities, isPlayerEntities, coords, modelFilter)
local closestEntity, closestEntityDistance, filteredEntities = -1, -1, nil