Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Source: http://wowprogramming.com/forums/development/633
- 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.
- self.time = (self.time or 3)-elapsed
- local alpha = self:GetAlpha()
- if self.time > 0 then return end
- 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.
- self.time = self.time+3
- 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)
- end
- if alpha <= 0 then
- self:Hide()
- else
- self:SetAlpha(alpha)
- end
- end
- 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.
- textFrame:SetSize(300,300)
- textFrame:Hide()
- textFrame:SetScript("OnUpdate",onUpdate)
- textFrame.text = textFrame:CreateFontString(nil,"BACKGROUND","PVPInfoTextFont")
- textFrame.text:SetAllPoints()
- textFrame:SetPoint("CENTER",0,200)
- 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.
- self.text:SetText(message)
- self:SetAlpha(1)
- self.time = 3
- self:Show()
- end
- -- Source by http://www.wowinterface.com/forums/showthread.php?t=42976
- local buffs = {
- ["Jolly Roger"] = false,
- ["Grand Melee"] = false,
- ["Shark Infested Waters"] = false,
- ["True Bearing"] = false,
- ["Buried Treasure"] = false,
- ["Broadsides"] = false
- }
- textFrame:RegisterEvent("UNIT_AURA")
- textFrame:SetScript("OnEvent", function(self, event, ...)
- local count = 0
- if (unit and unit ~= "player") then
- return
- end
- -- Check player buffs against the roll the bones buffs
- for buff in pairs(buffs) do
- if UnitBuff("player", buff) then
- count = count + 1
- end
- end
- -- Give warning if need to reroll the bones
- if UnitBuff("player", "True Bearing") or UnitBuff("player", "Shark Infested Waters") or count >= 2 then
- textFrame:message("")
- else
- textFrame:message("ROLL THE BONES!!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement