Quantcast
PLAYER_CHANGED_TARGET for target acquisition - WoWInterface
Thread Tools Display Modes
03-12-18, 01:49 AM   #1
jukx
A Murloc Raider
 
jukx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 7
Question PLAYER_CHANGED_TARGET for target acquisition

I want to update my (oUF) frames each time the target changes or something is targeted in the first place. Initially I thought I could use the PLAYER_TARGET_CHANGED event for that, but it doesn't fire if you don't have a target and select something for the first time. Is there an event I could hook for that case?

edit: it's the UNIT_TARGET event
edit2: to find out which events fire during play, refer to the /eventtrace command

Last edited by jukx : 03-12-18 at 04:36 AM.
  Reply With Quote
03-12-18, 04:27 AM   #2
spanky0312
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Mar 2013
Posts: 11
Originally Posted by jukx View Post
I want to update my (oUF) frames each time the target changes or something is targeted in the first place. Initially I thought I could use the PLAYER_TARGET_CHANGED event for that, but it doesn't fire if you don't have a target and select something for the first time. Is there an event I could hook for that case?

edit: it's the UNIT_TARGET event
Mind in sharing the code with us, I am interested in this
  Reply With Quote
03-12-18, 04:34 AM   #3
jukx
A Murloc Raider
 
jukx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 7
Sure, here you go:

Lua Code:
  1. frame:RegisterEvent("UNIT_TARGET")
  2. frame:HookScript("OnEvent", powerBarHandler)
  3.  
  4. function powerBarHandler(frame, event, unit)
  5.     updatePowerBarVisibility(frame)
  6. end
  7.  
  8. function updatePowerBarVisibility(frame)
  9.     local unit = 'target'
  10.     if UnitPlayerControlled(unit) or UnitPowerType(unit) ~= 1 then
  11.         frame.Power:Show()
  12.     else
  13.         frame.Power:Hide()
  14.     end
  15. end
(simplified a tad)

The goal was to hide the target frame power bar for NPCs that don't use power. From testing it seems that they have assigned the power type 1 (i.e. 'RAGE').
  Reply With Quote
03-12-18, 04:41 AM   #4
spanky0312
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Mar 2013
Posts: 11
Thanks mate
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » PLAYER_CHANGED_TARGET for target acquisition

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off