Skip to main content

Overview

The WeakAuras event system manages trigger events, custom events, and callback registration. It provides a flexible way to respond to game events and custom triggers.

Event Scanning

ScanEvents

Triggers an event scan for all registered triggers.
event
string
required
The event name to scan
...
any
Event arguments passed to trigger functions
-- Trigger a custom event
WeakAuras.ScanEvents("CUSTOM_EVENT", data1, data2)

-- Trigger a game event
WeakAuras.ScanEvents("PLAYER_REGEN_DISABLED")

ScanEventsByID

Triggers an event scan with a specific ID parameter.
event
string
required
The base event name
id
string
required
The ID to append to the event
...
any
Additional event arguments
-- Scan for both "EVENT" and "EVENT:id"
WeakAuras.ScanEventsByID("SPELL_AURA_APPLIED", "12345", unit, spellId)

ScanUnitEvents

Scans events specific to a unit.
event
string
required
The unit event name
unit
string
required
The unit identifier
...
any
Additional event arguments
WeakAuras.ScanUnitEvents("UNIT_HEALTH", "player")

Callback System

RegisterCallback

Registers a callback for an event.
event
string
required
The event to listen for
handler
function
required
The callback function to execute
local Private = select(2, ...)
Private.callbacks:RegisterCallback("MY_EVENT", function(event, ...)
  print("Event fired:", event)
end)

Fire

Fires a callback event.
event
string
required
The event name to fire
...
any
Arguments to pass to callbacks
local Private = select(2, ...)
Private.callbacks:Fire("MY_EVENT", arg1, arg2)

Internal Events

WeakAuras uses several internal events for system communication:

Frame Update Events

  • FRAME_UPDATE: Fires every frame for on-update triggers
  • WA_DELAYED_PLAYER_ENTERING_WORLD: Fires shortly after login

Unit Change Events

  • UNIT_CHANGED_: Fires when a unit changes (internal)
  • UNIT_IS_UNIT_CHANGED__: Fires when unit identity changes

Trigger Events

  • TRIGGER: Fires when observed trigger state changes
  • OPTIONS: Special event for preview mode

Event Prototypes

Event prototypes define how triggers respond to events.

Event Prototype Structure

Private.event_prototypes["Event Name"] = {
  type = "category",  -- Event category
  events = { "GAME_EVENT" },  -- WoW events to register
  internal_events = { "INTERNAL_EVENT" },  -- WeakAuras internal events
  name = "Display Name",
  init = function(trigger)
    -- Initialization code
    return "local var = value"
  end,
  args = {
    -- Trigger arguments
  },
  statesParameter = "one", -- "one", "all", "unit", "full"
}

States Parameters

one
string
Single state trigger (most common)
all
string
Multiple states, trigger manages all clones
unit
string
One state per unit
full
string
Full control over state table

Combat Log Events

WeakAuras provides special handling for COMBAT_LOG_EVENT_UNFILTERED.
-- Combat log events are automatically parsed
Private.event_prototypes["Combat Log"] = {
  events = { "COMBAT_LOG_EVENT_UNFILTERED" },
  -- Subevents are automatically handled
}

Custom Event Examples

Simple Custom Event

-- Define a custom event trigger
function()
  -- Check condition
  if someCondition then
    -- Fire custom event
    WeakAuras.ScanEvents("MY_CUSTOM_EVENT", data)
    return true
  end
  return false
end

Event with State Management

function(states, event, ...)
  if event == "CUSTOM_EVENT" then
    local arg1, arg2 = ...
    states[""] = states[""] or {}
    local state = states[""]
    state.show = true
    state.changed = true
    state.value = arg1
    return true
  end
  return false
end

Watched Trigger Events

Listen to other trigger state changes:
function(states, event, triggernum, updatedStates)
  if event == "TRIGGER" then
    -- triggernum contains the watched trigger number
    -- updatedStates contains its current states
    for cloneId, state in pairs(updatedStates) do
      if state.show then
        -- React to watched trigger
        return true
      end
    end
  end
  return false
end

See Also

Build docs developers (and LLMs) love