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 player.Iterator() instead of player.GetAll() for optimization #11

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 3 additions & 4 deletions lua/autorun/sh_cami.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
]]

-- Version number in YearMonthDay format.
local version = 20211019
local version = 20240107

if CAMI and CAMI.Version >= version then return end

Expand Down Expand Up @@ -299,8 +299,7 @@ end
function CAMI.GetPlayersWithAccess(privilegeName, callback, targetPly,
extraInfoTbl)
local allowedPlys = {}
local allPlys = player.GetAll()
local countdown = #allPlys
local countdown = player.GetCount()

local function onResult(ply, hasAccess, _)
countdown = countdown - 1
Expand All @@ -309,7 +308,7 @@ extraInfoTbl)
if countdown == 0 then callback(allowedPlys) end
end

for _, ply in ipairs(allPlys) do
for _, ply in player.Iterator() do
CAMI.PlayerHasAccess(ply, privilegeName,
function(...) onResult(ply, ...) end,
targetPly, extraInfoTbl)
Expand Down