Extensions Entity
scripts/vscripts/alyxlib/extensions/entity.lua
Methods
GetChildrenMemSafe
Gets the entities parented to this entity. Including children of children.
This is a memory safe version of GetChildren which causes a memory leak when called. If you need to get children often you should use this function instead.
Returns
- EntityHandle[]
IterateChildren
Returns a function that iterates over all children of this entity.
The function returns the next child every time it is called until no more children exist,
in which case nil is returned.
Useful in for loops:
This function is memory safe.
Returns
- function
The new iterator function
IterateChildrenBreadthFirst
Returns a function that iterates over all children of this entity in breadth-first order.
The function returns the next child every time it is called until no more children exist,
in which case nil is returned.
Useful in for loops:
Unlike IterateChildren, this visits all immediate children first, then their children, and so on.
This function is memory safe.
Returns
- function
The new iterator function
GetTopChildren
Gets the top level entities parented to this entity. Not children of children.
This function is memory safe.
Returns
- EntityHandle[]
EntFire
Sends an input to this entity.
Parameters
action
string
Input namevalue(optional)
any
Parameter override for the inputdelay(optional)
number
Delay in secondsactivator(optional)
EntityHandle
IO activatorcaller(optional)
EntityHandle
IO caller
GetFirstChildWithClassname
Gets the first child in this entity's hierarchy with a given classname.
Searches using breadth-first traversal, so it finds the closest matching child first.
This function is memory safe.
Parameters
classname
string
Classname to search for
Returns
- EntityHandle?
The first matching child found, or nil if none exists
GetFirstChildWithName
Get the first child in this entity's hierarchy with a given name.
Searches using breadth-first traversal, so it finds the closest matching child first.
This function is memory safe.
Parameters
name
string
Targetname to search for
Returns
- EntityHandle?
The first matching child found, or nil if none exists
SetQAngle
Sets entity pitch, yaw, roll from a QAngle.
Parameters
qangle
QAngle
The QAngle rotation to set
SetLocalQAngle
Sets entity local pitch, yaw, roll from a QAngle.
Parameters
qangle
QAngle
The QAngle rotation to set
SetAngle
Sets entity pitch, yaw or roll. Supply nil for any parameter to leave it unchanged.
Parameters
pitch(optional)
number
Pitch angleyaw(optional)
number
Yaw angleroll(optional)
number
Roll angle
ResetLocal
Resets local origin and angles to (0, 0, 0).
GetSize
Gets the bounding size of the entity.
Returns
- Vector
Bounding size of the entity as a Vector
GetBiggestBounding
Gets the biggest bounding box axis of the entity.
This will be either size.x, size.y or size.z.
Returns
- number
The largest bounding value
GetRadius
Gets the radius of the entity's bounding box. This is half the size of the bounding box along its largest axis.
Returns
- number
The bounding radius value
GetVolume
Gets the volume of the entity bounds in cubic inches.
Returns
- number
The volume of the entity bounds
GetBoundingCorners
Gets each corner of the entity's bounding box.
Parameters
rotated(optional)
boolean
Iftrue, corners are rotated by the entity's angles
Returns
- Vector[]
List of 8 corner positions
IsWithinBounds
Checks if entity is within the given worldspace bounds.
Parameters
mins
Vector
Worldspace minimum vector for the boundsmaxs
Vector
Worldspace maximum vector for the boundscheckEntityBounds(optional)
boolean
Iftruethe entity bounding box will be used for the check instead of its origin
Returns
- boolean
true if the entity is within the bounds, false otherwise.
DisablePickup
Sends the DisablePickup input to the entity.
EnablePickup
Sends the EnablePickup input to the entity.
Delay
Delays some code, using this entity as the context.
Parameters
func
function
The function to delaydelay(optional)
number
Delay in seconds (default 0)
GetParents
Gets all parents in the hierarchy upwards, from immediate parent up to the root.
Returns
- EntityHandle[]
List of parent entities
DoNotDrop
Sets if the prop is not allowed to be dropped. Only works for physics based props.
Parameters
enabled
boolean
trueif the prop is not allowed to be dropped
GetCriteria
Gets all criteria for this entity as a table.
Returns
- CriteriaTable
Criteria key-value pairs
GetOwnedEntities
Gets all entities owned by this entity.
Note: This searches all entities in the map and should be used sparingly.
Returns
- EntityHandle[]
List of owned entities
SetRenderAlphaAll
Sets the alpha modulation of this entity, plus any children that support SetRenderAlpha.
Parameters
alpha
integer
Alpha value (0 = fully transparent, 255 = fully opaque)
SetCenter
Moves the entity so that its center is at the given position.
Parameters
position
Vector
The new center position
SetOriginByAttachment
Sets the entity's origin so that the specified attachment point aligns with the given world position.
Parameters
position
Vector
The target world position for the attachment pointattachment
string
The name of the attachment point to align
TrackProperty
Tracks a property function and calls a callback when a change is detected.
-- Make entity fully opaque if alpha is ever detected below 255
thisEntity:TrackProperty(thisEntity.GetRenderAlpha, function(prevValue, newValue) if newValue < 255 then thisEntity:SetRenderAlpha(255) end end)
Parameters
propertyFunction
function
Property function to trackonChangeFunction
function
Function to call when a change is detectedinterval(optional)
number
Think interval (default: 0)context(optional)
EntityHandle
Entity to run the thinker on, or the calling entity ifnil
Returns
- string
The name of the think for stopping later
UntrackProperty
Untracks a property function which was set to be tracked using TrackProperty.
Parameters
propertyFunction
function
Property function to untrack
QuickThink
Quickly starts a think function on the entity with a random name.
Parameters
func
function
The think functiondelay(optional)
number
Delay before starting the think (default: 0)
Returns
- string
The name of the think for stopping later if desired
SetRenderingEnabled
Sets whether the entity is rendered or not.
Parameters
renderingEnabled
boolean
trueto enable rendering,falseto disable
SetCastShadow
Sets whether the entity casts a shadow or not.
Parameters
shadowEnabled
boolean
trueto enable shadow casting,falseto disable
DistanceFromEyes
Gets the position in front of the entity’s eyes at the specified distance.
Parameters
distance
number
How far in front of the eyes
Returns
- Vector
The world position in front of the eyes
GetAttachmentNameOrigin
Gets the world origin position of a named attachment point.
Parameters
name
string
The name of the attachment
Returns
- Vector
The world position of the attachment
GetAttachmentNameAngles
Gets the world angles (rotation) of a named attachment point.
Parameters
name
string
The name of the attachment
Returns
- Vector
The world rotation angles of the attachment
GetAttachmentNameForward
Gets the forward direction vector of a named attachment.
Parameters
name
string
The name of the attachment
Returns
- Vector
The forward unit vector of the attachment in world space
ClearParent
Unparents this entity if it is parented.
SetAbsVelocity
Sets the absolute world velocity of the entity.
Parameters
velocity
Vector
The target velocity in units/second
OBBvsOBB
Tests if the OBB of this entity intersects with the OBB of another entity.
Parameters
other
EntityHandle
The other entity
Returns
- boolean
true if the OBB of this entity intersects with the OBB of the other entity
AABBvsOBB
Tests if the AABB of this entity intersects with the OBB of another entity.
The AABB is defined by the entity's bounding mins/maxs and its current origin/angles.
Parameters
other
EntityHandle
The other entity
Returns
- boolean
true if the AABB of this entity intersects with the OBB of the other entity
AABBvsAABB
Tests if the AABB of this entity intersects with the AABB of another entity.
The AABB is defined by the entity's bounding mins/maxs and its current origin/angles.
Parameters
other
EntityHandle
The other entity
Returns
- boolean
true if the AABB of this entity intersects with the AABB of the other entity