WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   [TBC] Merge multiple event triggers into one notification? (Paladin's taunt)) (https://www.wowinterface.com/forums/showthread.php?t=58772)

Tair 05-30-21 09:14 PM

[TBC] Merge multiple event triggers into one notification? (Paladin's taunt))
 
Hi all,

I enjoy learning to write simple addons as I come across things in-game that I would like to add notifications for. I have a problem that I'm not sure how to solve and would really appreciate the input from more experienced authors.

In TBC, Paladins have the Righteous Defense spell, which applies an aura to up to 3 enemies. I'd like to track which targets are affected and print the names of those targets in a single message. The single message part is where I'm not sure how to proceed.

I've figured out how to detect and print which targets are taunted:

lua Code:
  1. if subevent == "SPELL_AURA_APPLIED" then
  2.      spellId, spellName, spellSchool = select(12, ...)
  3.      if spellName == "Righteous Defense" and Tair_BattleLog_SourceIsPlayer(sourceName) then
  4.           print("Taunted "..destName)
  5.      end
  6. end

Which prints up to 3 lines of target names. I'd like to combine that into a single message, so my next thought was to add them to a table:

lua Code:
  1. local tauntedMobs = {}

lua Code:
  1. if subevent == "SPELL_AURA_APPLIED" then
  2.      spellId, spellName, spellSchool = select(12, ...)
  3.      if spellName == "Righteous Defense" and Tair_BattleLog_SourceIsPlayer(sourceName) then
  4.           --print("Taunted "..destName)
  5.           table.insert(tauntedMobs, destName)
  6.      end
  7. end

I know that I can output the table of targets with table.concat, but my hurdle is that I'm not sure when I can actually call that and get the final list of targets.

Potential ideas I've had:
  • Maybe using UNIT_THREAT_LIST_UPDATE to print the table, assuming that it might have all of the targets at that point
  • Setting a timer function for some short duration to allow the table to populate before printing the list of targets

Hopefully I described things clearly enough. Thanks for reading this far!

Edit: I thought I ought to add a summary since the majority of the post just explained my thought process. I want to print a single message with the name of every target that has an aura applied as a result of a specific spell. So, as an example:

Righteous Defense: Scarlet Protector, Scarlet Defender, Scarlet Monk
Frost Nova: Scarlet Protector, Scarlet Defender, Scarlet Monk

I'm a little bit stuck because I'm not sure how to best take the multiple SPELL_AURA_APPLIED events that fire and combine them into a single message that captures the entire list of targets.

DahkCeles 05-30-21 09:53 PM

https://wowpedia.fandom.com/wiki/API_C_Timer.After

Lua Code:
  1. local needTimer = true
  2. local tauntedMobs = {}
  3.  
  4. local function timesUp()
  5.     needTimer = true
  6.     -- do whatever you want with tauntedMobs
  7. end
  8.  
  9. local function onSubEvent(subevent, ...)
  10.     if subevent == "SPELL_AURA_APPLIED" then
  11.          spellId, spellName, spellSchool = select(12, ...)
  12.          if spellName == "Righteous Defense" and Tair_BattleLog_SourceIsPlayer(sourceName) then
  13.               --print("Taunted "..destName)
  14.               table.insert(tauntedMobs, destName)
  15.               if (needTimer) then
  16.                   needTimer = false
  17.                   C_Timer.After(0, timesUp)
  18.               end
  19.          end
  20.     end
  21. end


PS. I'm not sure where 'destName' comes from.

Tair 05-31-21 09:51 AM

That worked perfectly. Thanks for teaching me something new.


All times are GMT -6. The time now is 03:16 AM.

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