WoW:API UnitIsFriend: Difference between revisions

m
Move page script moved page API UnitIsFriend to WoW:API UnitIsFriend without leaving a redirect
No edit summary
m (Move page script moved page API UnitIsFriend to WoW:API UnitIsFriend without leaving a redirect)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
/script if (UnitIsFriend("player","target")) then AssistUnit("target"); end
{{wowapi}}
This function will determine whether two units are friendly to each other (i.e. able to help each other in combat).
isFriend = UnitIsFriend("unit","otherunit");


Note: in the context of this function, "friend" is any PC in your faction or any NPC that is friendly towards you (i.e. is green if you target it). It has nothing to do with whether you have added the unit to your friends list or not.
== Arguments ==
;unit:String - A valid [[API TYPE UnitId|unit]].
;otherunit:String - A valid [[API TYPE UnitId|unit]].


If the second parameter is "target" and nothing is targeted, this function returns <tt>nil</tt>.
== Returns ==
;IsFriend:Boolean flag - 1 if otherunit is friendly to unit; nil otherwise.


Note: returns either nil or 1, not a boolean value.
== Example ==
 
The following snippet outputs a message when the player has a hostile target.
[[Category:API Functions|UnitIsFriend]]
if UnitExists("target") and not UnitIsFriend("player", "target") then
[[Category:API Unit Functions|UnitIsFriend]]
  print(UnitName("target") .. " is evil! Run!");
end
Anonymous user