🎭NPC

Table to work with CNPC.

CNPC extends CEntity

GetOwnerNPC(npc: CNPC): CNPC|nil

Name
Type
Description

npc

npc to get owner from

Returns owner of the CNPC. Works for spirit bear.


GetItem(npc: CNPC, name: string, isReal [?]: boolean): CItem|nil

Name
Type
Description

npc

npc to get item from

name

string

name of the item

isReal [?]

boolean

if true, returns only 1-6 slots and neutral item, otherwise returns all items (including backpack and stash) (default: true)

Returns CItem by name.


HasItem(npc: CNPC, name: string, isReal [?]: boolean): boolean

Name
Type
Description

npc

npc to check

name

string

name of the item

isReal [?]

boolean

if true, returns only 1-6 slots and neutral item, otherwise returns all items (including backpack and stash) (default: true)

Returns true if the CNPC has item with specified name.


HasModifier(npc: CNPC, name: string): boolean

Name
Type
Description

npc

npc to check

name

string

name of the modifier

Returns true if the CNPC has modifier with specified name.


GetModifier(npc: CNPC, name: string): CModifier|nil

Name
Type
Description

npc

npc to get modifier from

name

string

name of the modifier

Returns CModifier by name.


GetModifiers(npc: CNPC, poperty_filter [?]: Enum.ModifierFunction): CModifier[]

