Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ents/player.Iterator instead of GetAll #2073

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion garrysmod/gamemodes/base/gamemode/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function GM:OnChatTab( str )

if ( LastWord == nil ) then return str end

for k, v in ipairs( player.GetAll() ) do
for _, v in player.Iterator() do

local nickname = v:Nick()

Expand Down
8 changes: 4 additions & 4 deletions garrysmod/gamemodes/base/gamemode/cl_scoreboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ local PLAYER_LINE = {

self.Mute.PaintOver = function( s, w, h )
if ( !IsValid( self.Player ) ) then return end

local a = 255 - math.Clamp( CurTime() - ( s.LastTick or 0 ), 0, 3 ) * 255
if ( a <= 0 ) then return end

draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 0, 0, a * 0.75 ) )
draw.SimpleText( math.ceil( self.Player:GetVoiceVolumeScale() * 100 ) .. "%", "DermaDefaultBold", w / 2, h / 2, Color( 255, 255, 255, a ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
Expand Down Expand Up @@ -240,8 +240,8 @@ local SCORE_BOARD = {
--
-- Loop through each player, and if one doesn't have a score entry - create it.
--
for id, pl in ipairs( player.GetAll() ) do

for _, pl in player.Iterator() do

if ( IsValid( pl.ScoreEntry ) ) then continue end

Expand Down
8 changes: 4 additions & 4 deletions garrysmod/gamemodes/sandbox/gamemode/persistence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ hook.Add( "PersistenceSave", "PersistenceSave", function( name )
local PersistPage = ( name or GetConVarString( "sbox_persist" ) ):Trim()
if ( PersistPage == "" ) then return end

local Ents = ents.GetAll()
local Ents = {}

for k, v in ipairs( Ents ) do
for _, v in ents.Iterator() do

if ( !v:GetPersistent() ) then
Ents[ k ] = nil
if ( v:GetPersistent() ) then
table.insert( Ents, v )
end

end
Expand Down
2 changes: 1 addition & 1 deletion garrysmod/lua/autorun/properties/drive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ properties.Add( "drive", {
if ( ent:GetClass() == "prop_vehicle_jeep" || ent:GetClass() == "prop_vehicle_jeep_old" ) then return false end

-- Make sure nobody else is driving this or we can get into really invalid states
for id, pl in ipairs( player.GetAll() ) do
for _, pl in player.Iterator() do
if ( pl:GetDrivingEntity() == ent ) then return false end
end

Expand Down
30 changes: 14 additions & 16 deletions garrysmod/lua/includes/extensions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,19 @@ end

-- These are totally in the wrong place.
function player.GetByAccountID( ID )
local players = player.GetAll()
for i = 1, #players do
if ( players[i]:AccountID() == ID ) then
return players[i]
for _, pl in player.Iterator() do
if ( pl:AccountID() == ID ) then
return pl
end
end

return false
end

function player.GetByUniqueID( ID )
local players = player.GetAll()
for i = 1, #players do
if ( players[i]:UniqueID() == ID ) then
return players[i]
for _, pl in player.Iterator() do
if ( pl:UniqueID() == ID ) then
return pl
end
end

Expand All @@ -286,10 +284,10 @@ end

function player.GetBySteamID( ID )
ID = string.upper( ID )
local players = player.GetAll()
for i = 1, #players do
if ( players[i]:SteamID() == ID ) then
return players[i]

for _, pl in player.Iterator() do
if ( pl:SteamID() == ID ) then
return pl
end
end

Expand All @@ -298,10 +296,10 @@ end

function player.GetBySteamID64( ID )
ID = tostring( ID )
local players = player.GetAll()
for i = 1, #players do
if ( players[i]:SteamID64() == ID ) then
return players[i]

for _, pl in player.Iterator() do
if ( pl:SteamID64() == ID ) then
return pl
end
end

Expand Down
8 changes: 4 additions & 4 deletions garrysmod/lua/includes/gmsave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ end

function gmsave.SaveMap( ply )

local Ents = ents.GetAll()
local Ents = {}

for k, v in ipairs( Ents ) do
for _, v in ents.Iterator() do

if ( !gmsave.ShouldSaveEntity( v, v:GetSaveTable() ) || v:IsConstraint() ) then
Ents[ k ] = nil
if ( gmsave.ShouldSaveEntity( v, v:GetSaveTable() ) && !v:IsConstraint() ) then
table.insert( Ents, v )
end

end
Expand Down
2 changes: 1 addition & 1 deletion garrysmod/lua/includes/modules/duplicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ end
--
function RemoveMapCreatedEntities()

for k, v in ipairs( ents.GetAll() ) do
for _, v in ents.Iterator() do

if ( v:CreatedByMap() and ShouldMapEntityBeRemoved( v, v:GetClass() ) ) then
v:Remove()
Expand Down
2 changes: 1 addition & 1 deletion garrysmod/lua/includes/modules/scripted_ents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Register( t, name )
end

-- Update entity table of entities that are based on this entity
for _, e in ipairs( ents.GetAll() ) do
for _, e in ents.Iterator() do
if ( IsBasedOn( e:GetClass(), name ) ) then

table.Merge( e, Get( e:GetClass() ) )
Expand Down
6 changes: 3 additions & 3 deletions garrysmod/lua/includes/modules/team.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ end
function TotalDeaths(index)

local score = 0
for id,pl in ipairs( player.GetAll() ) do
for _, pl in player.Iterator() do
if (pl:Team() == index) then
score = score + pl:Deaths()
end
Expand All @@ -117,7 +117,7 @@ end
function TotalFrags(index)

local score = 0
for id,pl in ipairs( player.GetAll() ) do
for _, pl in player.Iterator() do
if (pl:Team() == index) then
score = score + pl:Frags()
end
Expand All @@ -136,7 +136,7 @@ function GetPlayers(index)

local TeamPlayers = {}

for id,pl in ipairs( player.GetAll() ) do
for _, pl in player.Iterator() do
if (IsValid(pl) and pl:Team() == index) then
table.insert(TeamPlayers, pl)
end
Expand Down
2 changes: 1 addition & 1 deletion garrysmod/lua/includes/modules/weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Register( t, name )
if ( old != nil ) then

-- Update SWEP table of entities that are based on this SWEP
for _, e in ipairs( ents.GetAll() ) do
for _, e in ents.Iterator() do
local class = e:GetClass()

if ( class == name ) then
Expand Down