Fandom

WoWWiki

API UnitCanAttack

104,759pages on
this wiki
Add New Page
Talk0 Share
WoW API < UnitCanAttack

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

canAttack = UnitCanAttack(attacker, attacked);

ParametersEdit

ArgumentsEdit

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

ReturnsEdit

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

ExampleEdit

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

ResultEdit

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.