👾Entity

Table to work with CEntity.

CEntity is base class for all entities in the game e.g. CNPC, Hero, CPlayer, CAbility

IsEntity(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is in entity list. Search in unordered set.


IsNPC(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is in NPC list. Search in unordered set.


IsHero(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is in hero list. Search in unordered set.


IsPlayer(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is in player list. Search in unordered set.


IsAbility(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is in ability list. Search in unordered set. Item is ability.


Get(index: integer): CEntity|nil

Not the same as Entities.Get(index). See example.

Name
Type
Description

index

integer

Returns entity by game index.

Example

-- get_by_index.lua
local hero = Heroes.GetLocal();
local index = Entity.GetIndex(hero);
local entity_by_index = Entity.Get(index);
assert(hero == entity_by_index, "Entity.Get() is broken!"); -- true

GetIndex(entity: CEntity): integer

Name
Type
Description

entity

Returns game index of entity.


GetClassName(entity: CEntity): string

Name
Type
Description

entity

Returns the entity's class name.


GetUnitName(entity: CEntity): string

Name
Type
Description

entity

Returns the entity's name.


GetUnitDesignerName(entity: CEntity): string

Name
Type
Description

entity

Returns the entity's designerName field.


GetTeamNum(entity: CEntity): Enum.TeamNum

Name
Type
Description

entity

Returns the entity's team number.


IsSameTeam(entity1: CEntity, entity2: CEntity): boolean

Name
Type
Description

entity1

entity2

Returns true if the entities are in the same team.


GetAbsOrigin(entity: CEntity): Vector

Name
Type
Description

entity

Returns the entity's position.


GetRotation(entity: CEntity): Angle

Name
Type
Description

entity

Returns the entity's rotation.

Example

-- forward_pos.lua
return {
    -- get local hero's forward position and draw a circle around it
    OnUpdate = function ()
        local hero = Heroes.GetLocal();
        local rotation = Entity.GetRotation(hero);
        -- forward_direction is a vector that points 100 units in direction of my hero's rotation
        local forward_direction = rotation:GetForward():Normalized():Scaled(100);
        -- add forward_direction to my hero's position to get the forward position
        local forward_pos = Entity.GetAbsOrigin(hero) + forward_direction;
        -- screen_x and screen_y are the coordinates of forward_pos on the screen
        local screen_x, screen_y, is_on_screen = Renderer.WorldToScreen(forward_pos);
        if is_on_screen then
            -- draw a circle around the position
            Renderer.SetDrawColor(255, 255, 255, 255);
            Renderer.DrawFilledCircle(screen_x, screen_y, 10, 10);
            -- result: https://i.imgur.com/ERf1Pxk.png
        end
    end
}

IsAlive(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is alive.


IsDormant(entity: CEntity): boolean

Name
Type
Description

entity

Returns true if the entity is not visible to the local player.


GetHealth(entity: CEntity): integer

Name
Type
Description

entity

Returns the entity's health.


GetMaxHealth(entity: CEntity): integer

Name
Type
Description

entity

Returns the entity's max health.


GetOwner(entity: CEntity): CEntity|nil

Name
Type
Description

entity

Returns the entity's owner or nil if the entity has no owner.\ e.g. for CPlayer -> npc_dota_hero_ember_spirit -> npc_dota_hero_ember_spirit_fire_remnant ownership chain Entity.GetOwner(remnant) will return Ember Spirit's entity.


OwnedBy(entity: CEntity, owner: CEntity): boolean

Name
Type
Description

entity

- entity to check

owner

- owner for comparison

Returns true if the entity is owned by another entity-owner. It will check the first owner only.


RecursiveGetOwner(entity: CEntity): CEntity|nil

Name
Type
Description

entity

Returns the entity's last owner.\ e.g. for CPlayer -> npc_dota_hero_ember_spirit -> npc_dota_hero_ember_spirit_fire_remnant ownership chain Entity.GetOwner(remnant) will return CPlayer.


RecursiveOwnedBy(entity: CEntity, owner: CEntity): boolean

Name
Type
Description

entity

entity to check

owner

owner for comparison

Returns true if the entity is owned by another entity-owner. It will check the whole ownership chain.


GetHeroesInRadius(entity: CEntity, radius: number, teamType [?]: Enum.TeamType, skipIllusions [?]: boolean): CHero[]

Name
Type
Description

entity

entity to get position

radius

number

radius to search around

teamType [?]

relative to the entity (default: TEAM_ENEMY)

skipIllusions [?]

boolean

true if you want to get table without illusions (default: true)

Returns an array of all alive and visible heroes in radius of the entity. Exclude illusion.

Example

local hero = Heroes.GetLocal()
-- get all enemy heroes in 1200 radius
local heroes_around = Entity.GetHeroesInRadius(hero, 1200)
for i = 1, #heroes_around do
	local hero = heroes_around[i];
	Log.Write(NPC.GetUnitName(hero) .. " is near!");
end

GetUnitsInRadius(entity: CEntity, radius: number, teamType [?]: Enum.TeamType, skipIllusions [?]: boolean): CNPC[]

Name
Type
Description

entity

entity to get position

radius

number

radius to search around

teamType [?]

relative to the entity (default: TEAM_ENEMY)

skipIllusions [?]

boolean

true if you want to get table without illusions (default: true)

Returns an array of all alive and visible NPCs in radius of the entity.

Example

local hero = Heroes.GetLocal()
-- get all ally NPCs in 1200 radius
local units_around = Entity.GetUnitsInRadius(hero, 1200, Enum.TeamType.TEAM_FRIEND)
for i = 1, #units_around do
	local unit = units_around[i];
	Log.Write(NPC.GetUnitName(unit) .. " is near!");
end

GetTreesInRadius(entity: CEntity, radius: number, active [?]: boolean): CTree[]

Active means that tree is not destroyed.

Name
Type
Description

entity

entity to get position

radius

number

radius to search around

active [?]

boolean

true if you want to get table with active trees only, otherwise for inactive trees (default: true)

Returns an array of all not temporary trees in radius of the entity.

Example

local hero = Heroes.GetLocal()
-- get all trees in 400 radius
local trees_around = Entity.GetTreesInRadius(hero, 400, true)
for i = 1, #trees_around do
	local tree = trees_around[i];
	Log.Write(Entity.GetClassName(tree) .. " is near!");
end

GetTempTreesInRadius(entity: CEntity, radius: number): CTree[]

Temporary trees are trees planted by abilities or items.

Name
Type
Description

entity

entity to get position

radius

number

radius to search around

Returns an array of all temporary trees in radius of the entity.

Example

local hero = Heroes.GetLocal()
-- get all trees in 400 radius
local trees_around = Entity.GetTempTreesInRadius(hero, 400)
for i = 1, #trees_around do
	local tree = trees_around[i];
	Log.Write(Entity.GetClassName(tree) .. " is near!");
end

IsControllableByPlayer(entity: CEntity, playerId: integer): boolean

Name
Type
Description

entity

entity to check

playerId

integer

player id

Returns true if entity is controllable by player.


GetForwardPosition(entity: CEntity, distance: number): Vector

Name
Type
Description

entity

entity to get position

distance

number

distance to move forward

Returns position in front of entity or (0,0,0) if entity is invalid.


GetClassID(entity: CEntity): integer

Name
Type
Description

entity

entity to get class id

Returns entity class id. Could be as a optimized way to check entity type.


GetField(entity: CEntity, fieldName: string, dbgPrint: boolean): any

Name
Type
Description

entity

entity to get field from

fieldName

string

field name

dbgPrint

boolean

print possible errors

Returns value of the field.

Last updated