Thread Tools Display Modes
05-30-21, 09:14 PM   #1
Tair
A Deviate Faerie Dragon
Join Date: Aug 2020
Posts: 10
[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.

Last edited by Tair : 05-30-21 at 09:28 PM.
  Reply With Quote
05-30-21, 09:53 PM   #2
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
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.

Last edited by DahkCeles : 05-30-21 at 09:56 PM.
  Reply With Quote
05-31-21, 09:51 AM   #3
Tair
A Deviate Faerie Dragon
Join Date: Aug 2020
Posts: 10
That worked perfectly. Thanks for teaching me something new.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [TBC] Merge multiple event triggers into one notification? (Paladin's taunt))

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