Quantcast
WoWInterface - View Single Post - How to check if Unit target is player
View Single Post
10-20-18, 02:05 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
In your nameplate addon you will have a unitID associated with every nameplate that you're drawing.

When a nameplate is shown, the NAME_PLATE_UNIT_ADDED event will fire, and provide the unitID as its first argument. This can be passed to C_NamePlate.GetNamePlateForUnit(unitID) to get the frame associated with the nameplate unit. That frame is what your addon is attaching to in order to draw its own nameplate above the unit's head.

The NAME_PLATE_CREATED, NAME_PLATE_UNIT_ADDED, and NAME_PLATE_UNIT_REMOVED events are used to track when to create a new nameplate frame, when to show and hide your addon's frames, and to keep track of which unitIDs belong to which nameplates.

When coloring your nameplates you generally have a series of conditions that need to be checked in a certain order, so "unit is targeting me" which you want to represent with one color might be a higher priority than "unit is a hostile npc" which has a different color, and therefor needs to take precedence over it.

In my personal addon I just do this check OnUpdate because I don't particularly care about efficiency, but how you do this is up to you.

Last edited by semlar : 10-20-18 at 02:08 PM.