WoW API < UnitCanAttack

Returns 1 if the first unit can attack the second, nil otherwise.

canAttack = UnitCanAttack(attacker, attacked);

Parameters[edit | edit source]

Arguments[edit | edit source]

UnitId - the unit that would initiate the attack (e.g., "player" or "target")
UnitId - the unit that would be attacked (e.g., "player" or "target")

Returns[edit | edit source]

Bool - 1 if the attacker can attack the attacked, nil otherwise.

Example[edit | edit source]

if ( UnitCanAttack("player", "target") ) then
 DEFAULT_CHAT_FRAME:AddMessage("You can attack " .. UnitName("target") .. ".");

Result[edit | edit source]

If the player can attack their target, a message stating so is displayed in the default chat frame.

Community content is available under CC-BY-SA unless otherwise noted.