Event Registration
Event Callbacks
Super Macro provides two event registration functions: RegisterEvent (persistent registration) and RegisterOnceEvent (one-shot registration). When a specified event occurs, Heitu will call your registered callback function.
RegisterEvent — Persistent Registration
Requires Heitu version >= 1.11.17
Registers a persistent event callback that executes every time the event fires. Pass nil to clear the callback for that event.
void RegisterEvent(string eventName, function callback)
RegisterOnceEvent — One-Shot Registration
Registers a one-shot event callback that is automatically removed after firing once. Registering again with the same event name overwrites the previous one. Pass nil to manually clear.
void RegisterOnceEvent(string eventName, function callback)
Notes
- Prefer
RegisterOnceEvent, asRegisterEventis global and may cause interference between macros - Each event can only have one callback per registration type (
RegisterEventandRegisterOnceEventare independent). Re-registering overwrites the previous one. - The callback runs on the main thread — the game will wait during execution. Do not write infinite loops or time-consuming operations in callbacks.
- If the callback encounters an error, a warning is logged but the game will not crash.
Supported Events
SWING_RESULT — Swing Complete
Fires when you complete a swing attack. Suitable for queuing Heroic Strike, monitoring rage, resetting swing timers, etc.
Callback parameter:
| Value | Meaning |
|---|---|
1 | Main-hand swing complete |
2 | Off-hand swing complete |
3 | Ranged weapon attack complete |
SWING_RESULT_HAND1 — Main-Hand Swing Complete
Fires when a main-hand swing attack completes. No callback parameters.
SWING_RESULT_HAND2 — Off-Hand Swing Complete
Fires when an off-hand swing attack completes. No callback parameters.
SWING_RESULT_HAND3 — Ranged Attack Complete
Fires when a ranged weapon (bow/crossbow/gun/wand) attack completes. No callback parameters.
Examples
Example 1: Persistent Swing Monitoring
Paste the following code into the Heitu Super Macro editor. After saving, you'll see swing notifications in-game:
function OnSwing(hand)
if hand == 1 then
print("Main-hand swing complete")
elseif hand == 2 then
print("Off-hand swing complete")
elseif hand == 3 then
print("Ranged attack complete")
end
end
RegisterEvent("SWING_RESULT", OnSwing)Tips
The initialization code above only runs once (when you copy it to the editor and save). After that, OnSwing is called automatically on every swing.
Example 2: Specific Event Listening
No need to check the hand parameter — listen directly to a specific event:
RegisterOnceEvent("SWING_RESULT_HAND1", function()
print("Main-hand swing complete")
-- Only care about main hand, no parameter check needed
end)Example 3: One-Shot Trigger
Fire only on the next swing, then cancel automatically:
RegisterOnceEvent("SWING_RESULT", function(hand)
if hand == 1 then
print("Main-hand swing complete — this callback runs only once")
end
end)Example 4: Clearing Callbacks
Pass nil to cancel event listening when no longer needed:
RegisterEvent("SWING_RESULT", nil)
RegisterOnceEvent("SWING_RESULT", nil)