WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Secureactionbuttontemplate with a variable attribute (https://www.wowinterface.com/forums/showthread.php?t=58535)

Jamien 01-08-21 07:45 PM

Secureactionbuttontemplate with a variable attribute
 
I've made a quick WeakAura for tracking buffs/debuffs for myself and the other tank in our raid, with a button that pops up on Readycheck if there is no focus.
Left clicking the button targets the other tank, right click focuses.

At present I have this (which works fine, but only on our mains):

Code:

local region = aura_env.region
local b = CreateFrame("Button", "FocusBtn", region, "SecureActionButtonTemplate")
b:RegisterForClicks("LeftButtonUp","RightButtonUp")
b:SetAllPoints(region)

if UnitName("player") == "Niian" then
    b:SetAttribute("*type1", "macro")
    b:SetAttribute("macrotext", "/target Aswm")
end

if UnitName("player") == "Aswm" then
    b:SetAttribute("*type1", "macro")
    b:SetAttribute("macrotext", "/target Niian")
end

b:SetAttribute("*type2","focus")

I can easily enough scan through the raid and create a variable with the name of the other tank, but is there a way that I can then use this variable in a secureactionbuttontemplate button? I've tried a few times but haven't been able to get it to work.
Thanks!

SDPhantom 01-09-21 01:44 AM

You can just call button:SetAttribute() again when you need to update it. This can't be done during combat however.

For example:
Lua Code:
  1. local button=CreateFrame("Button",nil,aura_env.region,"SecureActionButtonTemplate");
  2. button:RegisterForClicks("LeftButtonUp","RightButtonUp");
  3. button:SetAllPoints(aura_env.region);
  4.  
  5. button:SetAttribute("*type1","target");
  6. button:SetAttribute("*type2","focus");
  7. button:SetAttribute("unit","none");--   Special UnitID for "no unit"
  8.  
  9. button:RegisterEvent("PLAYER_ROLES_ASSIGNED");
  10. button:RegisterEvent("GROUP_ROSTER_UPDATE");
  11. button:RegisterEvent("RAID_ROSTER_UPDATE");
  12. button:RegisterEvent("PLAYER_REGEN_ENABLED");
  13. button:SetScript("OnEvent",function(self)
  14.     if not InCombatLockdown() then--    Can't update in combat
  15.         local unit="none";
  16.         if IsInRaid() then
  17.             for i=1,MAX_RAID_MEMBERS do
  18.                 local raidunit="raid"..i;
  19.                 local raidid=UnitInRaid(raidunit);--    Unit-to-ID mappings aren't guaranteed
  20.                 if raidid and not UnitIsUnit(raidunit,"player") and (select(10,GetRaidRosterInfo(raidid))=="maintank" or UnitGroupRolesAssigned(raidunit)=="TANK") then
  21.                     unit=raidunit; break;
  22.                 end
  23.             end
  24.         end
  25.         self:SetAttribute("unit",unit);
  26.     end
  27. end);

Jamien 01-09-21 03:05 AM

Thank you very much!
I'll have a look at this soon (once I'm done smashing my face against Torghast)


All times are GMT -6. The time now is 04:32 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI