Use ents.Iterator in place of ents.GetAll (#464)

* Use ents.Iterator in place of ents.GetAll

* syntax

* Update advdupe2.lua

---------

Co-authored-by: thegrb93 <grbrown93@sbcglobal.net>
This commit is contained in:
aStonedPenguin 2024-04-05 15:11:29 -07:00 committed by GitHub
parent 0c6f311f3a
commit 6fe9bc86ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -157,12 +157,9 @@ if(SERVER) then
--Find all the entities in a box, given the adjacent corners and the player
local function FindInBox(min, max, ply)
local PPCheck = (tobool(ply:GetInfo("advdupe2_copy_only_mine")) and ply.CPPIGetOwner~=nil) and PlayerCanDupeCPPI or PlayerCanDupeTool
local Entities = ents.GetAll() --Don't use FindInBox. It has a 512 entity limit.
local EntTable = {}
local pos, ent
for i = 1, #Entities do
ent = Entities[i]
pos = ent:GetPos()
for _, ent in ents.Iterator() do
local pos = ent:GetPos()
if (pos.X>=min.X) and (pos.X<=max.X) and
(pos.Y>=min.Y) and (pos.Y<=max.Y) and
(pos.Z>=min.Z) and (pos.Z<=max.Z) and PPCheck( ply, ent ) then
@ -335,7 +332,7 @@ if(SERVER) then
--select all owned props
Entities = {}
local PPCheck = (tobool(ply:GetInfo("advdupe2_copy_only_mine")) and CPPI~=nil) and PlayerCanDupeCPPI or PlayerCanDupeTool
for _, ent in pairs(ents.GetAll()) do
for _, ent in ents.Iterator() do
if PPCheck( ply, ent ) then
Entities[ent:EntIndex()] = ent
end
@ -812,10 +809,10 @@ if(SERVER) then
return
end
local Entities = ents.GetAll()
for k,v in pairs(Entities) do
if v:CreatedByMap() or not AdvDupe2.duplicator.IsCopyable(v) then
Entities[k]=nil
local Entities = {}
for _, v in ents.Iterator() do
if not v:CreatedByMap() and AdvDupe2.duplicator.IsCopyable(v) then
Entities[v:EntIndex()] = v
end
end
@ -1688,10 +1685,8 @@ if(CLIENT) then
local function FindInBox(min, max, ply)
local Entities = ents.GetAll()
local EntTable = {}
for _,ent in pairs(Entities) do
for _,ent in ents.Iterator() do
local pos = ent:GetPos()
if (pos.X>=min.X) and (pos.X<=max.X) and (pos.Y>=min.Y) and (pos.Y<=max.Y) and (pos.Z>=min.Z) and (pos.Z<=max.Z) then
--if(ent:GetClass()~="C_BaseFlexclass") then