Skip to main content

Event Handler

The Event Handler provides a streamlined way to handle both combat log events and normal WoW events. It offers filtering capabilities and structured event data.

Basic Usage

local EventHandler = Aurora.EventHandler

-- Register a combat log event handler
EventHandler:RegisterEvent("SPELL_CAST_SUCCESS", function(eventData)
if eventData.source.guid == UnitGUID("player") then
print(string.format("You cast %s", C_Spell.GetSpellLink(eventData.params[1])))
end
end)

-- Register a normal WoW event handler
EventHandler:RegisterNormalEvent("PLAYER_ENTERING_WORLD", function()
print("Player entered the world")
end)

Event Registration

Combat Log Events

EventHandler:RegisterEvent(eventType, handlerFunction)
  • eventType: Combat log event type (e.g., "SPELL_CAST_SUCCESS")
  • handlerFunction: Function that receives the structured event data

Normal Events

EventHandler:RegisterNormalEvent(eventType, handlerFunction)
  • eventType: WoW event name (e.g., "PLAYER_ENTERING_WORLD")
  • handlerFunction: Function that receives the raw event parameters

Event Data Structure

Combat log events provide structured data:

eventData = {
timestamp = 1234567890,
event = "SPELL_CAST_SUCCESS",
source = {
guid = "Player-1234-5678",
name = "PlayerName",
flags = sourceFlags,
raidFlags = sourceRaidFlags
},
dest = {
guid = "Target-1234-5678",
name = "TargetName",
flags = destFlags,
raidFlags = destRaidFlags
},
params = { spellId, spellName, ... } -- Additional event-specific parameters
}

Event Filtering

Add filters to process only specific events:

-- Only process events where the player is the source
EventHandler:AddFilter("SPELL_CAST_SUCCESS", function(eventData)
return eventData.source.guid == UnitGUID("player")
end)

Examples

Track Player Spells

EventHandler:RegisterEvent("SPELL_CAST_SUCCESS", function(eventData)
if eventData.source.guid == UnitGUID("player") then
local spellId, spellName = unpack(eventData.params)
print(string.format("Cast %s (ID: %d)", spellName, spellId))
end
end)

Monitor Interrupts

EventHandler:RegisterEvent("SPELL_INTERRUPT", function(eventData)
local _, _, _, extraSpellId, extraSpellName = unpack(eventData.params)
print(string.format("%s interrupted %s's %s",
eventData.source.name,
eventData.dest.name,
extraSpellName))
end)

Track Group Changes

EventHandler:RegisterNormalEvent("GROUP_ROSTER_UPDATE", function()
print("Group composition changed")
end)

Best Practices

Performance
  • Use filters to reduce unnecessary event processing
  • Keep event handlers lightweight
  • Consider batching frequent events
  • Clean up handlers when no longer needed
Common Pitfalls
  • Don't register too many handlers for the same event
  • Be careful with string operations in high-frequency events
  • Remember that some events fire very frequently
  • Handle nil cases in event data

Common Combat Log Events

Click to view common combat log events
-- Spell Events
"SPELL_CAST_START" -- When a spell cast begins
"SPELL_CAST_SUCCESS" -- When a spell cast completes
"SPELL_CAST_FAILED" -- When a spell cast fails
"SPELL_AURA_APPLIED" -- When a buff/debuff is applied
"SPELL_AURA_REMOVED" -- When a buff/debuff is removed
"SPELL_INTERRUPT" -- When a spell is interrupted
"SPELL_DISPEL" -- When a buff/debuff is dispelled

-- Damage & Healing
"SPELL_DAMAGE" -- Spell damage
"SWING_DAMAGE" -- Melee damage
"SPELL_HEAL" -- Healing
"SPELL_PERIODIC_HEAL" -- HoT healing

-- Unit Events
"UNIT_DIED" -- When a unit dies
"PARTY_KILL" -- When your party kills something
Event Processing
  • Combat log events provide more structured data than normal events