WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   RegisterUnitEvent ... UNIT_AURA (https://www.wowinterface.com/forums/showthread.php?t=58097)

glupikreten 07-14-20 02:15 PM

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)


LudiusMaximus 07-14-20 02:37 PM

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.

glupikreten 07-15-20 03:39 AM

Sometimes when tired you make the most embarrassing errors... like declaring f and using frame afterward :confused: :confused: :confused:

Thank you tho.

Fizzlemizz 07-15-20 09:34 AM

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.

glupikreten 07-16-20 11:54 AM

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

Seerah 07-16-20 11:59 AM

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

LudiusMaximus 07-16-20 12:05 PM

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)


glupikreten 07-16-20 12:11 PM

Oh yeah.. thank you so much .. and for fast answers as well...

SDPhantom 07-16-20 01:36 PM

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

LudiusMaximus 07-17-20 02:08 AM

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


Kanegasi 07-17-20 02:16 AM

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.

LudiusMaximus 07-17-20 02:22 AM

Cool thanks!


All times are GMT -6. The time now is 01:21 PM.

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