Menu
Lumberyard
Developer Guide (Version 1.12)

EntityUtils Lua Functions

CryLua is deprecated and will be removed in a future version of Lumberyard.

This topic describes the commonly used Lua entity utility functions.

  • File location: Game/Scripts/Utils/EntityUtils.lua

  • Loaded from: Game/Scripts/common.lua

DumpEntities()

Dumps to console all entity IDs, names, classes, positions, and angles that are currently used in a map. For example:

Copy
[userdata: 00000002]..name=Grunt1 clsid=Grunt pos=1016.755,1042.764,100.000 ang=0.000,0.000,1.500 [userdata: 00000003]..name=Grunt2 clsid=Grunt pos=1020.755,1072.784,100.000 ang=0.000,0.000,0.500 ...

CompareEntitiesByName()

Compares two entities identified by name. This function is commonly used when sorting tables.

Parameter Description
ent1 Name of first entity table.
ent2 Name of second entity table.

Example

Copy
local entities = System.GetEntitiesByClass("SomeEntityClass") table.sort(entities, CompareEntitiesByName)

CompareEntitiesByDistanceFromPoint()

Compares the distance of two entities from a specified point. If the distance is greater for Entity 1 than for Entity 2 (that is, Entity 1 is further away), this function returns TRUE, otherwise it returns FALSE.

Parameter Description
ent1 Entity 1 table
ent2 Entity 2 table
point 3D position vector identifying the point to measure distance to.

Example

Copy
local ent1 = System.GetEntityByName("NameEntityOne") local ent2 = System.GetEntityByName("NameEntityTwo") if(CompareEntitiesByDistanceFromPoint( ent1, ent2, g_localActor:GetPos()))then Log("Entity One is further away from the Player than Entity two...") end

BroadcastEvent()

Processes an entity event broadcast.

Parameter Description
sender Entity that sent the event.
event String based entity event to process.

Example

Copy
BroadcastEvent(self, "Used")

MakeDerivedEntity()

Creates a new table that is a derived version of a parent entity table. This function is commonly used to simplify the creation of a new entity script based on another entity.

Parameter Description
_DerivedClass Derived class table.
_Parent Parent or base class table.

MakeDerivedEntityOverride()

Creates a new table that is a derived class of a parent entity. The derived table's properties will override those from the parent.

Parameter Description
_DerivedClass Derived class table.
_Parent Parent or base class table.

MakeUsable()

Adds usable functionality, such as an OnUsed event, to a specified entity.

Parameter Description
entity Entity table to make usable.

Example

Copy
MyEntity = { ... whatever you usually put here ... } MakeUsable(MyEntity) function MyEntity:OnSpawn() ... function MyEntity:OnReset() self:ResetOnUsed() ... end

MakePickable()

Adds basic "pickable" functionality to a specified entity. The bPickable property is added to the entity's properties table.

Parameter Description
entity Entity table to make pickable.

MakeSpawnable()

Adds spawn functionality to a specified entity. Commonly used for AI actors during creation.

Parameter Description
entity Entity table to make spawnable.

EntityCommon.PhysicalizeRigid()

Physicalizes an entity based on the specified entity slot and its physics properties.

Parameter Description
entity Entity table to physicalize.
nSlot Entity slot to physicalize.
Properties Physics properties table
bActive Not used.