constraint/GetAllConstrainedEntities

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Func |Name=GetAllConstrainedEntities |Parent=constraint |Description=Returns a table of all entities recursively constrained to an entitiy. |Realm=Server |IsClass=No }...")
 
m (Add "view source" link)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=GetAllConstrainedEntities
 
|Parent=constraint
 
 
|Description=Returns a table of all entities recursively constrained to an entitiy.
 
|Description=Returns a table of all entities recursively constrained to an entitiy.
 
|Realm=Server
 
|Realm=Server
 
|IsClass=No
 
|IsClass=No
 +
|Name=GetAllConstrainedEntities
 +
|Parent=constraint
 +
|File=lua/includes/modules/constraint.lua
 +
|Line=1620
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 10: Line 12:
 
|name=ent
 
|name=ent
 
|desc=The entity to check
 
|desc=The entity to check
 +
}}
 +
{{Arg
 +
|type=table
 +
|name=ResultTable
 +
|desc=Table used to return result. Optional.
 +
|default=nil
 
}}
 
}}
 
{{Ret
 
{{Ret
 
|type=table
 
|type=table
|desc= ents
+
|desc=A table containing all of the constrained entities. This includes all entities constrained to entities constrained to the supplied entity, etc.
 
}}
 
}}
 
{{Example
 
{{Example
| Description = Adapted from stools/remover.lua
+
|Description=Adapted from stools/remover.lua
| Code = -- Remove this entity and everything constrained
+
|Code=-- Remove this entity and everything constrained
 
function TOOL:RightClick( trace )
 
function TOOL:RightClick( trace )
if ( !IsValid( trace.Entity ) or trace.Entity:IsPlayer() ) then return false end
+
if ( !IsValid( trace.Entity ) or trace.Entity:IsPlayer() ) then return false end
-- Loop through all the entities in the system
+
-- Loop through all the entities in the system
for _, Entity in pairs( constraint.GetAllConstrainedEntities( trace.Entity ) ) do
+
for _, Entity in pairs( constraint.GetAllConstrainedEntities( trace.Entity ) ) do
DoRemoveEntity( Entity )
+
DoRemoveEntity( Entity )
end
+
end
return true
+
return true
 
end
 
end
 
}}
 
}}

Latest revision as of 13:47, 10 April 2017

 constraint.GetAllConstrainedEntities( )

Contents

Description

Returns a table of all entities recursively constrained to an entitiy.

Arguments

Entity ent

The entity to check

Arguments

table ResultTable=nil

Table used to return result. Optional.

Returns

table

A table containing all of the constrained entities. This includes all entities constrained to entities constrained to the supplied entity, etc.

Examples

Example

Adapted from stools/remover.lua

-- Remove this entity and everything constrained
function TOOL:RightClick( trace )
	if ( !IsValid( trace.Entity ) or trace.Entity:IsPlayer() ) then return false end
	-- Loop through all the entities in the system
	for _, Entity in pairs( constraint.GetAllConstrainedEntities( trace.Entity ) ) do
		DoRemoveEntity( Entity )
	end
	return true
end


Personal tools
Navigation