Skip to content

enemies_around_unit

The enemies_around_unit function retrieves a list of enemy units around a specified unit within a given distance. This function is useful for identifying and targeting enemies in the vicinity of a unit.

Parameters

  • unit (string): The unit identifier (such as "player", "target", "focus", etc.) around which to search for enemies.
  • distance (number): The maximum distance within which to search for enemy units.
  • func (function, optional): An optional filter function to apply additional criteria to the search.

Returns

  • enemies (table): A table containing the identifiers of the enemy units found within the specified distance.
  • count (number): Total count of enemy units found within the specified distance.

Example Usage in Lua

Here is an example of how to use the enemies_around_unit function in Lua:

local api = ...

-- Function to print the list of enemy units around a specified unit
function PrintEnemiesAroundUnit(unit, distance)
    local enemies, count  = api.enemies_around_unit(unit, distance)
    print("Enemies around unit '" .. unit .. "' within distance " .. distance .. ":")
    for _, enemy in ipairs(enemies) do
        print(enemy)
    end
    print ('Total enemies around the unit is: ', count)
end

-- Example usage: Print the list of enemy units around the player within a distance of 10
PrintEnemiesAroundUnit("player", 10)