frame:HookScript("OnEvent", function(self, event, ...) -- Do something end);
- Frame - Reference to the frame who had registered for the event.
- String - Full name of the triggered event.
- Vararg Function - Variable number of remaining arguments representing the payload of each event.
The following examples show a frame that responds to many different events, including one with a payload that is transcribed to arg1 through arg4:
local myFrame = CreateFrame("Frame") myFrame:HookScript("OnEvent", function(__, event, arg1, arg2, arg3, arg4) if (event == "PLAYER_LOGIN") then -- The player just logged in (payload: none) elseif (event == "PLAYER_REGEN_DISABLED") then -- The player is about to enter combat (payload: none) elseif (event == "PLAYER_REGEN_ENABLED") then -- The player just left combat (payload: none) elseif (event == "UNIT_SPELLCAST_SENT" and arg1 == "player" and arg4 == "1459") then -- I am casting arcane intellect (payload: unit, target, castGUID, spellID) end end); myFrame:RegisterEvent("PLAYER_LOGIN"); myFrame:RegisterEvent("PLAYER_REGEN_DISABLED"); myFrame:RegisterEvent("PLAYER_REGEN_ENABLED"); myFrame:RegisterEvent("UNIT_SPELLCAST_SENT");
- Each event has its own payload, or variable number of arguments, described on that event's own page within Wowpedia