Thread Tools Display Modes
07-14-20, 02:15 PM   #1
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
RegisterUnitEvent ... UNIT_AURA

Hi,

I'm trying to mess with unit auras and code below does nothing for me.
I'm talking classic wow.

Can i do that somehow?

I tried with hooksecurefunc but that works on target and player... not on pet... at least I couldn't find anything.

Question is: can I track pet auras as an event?

Thank you

Code:
local Pet()
print("function)
end

local Target()
print("function)
end

local f = CreateFrame("Frame")
frame:RegisterUnitEvent("UNIT_AURA", "pet")
frame:SetScript("OnEvent", Pet)

local f = CreateFrame("Frame")
frame:RegisterUnitEvent("UNIT_AURA", "target")
frame:SetScript("OnEvent", Target)

THIS WORKS ... but  there is nothing to track pet auras similar to this (or?)
hooksecurefunc("TargetFrame_UpdateAuras", Target)
  Reply With Quote
07-14-20, 02:37 PM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Are you sure this code is running at all? It has some obvious syntax errors...

Have you enabled your error messages?
Code:
/console scriptErrors 1

I think your
Code:
local Pet()
print("function)
end
should really be
Code:
local function Pet()
  print("This is Pet()... or something.")
end

Furthermore, you are creating your frame as f, but use the variable name frame afterwards. This should throw an error, too.

Then you are using frame:SetScript() for "OnEvent" twice.
The second script assignment will override the first.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 07-14-20 at 03:26 PM.
  Reply With Quote
07-15-20, 03:39 AM   #3
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
Sometimes when tired you make the most embarrassing errors... like declaring f and using frame afterward

Thank you tho.
  Reply With Quote
07-15-20, 09:34 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
A single frame can monitor multiple events or in this case, the same event for more than one unit.

Lua Code:
  1. local function AuraCheck(self, event, ...)
  2.     local unit = ...
  3.     if unit == "target" then
  4.         print("Target Aura changed!")
  5.     elseif unit == "pet" then
  6.         print("Pet Aura changed!")
  7.     end
  8. end
  9.  
  10. local f = CreateFrame("Frame")
  11. f:RegisterUnitEvent("UNIT_AURA", "target", "pet")
  12. f:SetScript("OnEvent", AuraCheck)

You can only register a maximum of two units with RegisterUnitEvent but if you need more, you could just use RegisterEvent and extend the unit checking in the event function.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-16-20, 11:54 AM   #5
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
Thank you. That was helpful.

Could you be so kind and tell me just one more thing... is there an easy way to know when some frame is opened (like CharcterFrame or TalentFrame)?

Some of them have events like MERCHANT_SHOW, BANKFRAME_OPENED...
  Reply With Quote
07-16-20, 11:59 AM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
If there is no event that fires when a frame is shown, you can try hooking that frame's OnShow script (if it has one).
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-16-20, 12:05 PM   #7
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
For CharcterFrame you can simply do:
Code:
hooksecurefunc(CharcterFrame, "Show", function() print("Showing CharcterFrame") end)
hooksecurefunc(CharcterFrame, "Hide", function() print("Hiding CharcterFrame") end)

But for PlayerTalentFrame (and others like ArchaeologyFrame, InspectFrame, AuctionHouseFrame, ClassTrainerFrame) it is a bit more complicated, because these frames do not exist yet after login. You have to wait with your hook until after they are created, and that is what these events you are mentioning can be helpful for. So for PlayerTalentFrame you could do:
Code:
local playerTalentFrameHooked = false
local addonLoadedFrame = CreateFrame("Frame")
addonLoadedFrame:RegisterEvent("ADDON_LOADED")
addonLoadedFrame:SetScript("OnEvent", function(self, event, arg1, ...)
  if not playerTalentFrameHooked and arg1 == "Blizzard_TalentUI" then
    hooksecurefunc(PlayerTalentFrame, "Show", function() print("Showing PlayerTalentFrame") end)
    hooksecurefunc(PlayerTalentFrame, "Hide", function() print("Hiding PlayerTalentFrame") end)
    playerTalentFrameHooked = true
  end
end)
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
07-16-20, 12:11 PM   #8
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
Oh yeah.. thank you so much .. and for fast answers as well...
  Reply With Quote
07-16-20, 01:36 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I would usually hook the frame's OnShow/OnHide handlers. (As Seerah mentioned before)
Lua Code:
  1. frame:HookScript("OnShow",function(self)
  2. -- Do something
  3. end);
  4.  
  5. frame:HookScript("OnHide",function(self)
  6. -- Do something
  7. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-16-20 at 01:39 PM.
  Reply With Quote
07-17-20, 02:08 AM   #10
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
What are the cases where you would feel the difference between these two?

Code:
frame:HookScript("OnShow",function(self)
-- Do something
end);
Code:
hooksecurefunc(frame, "Show", function(self)
-- Do something
end);
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
07-17-20, 02:16 AM   #11
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Sometimes a frame's Show widget, or at least the pointer you can hook, isn't used to show the frame. The OnShow handler is guaranteed to fire every time the frame shows.
  Reply With Quote
07-17-20, 02:22 AM   #12
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Cool thanks!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » RegisterUnitEvent ... UNIT_AURA

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