units_attacking_unit
The units_attacking_unit function retrieves a list of units that are currently attacking a specified unit. This function is useful for identifying and targeting enemies that are actively engaged in combat with a specific unit.
Parameters
unit(string): The unit identifier (such as "player", "target", "focus", etc.) for which to retrieve the attacking units.
Returns
units(table): A table containing the identifiers of the units that are currently attacking the specified unit.
Example Usage in Lua
Here is an example of how to use the units_attacking_unit function in Lua:
local api = ...
-- Function to print the list of units attacking a specified unit
function PrintUnitsAttackingUnit(unit)
local attacking_units = api.units_attacking_unit(unit)
print("Units attacking '" .. unit .. "':")
for _, attacker in ipairs(attacking_units) do
print(attacker)
end
end
-- Example usage: Print the list of units attacking the player
PrintUnitsAttackingUnit("player")