`poperty_filter` doesn`t filter all modifiers every call, it uses already prefiltered list.

Name
Type
Description

npc

npc to get modifiers from

poperty_filter [?]

Filter modifiers by specified property (default: Enum.ModifierFunction.MODIFIER_FUNCTION_INVALID)

Returns an array of all NPC's CModifiers.


HasInventorySlotFree(npc: CNPC, isReal [?]: boolean): boolean

Name
Type
Description

npc

npc to check

isReal [?]

boolean

if true, returns only 1-6 slots and neutral item, otherwise returns all items (including backpack and stash) (default: true)

Returns true if the CNPC has free inventory slot.


HasState(npc: CNPC, state: Enum.ModifierState): boolean

Name
Type
Description

npc

npc to check

state

state to check

Returns true if the CNPC has state. The best way to check if the CNPC is stunned, silenced, hexed, has BKB immune etc.


IsWaitingToSpawn(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if waiting to spawn. For example, creeps are waiting to spawn under the ground near the barracks.


IsIllusion(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is illusion.


IsVisible(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is visible to local player.


IsVisibleToEnemies(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is visible enemies.


IsCourier(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a courier.


IsRanged(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a ranged unit.


IsCreep(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a creep.


IsLaneCreep(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a lane creep.


IsStructure(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a structure.


IsTower(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a tower.


GetUnitType(npc: CNPC): Enum.UnitTypeFlags

Name
Type
Description

npc

npc to check

Returns unit type flags.


IsConsideredHero(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if it is unit a considered a hero for targeting purposes.


IsBarracks(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a barracks.


IsAncient(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is an ancient creeps.


IsRoshan(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a Roshan.


IsNeutral(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a neutral. Neutral creeps, ancient creeps.


IsHero(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a hero.


IsWard(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a ward.


IsMeepoClone(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is a meepo clone.


IsEntityInRange(npc: CNPC, npc2: CNPC, range: number): boolean

Name
Type
Description

npc

npc to check

npc2

npc to check

range

number

range to check

Returns true if the CNPC in range of other CNPC.


IsPositionInRange(npc: CNPC, pos: Vector, range: number, hull [?]: number): boolean

Name
Type
Description

npc

npc to check

pos

position to check

range

number

range to check

hull [?]

number

hull just added to range (default: 0.0)

Returns true if the CNPC in range of position.


IsLinkensProtected(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is protected by Linkens Sphere.


IsMirrorProtected(npc: CNPC): boolean

Name
Type
Description

npc

npc to check

Returns true if the CNPC is protected by Mirror Shield.


IsChannellingAbility(npc: CNPC): boolean

Do not work for items.

Name
Type
Description

npc

npc to check

Returns true if the CNPC is channeling ability. Black Hole, Life Drain, etc.


GetChannellingAbility(npc: CNPC): CAbility|nil

Name
Type
Description

npc

target npc

Returns the currently channelling CAbility.


IsRunning(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC is running.


IsAttacking(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC is attacking.


IsSilenced(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC is silenced.


IsStunned(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC is stunned.


HasAegis(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC has aegis.


IsKillable(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC has killable. Example: false if affected by Eul.


GetActivity(npc: CNPC): Enum.GameActivity

Name
Type
Description

npc

target npc

Returns the CNPC activity, such as running, attacking, casting, etc.


GetAnimationInfo(npc: CNPC): {sequence:integer, cycle:number, name:string, mdl_name:string}

Name
Type
Description

npc

target npc

Returns information about the current animation of the CNPC.


GetAttackRange(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the base attack range of the CNPC.


GetAttackRangeBonus(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the bonus attack range of the CNPC.


GetCastRangeBonus(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the bonus cast range of the CNPC.


GetPhysicalArmorValue(npc: CNPC, excludeWhiteArmor [?]: boolean): number

Name
Type
Description

npc

target npc

excludeWhiteArmor [?]

boolean

exclude white armor (default: true)

Returns the physical armor value of the CNPC.


GetPhysicalDamageReduction(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the physical damage reduction value of the CNPC.


GetArmorDamageMultiplier(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the physical damage multiplier value of the CNPC.


GetMagicalArmorValue(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the magical armor value of the CNPC.


GetMagicalArmorDamageMultiplier(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the magical damage multiplier value of the CNPC.


GetIncreasedAttackSpeed(npc: CNPC, ignore_temp_attack_speed [?]: boolean): number

Name
Type
Description

npc

target npc

ignore_temp_attack_speed [?]

boolean

ignore temporary attack speed (default: false)

Returns increased attack speed of the CNPC.


GetAttacksPerSecond(npc: CNPC, ignore_temp_attack_speed [?]: boolean): number

Name
Type
Description

npc

target npc

ignore_temp_attack_speed [?]

boolean

ignore temporary attack speed (default: false)

Returns the number of attacks per second that the CNPC can deal.


GetAttackTime(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the amount of time needed for the CNPC to perform an attack.


GetAttackSpeed(npc: CNPC, ignore_temp_attack_speed [?]: boolean): number

Name
Type
Description

npc

target npc

ignore_temp_attack_speed [?]

boolean

ignore temporary attack speed (default: false)

Returns the attack speed of the CNPC.


GetBaseAttackSpeed(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the base attack speed of the CNPC.


GetHullRadius(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the model interaction radius of the CNPC.


GetPaddedCollisionRadius(npc: NPC): number

Name
Type
Description

npc

NPC

target npc

Returns the collision hull radius (including padding) of this NPC.


GetProjectileCollisionSize(npc: CNPC): number

see: https://dota2.fandom.com/wiki/Unit_Size#Collision_Size

Name
Type
Description

npc

target npc

Returns the collision size of the CNPC. Collision size is the internal size that prevents other units from passing through.


GetTurnRate(npc: CNPC): number

see: https://dota2.fandom.com/wiki/Turn_rate

Name
Type
Description

npc

target npc

Returns the turn rate, which is the speed at which the CNPC can turn.


GetAttackAnimPoint(npc: CNPC): number

see: https://dota2.fandom.com/wiki/Attack_animation

Name
Type
Description

npc

target npc

Returns the attack animation point, nil if not found.


GetAttackProjectileSpeed(npc: CNPC): integer

see: https://dota2.fandom.com/wiki/Projectile_Speed

Name
Type
Description

npc

target npc

Returns the attack projectile speed, nil if not found.


IsTurning(npc: CNPC): boolean

Name
Type
Description

npc

target npc

Returns true if the CNPC is turning.


GetAngleDiff(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the remaining degree angle needed to complete the turn of the CNPC.


GetPhysicalArmorMainValue(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the (main) white armor of the CNPC.


GetTimeToFace(npc: CNPC, npc: CNPC): number

Name
Type
Description

npc

source npc

npc

target npc

Returns the amount of time needed for the source CNPC to face the target CNPC.


FindRotationAngle(npc: CNPC, pos: Vector): number

Name
Type
Description

npc

source npc

pos

position to find the rotation angle

Returns the rotation angle of the CNPC.


GetTimeToFacePosition(npc: CNPC, pos: Vector): number

Name
Type
Description

npc

source npc

pos

target position

Returns the amount of time needed for the source CNPC to face a specific position.


FindFacingNPC(npc: CNPC, ignoreNpc: CNPC, team_type [?]: Enum.TeamType, angle [?]: number, distance [?]: number): CNPC|nil

Name
Type
Description

npc

source npc

ignoreNpc

ignore npc

team_type [?]

team type (default: TEAM_BOTH)

angle [?]

number

max angle to check (default: 0.0)

distance [?]

number

max distance to check (default: 0.0)

Returns the CNPC that the source CNPC is currently facing.


GetBaseSpeed(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the base move speed of the CNPC.


GetMoveSpeed(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the move speed of the CNPC.


GetMinDamage(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the minumum attack damage of the CNPC.


GetBonusDamage(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the bonus attack damage of the CNPC.


GetTrueDamage(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the minumum attack damage + bonus damage of the CNPC.


GetTrueMaximumDamage(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the maximum attack damage + bonus damage of the CNPC.


GetItemByIndex(npc: CNPC, index: integer): CItem|nil

Name
Type
Description

npc

target npc

index

integer

item index

Returns the CItem by index.


GetAbilityByIndex(npc: CNPC, index: integer): CAbility|nil

Name
Type
Description

npc

target npc

index

integer

ability index

Returns the CAbility by index.


GetAbilityByActivity(npc: CNPC, activity: Enum.GameActivity): CAbility|nil

Name
Type
Description

npc

npc to get ability from

activity

game activity

Returns the CAbility by game activity.


GetAbility(npc: CNPC, name: string): CAbility|nil

Name
Type
Description

npc

target npc

name

string

ability name

Returns the CAbility by name.


HasAbility(npc: CNPC, name: string): boolean

Name
Type
Description

npc

target npc

name

string

ability name

Returns true if the CNPC has this ability.


GetMana(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the current mana of the CNPC.


GetMaxMana(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the maximum mana of the CNPC.


GetManaRegen(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the mana regeneration rate of the CNPC.


GetHealthRegen(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the health regeneration rate of the CNPC.


GetCurrentLevel(npc: CNPC): number

Name
Type
Description

npc

target npc

Returns the current level of the CNPC.


GetDayTimeVisionRange(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the day-time vision range of the CNPC.


GetNightTimeVisionRange(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the night-time vision range of the CNPC.


GetUnitName(npc: CNPC): string

Name
Type
Description

npc

target npc

Returns the unit-name of the CNPC.


GetHealthBarOffset(npc: CNPC, checkOverride [?]: bool): integer

Name
Type
Description

npc

target npc

checkOverride [?]

bool

returns override offset if it exists (default: true)

Returns the health bar offset of the CNPC.


GetUnitNameIndex(npc: CNPC): integer

index can change when new unit are added

Name
Type
Description

npc

target npc

Returns unit-name index of the CNPC.


GetAttachment(npc: CNPC, name: string): Vector

Name
Type
Description

npc

target npc

name

string

attachment name. e.g. "attach_hitloc"

Returns the attachment position of the CNPC by the name.

Example

-- attachments.txt
attach_hitloc
attach_eye_r
attach_eye_l
attach_mouth
attach_totem
attach_head
attach_tidebringer
attach_tidebringer_2
attach_sword
attach_attack1
attach_weapon
attach_eyes
attach_prop_l
attach_prop_r
attach_light
attach_staff
attach_mouthbase
attach_mouthend
attach_mom_l
attach_mom_r
attach_attack2
attach_fuse
attach_mane
attach_tail
attach_upper_jaw
attach_weapon_core_fx
attach_bow_top
attach_bow_bottom
attach_bow_mid
attach_armor
attach_chimmney
attach_eyeR
attach_eyeL
attach_spine4
attach_spine5
attach_spine6
attach_spine7
attach_spine8
attach_spine9
attach_armlet_1
attach_armlet_2
attach_armlet_3
attach_armlet_4
attach_armlet_5
attach_vanguard_guard_1
attach_vanguard_guard_2
attach_weapon_offhand
attach_vanguard_1
attach_vanguard_2
attach_attack3
attach_attack4
attach_banner
attach_fx
attach_portcullis
attach_gem

GetAttachmentByIndex(npc: CNPC, index: integer): Vector

Name
Type
Description

npc

target npc

index

integer

attachment index

Returns the attachment position of the CNPC by the specified index.


GetAttachmentIndexByName(npc: CNPC, name: string): integer

Name
Type
Description

npc

target npc

name

string

attachment name. e.g. "attach_hitloc"

Returns the attachment index of the CNPC by the name.


GetBountyXP(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the amount of experience points (XP) you can earn for killing the CNPC.


GetGoldBountyMin(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the minimum amount gold you can earn for killing the CNPC.


GetGoldBountyMax(npc: CNPC): integer

Name
Type
Description

npc

target npc

Returns the maximum amount gold you can earn for killing the CNPC.


MoveTo(npc: CNPC, position: Vector, queue [?]: boolean, show [?]: boolean, callback [?]: boolean, executeFast [?]: boolean, identifier [?]: string): nil

Name
Type
Description

npc

The target NPC.

position

The destination position.

queue [?]

boolean

Add the order to the Dota queue. (default: false)

show [?]

boolean

Show the order position. (default: false)

callback [?]

boolean

Push the order to the OnPrepareUnitOrders callback. (default: false)

executeFast [?]

boolean

Place the order at the top of the queue. (default: false)

identifier [?]

string

The identifier which will be passed to OnPrepareUnitOrders callback. (default: nil)

Initiates an order for the CNPC to move to a specified position.


SetZDelta(npc: CNPC, z: number): nil

Name
Type
Description

npc

The target NPC.

z

number

Z pos

Sets the Z position of the CNPC model.


HasScepter(npc: CNPC): boolean

Name
Type
Description

npc

The target NPC.

Returns true if the CNPC has or consumed Aghanim Scepter.


HasShard(npc: CNPC): boolean

Name
Type
Description

npc

The target NPC.

Returns true if the CNPC has or consumed Aghanim Shard.


SequenceDuration(npc: CNPC, sequence: integer): number

Name
Type
Description

npc

The target NPC.

sequence

integer

The sequence index.

Returns sequence duration of the npc with the specified sequence index.


GetSecondsPerAttack(npc: CNPC, bIgnoreTempAttackSpeed: boolean): number

Name
Type
Description

npc

The target NPC.

bIgnoreTempAttackSpeed

boolean

Ignore temporary attack speed.

Returns the seconds per attack of the npc.


GetBarriers(npc: CNPC): {physical:{total:number, current:number}, magic:{total:number, current:number}, all:{total:number, current:number}}

Name
Type
Description

npc

The target NPC.

Returns a table with information about the barriers of the CNPC.


GetGlow(npc: CNPC): {m_bSuppressGlow:boolean, m_bFlashing:boolean, m_bGlowing:boolean, m_iGlowType:integer, r:integer, g:integer, b:integer}

Name
Type
Description

npc

The target NPC.

Returns a table with information about the current glow effect of the CNPC.


SetGlow(npc: CNPC, suppress_glow: boolean, flashing: boolean, glowing: boolean, glow_type: integer, r: integer, g: integer, b: integer): nil

Name
Type
Description

npc

The target NPC.

suppress_glow

boolean

suppress_glow

flashing

boolean

flashing

glowing

boolean

glowing

glow_type

integer

glow type

r

integer

r factor

g

integer

g factor

b

integer

b factor

Sets the CNPC glow effect.


SetColor(npc: CNPC, r: integer, g: integer, b: integer): nil

Name
Type
Description

npc

The target NPC.

r

integer

r factor

g

integer

g factor

b

integer

b factor

Sets the CNPC model color.


IsInRangeOfShop(npc: CNPC, npc: Enum.ShopType): boolean

Name
Type
Description

npc

The target NPC.

npc

The target NPC.

Checks if the CNPC is in range of a shop.


GetBaseSpellAmp(npc: CNPC): number

Name
Type
Description

npc

The target NPC.

Returns the base spell amplification of the CNPC.


GetModifierProperty(npc: CNPC, property: Enum.ModifierFunction): number

Name
Type
Description

npc

The target NPC.

property

Property enum.

Returns the property value for the CNPC.


IsControllableByPlayer(npc: CNPC, playerId: integer): boolean

Name
Type
Description

npc

npc to check

playerId

integer

player id

Returns true if npc is controllable by player.


GetModifierPropertyHighest(npc: CNPC, property: Enum.ModifierFunction): number

Fixes the issue when you have multiple Kaya items that actually don't stack.

Name
Type
Description

npc

The target NPC.

property

Property enum.

Returns the hieghest property value for the CNPC.

Last updated