WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Smart way to register unit aura event for all raid members (https://www.wowinterface.com/forums/showthread.php?t=57030)

wille480 02-25-19 03:51 PM

Smart way to register unit aura event for all raid members
 
Hello! So i am reaching out for some smart advice to register every raid member in a a raid on the unit_aura event.

Some quick info about the addon: I am gathering each raid members debuffs (UnitDebuff()) and checking if a debuff on the raid member exists in my pre defined list of debuffs that i am checking.

How would a smart way be to register all the raid members on the event "UNIT_AURA" for this?

What i currently have is something along this line

Lua Code:
  1. local frame = CreateFrame("FRAME", nil); -- Frame that register various events in the world
  2.  
  3. function frame:UNIT_AURA()
  4.     -- check if every raid member inside my raid have any of the following debuffs in my debuff list
  5. end
  6.  
  7. function frame:PLAYER_ENTERING_WORLD(event, ...)
  8.     if(IsInRaid("player")) then --
  9.         for i = 1, MAX_RAID_MEMBERS do --(40)
  10.             if(UnitName("raid"..i) ~= nil) then
  11.                 frame:RegisterEvent("UNIT_AURA", "raid"..i)
  12.             end
  13.         end
  14.     end
  15. end
  16.  
  17.  
  18. frame:SetScript("OnEvent", function(self, event, ...)
  19.         self[event](self, event, ...)
  20.     end)
  21. frame:RegisterEvent("PLAYER_ENTERING_WORLD");

Would this be a good and smart way to register all the raid members under the event "UNIT_AURA" in order to check the raid members for debuffs? It is important for me to have the frame:UNIT_AURA() function executed whenever anything in regards to debuffs happends on whatever player in my raid. Kinds regards!

Fizzlemizz 02-25-19 05:00 PM

Events starting with UNIT_ will pass the unit the event is for as the first parameter.

Lua Code:
  1. local Events = {}
  2. function Events.UNIT_AURA(self, ...)
  3.     local unit = ...
  4. -- check the units auras
  5. end
  6.  
  7. function Events.PLAYER_ENTERING_WORLD(self, ...)
  8.     local isInitialLogin, isReloadingUi = ...
  9. -- do whatever
  10. end
  11.  
  12. local frame = CreateFrame("FRAME", nil); -- Frame that register various events in the world
  13. frame:SetScript("OnEvent", function(self, event, ...)
  14.     Events[event](self, ...)
  15. end)
  16.  
  17. for k,_ in pairs(Events) do
  18.     frame:RegisterEvent(k)
  19. end


All times are GMT -6. The time now is 07:56 AM.

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