Skip to content

enemies_in_combat

The enemies_in_combat function retrieves the number of enemy units that are currently in combat within a specified range around a unit. This function is useful for identifying and counting enemies that are actively engaged in combat.

Parameters

  • range (number, optional): The maximum distance within which to search for enemy units in combat. Defaults to 40 if not specified.
  • unit (string, optional): The unit identifier (such as "player", "target", "focus", etc.) around which to search for enemies in combat. Defaults to "player" if not specified.
  • units (table, optional): A table to store the identifiers of the enemy units found in combat.

Returns

  • count (number): The number of enemy units found in combat within the specified range.
  • valid_objects (table): A table containing the identifiers of the enemy units found in combat.

Example Usage in Lua

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

local api = ...

-- Function to print the number of enemy units in combat around a specified unit
function PrintEnemiesInCombat(range, unit)
    local count, valid_objects = api.enemies_in_combat(range, unit)
    print("Number of enemies in combat around unit '" .. unit .. "' within range " .. range .. ": " .. count)
    for _, enemy in ipairs(valid_objects) do
        print(enemy)
    end
end

-- Example usage: Print the number of enemy units in combat around the player within a range of 40
PrintEnemiesInCombat(40, "player")