Quantcast WoWInterface - View Single Post - code to check player for buff
View Single Post
03-08-12, 08:42 PM   #5
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Here's how you would modify Phanx's code to do what you want to do:

lua Code:
  1. local buffs = {
  2.     -- setting the defaults to false so that you can start out assuming the player doesn't have the buff
  3.     ["Battle Shout"] = false,
  4.     ["Blessing of Kings"] = false,
  5.     ["Horn of Winter"] = false,
  6.     ["Mark of the Wild"] = false,
  7.     -- add the spell IDs for food buffs here - you can feed them into UnitBuff with the same syntax as spell names
  8.     87554 = false,
  9.     87555 = false,
  10.     87549 = false,
  11.     87545 = false,
  12. }
  13.  
  14. local frame = CreateFrame("Frame")
  15.  
  16. frame:RegisterEvent("UNIT_AURA")
  17. -- probably want to check for buffs on login as well, I'm not sure if Unit_Aura fires
  18. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  19.  
  20. frame:SetScript("OnEvent", function(self, event, ...)
  21.     if (unit and unit ~= "player") then
  22.         return
  23.     end
  24.  
  25.     for buff in pairs(buffs) do
  26.         if UnitBuff("player", buff) then
  27.             -- If you have the buff, check to see if it's already been factored in
  28.             if not buffs[buff] then
  29.                 -- If it hasn't been factored in, adjust accordingly
  30.                 buffs[buff] = true
  31.                 AddBuffAdjustment(buff)
  32.             end
  33.         else
  34.             -- If you don't have the buff, check to see if you're still adjusting for it
  35.             if buffs[buff] then
  36.                 -- If you're still adjusting for it, remove the adjustment
  37.                 buffs[buff] = false
  38.                 RemoveBuffAdjustment(buff)
  39.             end
  40.         end
  41.     end
  42. end)
  43.  
  44. local function AddBuffAdjustment(buff)
  45.     if buff == "Battle Shout" then
  46.         -- do whatever you need to do when Battle Shout is added
  47.     elseif buff == "Blessing of Kings" or buff = "Mark of the Wild" then
  48.         -- do whatever you need to do when BoK/Mark is added
  49.     elseif
  50.         -- and so forth
  51.     else
  52.    
  53.     end
  54. end
  55.  
  56. local function RemoveBuffAdjustment(buff)
  57.     if buff == "Battle Shout" then
  58.         -- do whatever you need to do when Battle Shout is removed
  59.     elseif buff == "Blessing of Kings" or buff == "Mark of the Wild" then
  60.         -- do whatever you need to do when BoK/Mark is removed
  61.     elseif
  62.         -- and so forth
  63.     else
  64.    
  65.     end
  66. end

You'll have to calculate a bit differently than you've been doing, but it should actually be simpler.
  Reply With Quote