View Single Post
05-05-20, 06:29 PM   #9
save-disk
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 9
Thanks everybody for the extra pointers, I'm very grateful! Seerah, here is my complete code right now (pardon how ugly my button looks, i'm planning to pretty it up once it all works. I also plan to find the aura by name in that if statement, not just by only having ten seconds remaining.) I put all the suggestions in, to my best ability - it's not working but I'm certain that's just because of a rookie error on my end.

Lua Code:
  1. local button = CreateFrame("Button", "myMacroButton", UIparent, "SecureActionButtonTemplate")
  2.  
  3. frame:RegisterEvent("UNIT_AURA");
  4. local function timeleft(self, event, ...)
  5.  
  6. frame.TimeToCheck = 1 -- check buff timers every second
  7. frame:SetScript("OnUpdate", function(self, elapsed)
  8.     self.TimeToCheck = self.TimeToCheck - elapsed
  9.     if self.TimeToCheck > 0 then
  10.         return -- We haven't counted down to zero yet so do nothing
  11.     end
  12.     self.TimeToCheck = 1 -- We've waited a second so reset the timer
  13.  
  14. for i=1,40 do
  15.         local aura.name, aura.icon, aura.count, aura.type, aura.max_time, aura.end_time, aura.caster, aura.is_stealable = UnitAura("player", i);
  16.         if aura.max_time and aura.max_time > 0 then
  17.         aura.start_time = aura.end_time - aura.max_time;
  18.     elseif aura.end_time and aura.end_time > 0 then
  19.         aura.start_time = GetTime();
  20.         aura.max_time   = aura.end_time - aura.start_time;
  21.     else
  22.         aura.max_time   = nil;
  23.         aura.start_time = nil;
  24.         aura.end_time   = nil;
  25.     end
  26.     return aura.end_time - aura.start_time
  27.    
  28.      if timeleft <= 10 then
  29.     print "test"
  30.     popup()
  31.     end
  32.  end
  33.  end
  34.  
  35.  
  36.     end
  37. end)
  38.  
  39.    
  40.   local function popup()
  41.    
  42.             button:Show()
  43.             PlaySound(1221)
  44.             FlashClientIcon()
  45.             button:SetAttribute("type1", "macro") -- left click causes macro
  46.             button:SetAttribute("macrotext1", "/cast Reflecting Prism")
  47.             button:SetPoint("CENTER", mainframe, "CENTER", 0, 0)
  48.  
  49.        
  50.            button:SetText("Your Reflecting Prism will expire in 1 minute.")
  51.                 button:SetNormalFontObject("GameFontNormalSmall")
  52.        
  53.                 button:SetNormalTexture("Interface/Icons/Inv_jewelcrafting_prism")
  54.                 button:SetHighlightTexture("Interface/ICONS/Spell_nature_wispsplode")
  55.                 button:SetPushedTexture("Interface/Icons/Spell_nature_wispsplode")
  56.    
  57.             button:SetAttribute("type", "spell")
  58.             button:SetAttribute("spell", spell)
  59.             button:SetPoint('CENTER')
  60.             button:SetSize(30, 30)
  61.  
  62.             button:EnableMouse(true)
  63.             button:RegisterForClicks("LeftButtonUp")
  64.             button:SetScript("PostClick", function(self, arg1)
  65.                 print "x"
  66.                 button:Hide()
  67.                 button:SetParent(nil)
  68.                 end)
  69.         end
  Reply With Quote