View Single Post
03-06-12, 11:02 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Something like this:

lua Code:
  1. --  Make a list of the buffs you want to check for:
  2. local buffs = {
  3.     ["Battle Shout"] = true,
  4.     ["Blessing of Kings"] = true,
  5.     ["Horn of Winter"] = true,
  6.     ["Mark of the Wild"] = true,
  7.     ["Well Fed"] = true,
  8. }
  9.  
  10. ------------------------------------------------------------------------
  11. --  Create a frame.
  12. --  Frames are the basic UI objects in WoW.
  13. --  You need them in order to respond to events (things happening in the
  14. --  game) or to show visible elements on the screen (graphics, text,
  15. --  buttons, etc.).
  16. ------------------------------------------------------------------------
  17. local frame = CreateFrame("Frame")
  18.  
  19. ------------------------------------------------------------------------
  20. --  Register for the UNIT_AURA event.
  21. --  Events are how WoW tells addons that something has happened.
  22. --  The UNIT_AURA event fires whenever any buff or debuff changes on any
  23. --  unit that currently has a unit token (such as player, target, boss1,
  24. --  focustarget, arena3, party2, or raid18pet).
  25. ------------------------------------------------------------------------
  26. frame:RegisterEvent("UNIT_AURA")
  27.  
  28. ------------------------------------------------------------------------
  29. --  Set an OnEvent handler for the frame.
  30. --  This is a function that will be run each time the frame receives
  31. --  an event for which it has registered.
  32. --  The function recieves a reference to the frame as its first
  33. --  argument (conventionally named "self"), the name of the event
  34. --  as the second argument (conventionally named "event"), and then
  35. --  event-specific data from the third argument onward.
  36. ------------------------------------------------------------------------
  37. frame:SetScript("OnEvent", function(self, event, ...)
  38.     --------------------------------------------------------------------
  39.     --  ... is called a vararg, and is a construct that contains any
  40.     --  number of variables. It is used mainly when receiving variables
  41.     --  without knowing how many of them there are. Since different
  42.     --  events pass different numbers of arguments, a vararg is very
  43.     --  common in event handling functions.
  44.     --  Technically you don't need it here, since your frame is only
  45.     --  registered for one event, but if you expand your addon later,
  46.     --  it may become useful.
  47.     --------------------------------------------------------------------
  48.  
  49.     --  Unpack the vararg into the variable(s) it contains:
  50.     local unit = ...
  51.  
  52.     --  If the unit is not "player" you don't care about it, so
  53.     --  you can quit out of the function early to save time:
  54.     if unit ~= "player" then
  55.         return
  56.     end
  57.  
  58.     --  Loop through all of the buffs you want to check for:
  59.     for buff in pairs(buffs) do
  60.         --  Check to see if you have the buff:
  61.         if UnitBuff("player", buff) then
  62.             --  You have the buff.
  63.             --  Do something here.
  64.         else
  65.             --  You don't have the buff.
  66.             --  Do something here.
  67.         end
  68.     end
  69. end)
  Reply With Quote