Skip to content

GetHeroesList()

GetHeroesList(): Hero[]

CAUTION

Do not modify the returned array. It is a reference to the internal array.

WARNING

This array will also contain any copies and illusions of heroes (Monkey King's ult, Naga Siren's illusions, and other entities). If you need only original heroes, don't forget to add checks with IsMeepoClone and IsIllusion functions

IMPORTANT

If a hero has never been seen once during the game, he will not be in this array.

Description

The GetHeroesList function retrieves a list of all hero entities.

Returned

  • Hero[] - array of all hero entities.

Example

ts
let exampleScript: ScriptDescription = {};

exampleScript.OnScriptLoad = () => {
	// Check if we are in the game, because otherwise the list of hero will be empty
	if(!GameRules.IsActiveGame()) {
		return;
	}

	let heroes = EntitySystem.GetHeroesList();
	for(let hero of heroes) {
		// Display the name of each hero
		console.log(hero.GetUnitName());
	}
}

RegisterScript(exampleScript, "Example script");