Lua:Collection
|
Collection()
A collection is a list of entities you can use to keep track of game objects. For example, you could keep a list of all players, or of all players touching a trigger, or all sentries belonging to blue team.
Functions
AddItem
collection:AddItem( entity ) Adds the entity to the collection
Returns: nothing
- entity(CBaseEntity) An entity
Code:
local col = Collection() trigger_name = trigger_ff_script:new() function trigger_name:ontouch( touch_entity ) col:AddItem( touch_entity ) end
collection:AddItem( TableOfEntities ) Adds each entity in the table to the collection
Returns: nothing
- TableOfEntities(table) Entities separated by commas enclosed in { }
Code:
local col = Collection() trigger_name = trigger_ff_script:new() function trigger_name:ontouch( touch_entity ) col:AddItem( { touch_entity, GetEntityByName( "entity_name" ) } ) end
RemoveItem
collection:RemoveItem( entity ) Removes the entity from the collection
Returns: nothing
- entity(CBaseEntity) An entity
Code:
local col = Collection() trigger_name = trigger_ff_script:new() function trigger_name:onendtouch( touch_entity ) col:RemoveItem( touch_entity ) end
collection:RemoveItem( TableOfEntities ) Removes each entity in the table from the collection
Returns: nothing
- TableOfEntities(table) Entities separated by commas enclosed in { }
Code:
local col = Collection() trigger_name = trigger_ff_script:new() function trigger_name:onendtouch( touch_entity ) col:RemoveItem( { touch_entity, GetEntityByName( "entity_name" ) } ) end
RemoveAllItems
collection:RemoveAllItems() Removes all items from the collection (clears the collection)
Returns: nothing
Code:
local col = Collection() trigger_name = trigger_ff_script:new() function trigger_name:oninactive() col:RemoveAllItems( ) end
IsEmpty
collection:IsEmpty() Verifies whether or not the collection is empty
Returns: boolean (true or false)
Code:
local col = Collection() if col:IsEmpty() then --do something end
Count
collection:Count() Gives the number of items in the collection
Returns: number of items (int)
Code:
local col = Collection() if col:Count() > 5 then --do something end
NumItems
collection:NumItems() Alias for collection:Count()
HasItem
collection:HasItem( entity ) Verifies whether or not the collection contains the entity
Returns: boolean (true or false)
- entity(CBaseEntity) An entity
Code:
local col = Collection() if col:HasItem( GetEntityByName("entity_name") ) then -- do something end
collection:HasItem( TableOfEntities ) Verifies whether or not the collection contains at least one of the entities in the table
Returns: boolean (true or false)
- TableOfEntities(table) Entities separated by commas enclosed in { }
Code:
local col = Collection() if col:HasItem( { GetEntityByName("entity_name"), GetEntityByName("ent2") } ) then -- do something end
GetItem
collection:GetItem( entity ) Gives the entity you pass it if the entity is found in the collection. Entirely useless?
Returns: entity (CBaseEntity)
- entity(CBaseEntity) An entity
Code:
local col = Collection() local ent = col:GetItem( GetEntityByName("entity_name") )
collection:GetItem( TableOfEntities ) Gives the first item from the table found in the collection. Entirely useless?
Returns: entity (CBaseEntity)
- TableOfEntities(table) Entities separated by commas enclosed in { }
Code:
local col = Collection() local ent = col:GetItem( { GetEntityByName("entity_name"), GetEntityByName("ent2") } )
Element
collection:Element( number ) Gives the corresponding item from the collection
Returns: entity (CBaseEntity)
- number(integer) The number of the element you want to get, with the first element being at position 0
Code:
local col = Collection() -- get the first element of the collection local ent = col:Element( 0 )
GetByName
collection:GetByName( TableOfEntityNames ) Searches for entities with the inputted names and adds them to the collection
Returns: nothing
- TableOfEntityNames(table) Strings separated by commas enclosed in { }
Code:
local col = Collection() col:GetByName( { "entity_name", "ent2" } )
collection:GetByName( TableOfEntityNames, TableOfFilters ) Searches for entities that match the filters with the inputted names and adds them to the collection
Returns: nothing
- TableOfEntityNames(table) Strings separated by commas enclosed in { }
- TableOfFilters(table) Filter flags separated by commas enclosed in { }. See flag prefix: CF
Code:
local col = Collection() col:GetByName( { "entity_name", "ent2" }, { CF.kInfoScipts, CF.kInfoScript_Carried } )
GetInSphere
collection:GetInSphere( entity, radius, TableOfFilters ) Detects any entities that match the filters within distance from the origin of the entity and adds them to the collection
IMPORTANT: The filter CF.kTraceBlockWalls is REQUIRED for this function to work
Returns: nothing
- entity(CBaseEntity) An entity
- radius(float) Radius around the entity to check
- TableOfFilters(table) Filter flags separated by commas enclosed in { }. See flag prefix: CF
Code:
local col = Collection() col:GetInSphere( GetEntityByName("entity_name"), 256, { CF.kTraceBlockWalls } )
collection:GetInSphere( origin, radius, TableOfFilters ) Detects any entities that match the filters within distance from the origin and adds them to the collection
IMPORTANT: The filter CF.kTraceBlockWalls is REQUIRED for this function to work
Returns: nothing
- origin(Vector) Origin of the check
- radius(float) Radius around the entity to check
- TableOfFilters(table) Filter flags separated by commas enclosed in { }. See flag prefix: CF
Code:
local col = Collection() local origin = GetEntityByName("entity_name"):GetOrigin() -- check for entities within a 128 unit radius 256 units above the entity and add them to the collection col:GetInSphere( Vector(origin.x, origin.y, origin.z + 256), 128, { CF.kTraceBlockWalls } )
GetByFilter
collection:GetByFilter( TableOfFilters ) Finds any entities that match the filter(s) and adds them to the collection
Returns: nothing
- TableOfFilters(table) Filter flags separated by commas enclosed in { }. See flag prefix: CF
Code:
local col = Collection() -- get all blue snipers col:GetByFilter( { CF.kPlayers, CF.kPlayerSniper, CF.kTeamBlue } )