Skip to content
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
14 changes: 12 additions & 2 deletions lua/ulx/modules/sh/cfc_arrest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ local cmd = CFCUlxCommands.arrest

CATEGORY_NAME = "Cleanup"

local function isTargetPlayer( ply, targetPlayers )
for _, p in pairs( targetPlayers ) do
if p == ply then
return true
end
end

return false
end

function cmd.arrest( callingPlayer, targetPlayers )
local entities = ents.GetAll()
local entCount = 0
local entCounts = {}

for _, ent in ipairs( entities ) do
local owner = ent.CPPIGetOwner and ent:CPPIGetOwner()
if owner and entCounts[owner] then
if owner and isTargetPlayer( owner ) then
Comment on lines +6 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead we could make a lookup table first, which would only loop through the players once

function cmd.arrest( callingPlayer, targetPlayers )
    local entities = ents.GetAll()
    local entCount = 0
    local entCounts = {}

    local targetLookup= {}
    for _, ply in ipairs( targetPlayers ) do
        targetLookup[ply] = true
    end

    for _, ent in ipairs( entities ) do
        local owner = ent.CPPIGetOwner and ent:CPPIGetOwner() or ent:GetOwner()
        if owner and targetLookup[owner] then

if ent:GetClass() == "gmod_wire_expression2" then
ent:PCallHook( "destruct" )
ent:ResetContext()
Expand All @@ -19,7 +29,7 @@ function cmd.arrest( callingPlayer, targetPlayers )
end

if ent:GetClass() == "starfall_processor" then
ent:Error( SF.MakeError( ent.name .. ": Halted by ULX", 1, true, true) )
ent:Error( SF.MakeError( ent.name .. ": Halted by ULX", 1, true, true ) )
end

local canFreeze = not ( ent:IsWeapon() or ent:GetUnFreezable() or ent:IsPlayer() )
Expand Down