Table of Contents

Method FindNearestEnemies

Namespace
GrindFest
Assembly
GrindFest.dll

FindNearestEnemies(string, string, string, float, float)

Finds all hostile enemies within range that the hero can reach, sorted by distance.

public IReadOnlyList<MonsterBehaviour> FindNearestEnemies(string name1 = "", string name2 = null, string name3 = null, float maxDistance = 15, float howNear = 2)

Parameters

name1 string

Primary name to search for. Monster name must contain this string. If empty, matches any name.

name2 string

Optional secondary name to search for. If provided, monster name must contain either this or name1.

name3 string

Optional tertiary name to search for. If provided, monster name must contain either this, name2, or name1.

maxDistance float

Maximum search distance from the hero. Enemies beyond this range will be ignored.

howNear float

How close the hero needs to be able get to the enemy. Most melee attacks require you to stand at distance 2. Used for pathfinding checks.

Returns

IReadOnlyList<MonsterBehaviour>

A list of reachable enemies sorted by distance (nearest first), or empty list if no valid enemies are found.

Remarks

Similar to FindNearestEnemy(string, string, string, float, float) but returns all matching enemies instead of just the closest one. The method filters enemies based on several criteria:

  • Must be alive (not dead)
  • Must be within maxDistance
  • Must be hostile to the hero
  • Must be reachable via navigation system
  • Must match one of the provided name patterns if specified
Get all nearby enemies for context:
var enemies = FindNearestEnemies(maxDistance: 20);
if (enemies.Count > 0)
{
    var enemyNames = enemies.Select(e => e.name).ToArray();
    Say($"I see {enemies.Count} enemies: {string.Join(", ", enemyNames)}");
}
Find specific enemy types within range:
var skeletons = FindNearestEnemies("Skeleton", maxDistance: 15);
Say($"Found {skeletons.Count} skeletons nearby!");