WoWInterface - View Single Post - Help with using expirationTime
View Single Post
05-05-20, 09:37 PM   #10
I did that?
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
I think this is more what you're looking for (I'm using Arcane intellect if you have a Mage or choose another spell to test that doesn't cost). I'm only counting down a couple of seconds from the start of the buff being applied so do with the timing as you will (x seconds before it runs out or whatever). Also printing the countdown so you can see it running.

Once a frame is hidden it's OnUpdate stops so I'm using a second frame for that and checking the event then using it to show the button if it finds the buff. This is where C_Timer is possibly a useful alternative but, this is just a basic starter example of how it might work.

I've started with the button hidden but that's up to you if you want it to be the primary source of the buff rather than just a popup reminder.

functions, variables etc. declared as local can't be used until after they're declared and only within the same code chunk.

Lua is case sensitive so UIparent is not the same as UIParent.

There are a bunch of other errors, if you don't have them installed I would suggest getting BuggGrabber and Bugsack so you can see when and mostly where/what your errors are.

Lua Code:
  1. -- Setup the button
  2. local button = CreateFrame("Button", "save-disk_MacroButton", UIParent, "SecureActionButtonTemplate, ActionButtonTemplate")
  3. self:SetAlpha(0.3)
  4. button:SetSize(24, 24)
  5. --button:SetPoint("CENTER", mainframe, "CENTER", 0, 0)
  6. button:SetPoint("CENTER")
  7. button:SetAttribute("type1", "macro") -- left click causes macro
  8. --button:SetAttribute("macrotext", "/cast Reflecting Prism")
  9. button:SetAttribute("macrotext", "/cast Arcane Intellect")
  10. button:SetText("Your Reflecting Prism will expire in 1 minute.")
  11. button:SetNormalFontObject("GameFontNormalSmall")
  12. button:SetNormalTexture("Interface/Icons/Inv_jewelcrafting_prism")
  13. button:SetHighlightTexture("Interface/ICONS/Spell_nature_wispsplode")
  14. button:SetPushedTexture("Interface/Icons/Spell_nature_wispsplode")
  15. button:EnableMouse(true)
  16. button:RegisterForClicks("LeftButtonUp")
  17. button:SetScript("PostClick", function(self, arg1)
  18.     self:SetAlpha(0.3)
  19. end)
  21. -- Show button function (code could be rolled into the timer)
  22. -- could be used to change the macro, icon, text depending on buff
  23. -- could be used for other stuff.
  24. local function popup(self)
  25.     self:SetAlpha(1)
  26.     PlaySound(1221)
  27.     FlashClientIcon()
  28. end
  30. -- Timer function
  31. local function MyOnUpdate(self, elapsed)
  32.     self.TimeToCheck = self.TimeToCheck - elapsed
  33.     if self.TimeToCheck > 0 then
  34.         return -- We haven't counted down to zero yet so do nothing
  35.     end
  36.     self.TimeToCheck = 1 -- We've waited a second so reset the timer
  37.     for i=1,40 do
  38.             local name, icon, count, type, max_time, end_time, caster, buttonis_stealable = UnitAura("player", i);
  39.         if not name then break end -- no name means no more buffs to check
  40. --          if name == "Reflecting Prism" then
  41.             if name == "Arcane Intellect" then
  42.             local TimeLeft = end_time - GetTime()-- check to see how much timer is left
  43.             print(name, TimeLeft)
  44.             if TimeLeft < 3595 then -- if we're in the zone
  45.                 self:SetScript("OnUpdate", nil)  -- cancel, the timer
  46.                 if not button:IsShown() then
  47.                     popup(button) -- show the button if required
  48.                 end
  49.                 return
  50.             end
  51.         end
  52.     end
  53. end
  55. -- Buff detection/timer starter frame
  56. local Auraframe = CreateFrame("Frame")
  57. Auraframe.TimeToCheck = 1
  58. Auraframe:RegisterEvent("UNIT_AURA");
  59. Auraframe:SetScript("OnEvent", function(self, event, ...)
  60. --  if AuraUtil.FindAuraByName("Reflecting Prism", "player") then
  61.     if AuraUtil.FindAuraByName("Arcane Intellect", "player") then -- detect the buff has been applied
  62.         self:SetScript("OnUpdate", MyOnUpdate) -- start the timer
  63.     end
  64. end)
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-06-20 at 03:55 PM.
  Reply With Quote