mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 21:53:46 +03:00
Upload
This commit is contained in:
58
lua/includes/extensions/ents.lua
Normal file
58
lua/includes/extensions/ents.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
function ents.FindByClassAndParent( classname, entity )
|
||||
|
||||
if ( !IsValid( entity ) ) then return end
|
||||
|
||||
local list = ents.FindByClass( classname )
|
||||
if ( !list ) then return end
|
||||
|
||||
local out = {}
|
||||
for k, v in ipairs( list ) do
|
||||
|
||||
if ( !IsValid(v) ) then continue end
|
||||
|
||||
local p = v:GetParent()
|
||||
if ( !IsValid(p) ) then continue end
|
||||
if ( p != entity ) then continue end
|
||||
|
||||
table.insert( out, v )
|
||||
|
||||
end
|
||||
|
||||
if ( #out == 0 ) then return end
|
||||
|
||||
return out
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
local inext = ipairs({})
|
||||
local EntityCache = nil
|
||||
|
||||
function ents.Iterator()
|
||||
|
||||
if ( EntityCache == nil ) then EntityCache = ents.GetAll() end
|
||||
|
||||
return inext, EntityCache, 0
|
||||
|
||||
end
|
||||
|
||||
local function InvalidateEntityCache( ent )
|
||||
|
||||
EntityCache = nil
|
||||
|
||||
end
|
||||
|
||||
hook.Add( "OnEntityCreated", "ents.Iterator", InvalidateEntityCache )
|
||||
hook.Add( "EntityRemoved", "ents.Iterator", InvalidateEntityCache )
|
||||
Reference in New Issue
Block a user