Advertisement
Seerah

ESO Event Tutorial

Apr 10th, 2014
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. --Register for our event
  2. --this event has one return, the name of the addon that loaded, causing the event to fire
  3. --but an event handler (what you are doing right here, assigning a function to an event) will always return what event fired FIRST
  4. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, function(event, addon)   --this function continues on the next few lines
  5.         if addon == "MyAddon" then  --if the addon return matches the name of our addon
  6.             DoSomething()   --then do whatever you want when it happens
  7.         end
  8.     end)    --this is now the end of the function and the end of the event handler
  9.  
  10.  
  11. --You can also do this by passing a pre-defined event to the event handler, rather than creating an anonymous one
  12. --When you do this, you can assign multiple events to the same function
  13. --Let's define our function first --> don't forget that the event code comes first from our event handler!!
  14. local function MyFunction(event, arg1)
  15.     if event == EVENT_ADD_ON_LOADED then    --if it was our addon loading
  16.         DoSomething()   --do what you want to at load
  17.     else    --if it was our character loading into the world
  18.         d("Hello World!")   --do something else
  19.     end
  20. end
  21.  
  22. --now that our function is defined, we can register for our events and pass that function to the event handler
  23. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, MyFunction)  --the args/returns get passed into our function automatically
  24. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_PLAYER_READY, MyFunction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement