Advertisement
Guest User

rollbones

a guest
Sep 28th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1.  
  2. -- Source: http://wowprogramming.com/forums/development/633
  3. local function onUpdate(self,elapsed) -- OnUpdate already provides an argument 'elapsed' as arg2 of the call - this contains the amount of seconds passed since the last OnUpdate fired. We can use this for timing purposes instead of calling GetTime on every OnUpdate.
  4.      self.time = (self.time or 3)-elapsed
  5.      local alpha = self:GetAlpha()
  6.      if self.time > 0 then return end
  7.      while self.time <= 0 do -- usually, this loop will execute at most once - however, it's possible to have heavy FPS lag and drop below 1/3 frames per second. It never hurts to account for extreme cases.
  8.          self.time = self.time+3
  9.          alpha = alpha-0.05 -- you can increase this value to quicken the fade. You could also decrease the time delay (lower time delay means 'smoother' fade at the cost of slightly higher resource consumption)
  10.      end
  11.      if alpha <= 0 then
  12.          self:Hide()
  13.      else
  14.          self:SetAlpha(alpha)
  15.      end
  16.  end
  17.  local textFrame = CreateFrame("Frame","MOD_TextFrame",UIParent) -- make sure your frame name (arg2) is unique (best done by prefixing your addon name), as a global with this name is automatically created for your frame. Pass nil as arg2 if a name is not needed to avoid namespace pollution.
  18.  textFrame:SetSize(300,300)
  19.  textFrame:Hide()
  20.  textFrame:SetScript("OnUpdate",onUpdate)
  21.  textFrame.text = textFrame:CreateFontString(nil,"BACKGROUND","PVPInfoTextFont")
  22.  textFrame.text:SetAllPoints()
  23.  textFrame:SetPoint("CENTER",0,200)
  24.  
  25.  function textFrame:message(message) -- last i checked, method lookups were faster than globals. plus no namespace pollution. if you want to call it from outside this file though, you probably want to make a global function - global lookup (function) + local lookup (frame) vs. global lookup (frame) + method lookup (function). if you do, make sure you prefix with addon name to avoid conflicts.
  26.      self.text:SetText(message)
  27.      self:SetAlpha(1)
  28.      self.time = 3
  29.      self:Show()
  30.  end
  31.  
  32.  
  33.  
  34. -- Source by http://www.wowinterface.com/forums/showthread.php?t=42976
  35.  
  36.  local buffs = {
  37.                 ["Jolly Roger"] = false,
  38.                 ["Grand Melee"] = false,
  39.                 ["Shark Infested Waters"] = false,
  40.                 ["True Bearing"] = false,
  41.                 ["Buried Treasure"] = false,
  42.                 ["Broadsides"] = false
  43.  }
  44.  
  45.  
  46.  
  47.  textFrame:RegisterEvent("UNIT_AURA")
  48.  textFrame:SetScript("OnEvent", function(self, event, ...)
  49.  
  50.  
  51.      local count = 0
  52.  
  53.          if (unit and unit ~= "player") then
  54.                  return
  55.          end
  56.  
  57.  
  58.          --  Check player buffs against the roll the bones buffs
  59.             for buff in pairs(buffs) do
  60.                     if UnitBuff("player", buff) then
  61.                         count = count + 1
  62.                     end
  63.             end
  64.  
  65.          --  Give warning if need to reroll the bones
  66.             if UnitBuff("player", "True Bearing") or UnitBuff("player", "Shark Infested Waters") or count >= 2 then
  67.                  textFrame:message("")
  68.             else
  69.              textFrame:message("ROLL THE BONES!!")
  70.             end
  71.  
  72.  
  73.  end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement