Wikia

WoWWiki

API UnitCanAttack

Talk0
98,518pages on
this wiki

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

canAttack = UnitCanAttack(attacker, attacked);

Parameters

Arguments

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")

Returns

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

Example

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

Result

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

Advertisement | Your ad here

Photos

Add a Photo
62,044photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki