WoW:API UnitIsFriend: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(boilerplate)
Line 1: Line 1:
{{wowapi}}
{{wowapi}}
This function will determine if the target 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.
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");


== Parameters ==
== Arguments ==
;unit:String - A valid [[API TYPE UnitId|unit]].
;otherunit:String - A valid [[API TYPE UnitId|unit]].


=== Function ===
== Returns ==
:;UnitIsFriend : UnitIsFriend("unit","otherunit")<br>Determine whether a unit is friendly with you or not.
;IsFriend:Boolean flag - 1 if otherunit is friendly to unit; nil otherwise.


=== Arguments ===
== Example ==
:;unit:String - The [[API TYPE UnitId|UnitId]] of the first unit.
The following snippet outputs a message when the player has a hostile target.
:;otherunit:String - The [[API TYPE UnitId|UnitId]] of the unit to compare with the first unit.
if UnitExists("target") and not UnitIsFriend("player", "target") then
 
  print(UnitName("target") .. " is evil! Run!");
=== Returns ===
end
:;IsFriend: Returns either nil or 1, not a boolean value.<br>If the second parameter is "target" and nothing is targeted, this function returns <tt>nil</tt>.
 
=== Example ===
:;IsFriend : /script if (UnitIsFriend("player","target")) then AssistUnit("target"); end <br> This will determine if your target is friendly, and if it is assist.
 
:;Not IsFriend : /script if not (UnitIsFriend("player","target")) then SendChatMessage("%t is evil!","SAY"); end; <br> This is to find if the target is not friendly with you (enemy). If you target an unfriendly target with the name "60Mage" this script will write "60Mage is evil!" in /s, using your faction's default language.

Revision as of 18:35, 31 August 2009

WoW API < UnitIsFriend

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

Arguments

unit
String - A valid unit.
otherunit
String - A valid unit.

Returns

IsFriend
Boolean flag - 1 if otherunit is friendly to unit; nil otherwise.

Example

The following snippet outputs a message when the player has a hostile target.

if UnitExists("target") and not UnitIsFriend("player", "target") then
 print(UnitName("target") .. " is evil! Run!");
end