Thread Tools Display Modes
01-08-21, 07:45 PM   #1
Jamien
A Defias Bandit
Join Date: Jan 2021
Posts: 2
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!
  Reply With Quote
01-09-21, 01:44 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 01-09-21 at 01:49 AM.
  Reply With Quote
01-09-21, 03:05 AM   #3
Jamien
A Defias Bandit
Join Date: Jan 2021
Posts: 2
Thank you very much!
I'll have a look at this soon (once I'm done smashing my face against Torghast)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Secureactionbuttontemplate with a variable attribute

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off