WoW:API UnitCanAttack: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
mNo edit summary
m (Move page script moved page API UnitCanAttack to API UnitCanAttack without leaving a redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<center>'''UnitCanAttack''' ''-Documentation by [[user:danboo|danboo]]-''</center>
{{wowapi}} __NOTOC__
Returns 1 if the first unit can attack the second, nil otherwise.


Returns true if the first unit can attack the second, false otherwise.
canAttack = UnitCanAttack(attacker, attacked);


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==
;''Arguments''
if ( UnitCanAttack("player", "target") ) then
  DEFAULT_CHAT_FRAME:AddMessage("You can attack " .. UnitName("target") .. ".");
end


:(String attacker, Table attacked)
===Result===
 
If the player can attack their target, a message stating so is displayed in the default chat frame.
:;attacker : the unit that would initiate the attack (e.g., "player" or "target")
:;attacked : the unit that would be attacked (e.g., "player" or "target")
 
----
;''Returns''
 
:Boolean isTrue
:;isTrue : true if the <tt>attacker</tt> can attack the <tt>attacked</tt>, false otherwise
 
----
;''Example''
  if ( UnitCanAttack("target", "player") ) then
    -- Hostile players are red
    if ( UnitCanAttack("player", "target") ) then
      TargetFrameNameBackground:SetVertexColor(1.0, 0.0, 0.0);
    end
  end
 
;''Result''
:If the target can attack the player and the player can attack the target then the target's name will appear red to the player.
 
----
;''Description''
 
: Returns true if the first unit can attack the second, false otherwise.
 
----
{{Template:WoW API}}
[[Category:API Functions|UnitCanAttack]]
[[Category:API Unit Functions|UnitCanAttack]]

Latest revision as of 04:47, 15 August 2023

WoW API < UnitCanAttack

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

canAttack = UnitCanAttack(attacker, attacked);

Parameters[edit]

Arguments[edit]

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[edit]

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

Example[edit]

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

Result[edit]

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