WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   PLAYER_CHANGED_TARGET for target acquisition (https://www.wowinterface.com/forums/showthread.php?t=56089)

jukx 03-12-18 01:49 AM

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

spanky0312 03-12-18 04:27 AM

Quote:

Originally Posted by jukx (Post 327173)
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 :)

jukx 03-12-18 04:34 AM

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').

spanky0312 03-12-18 04:41 AM

Thanks mate :)


All times are GMT -6. The time now is 12:52 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI