World of Warcraft Lua - Changing frame:SetAttribut

2019-08-08 21:08发布

I'm working on an addon for World of Warcraft that completely overhauls the interface to adapt to my play style.

In this addon, I would like to have a large button that acts as a "main dps rotation" for my mage. I would like it to change what spell it casts based on what is optimal at any given time. It doesn't cast the spell automatically, it just presents the next best option for the user.

Here is my code so far:

print "Interface Overhaul : LOADED"
heatingUpIsActive = false
print(heatingUpIsActive)

local Button = CreateFrame("Button", "MyButton", UIParent,"SecureActionButtonTemplate")
Button:SetWidth(256)
Button:SetHeight(256)
Button:SetFrameStrata("HIGH")
Button:SetPoint("LEFT")
Button:SetText("Main Rotation")
Button:RegisterForClicks("AnyUp")
Button:SetAttribute("type", "spell")
Button:SetAttribute("spell", "Fireball")

Button:RegisterEvent("UNIT_AURA");
local function auraGained(self, event, ...)

    if (UnitAura("player", "Heating Up")) then
             if (heatingUpIsActive == false) then
             heatingUpIsActive = true
             print (heatingUpIsActive)
             print ("Heating Up is active!")
             Button:SetAttribute("spell", "Inferno Blast")
             end
            else
             heatingUpIsActive = false
             print("Heating Up is NOT active.")
             print(heatingUpIsActive)
    end
end
Button:SetScript("OnEvent", auraGained);

local tex = Button:CreateTexture("ARTWORK");
tex:SetPoint("LEFT")
tex:SetWidth(256)
tex:SetHeight(256)
tex:SetTexture("Interface\\AddOns\\InterfaceOverhaul\\Button2")

If heatingUpIsActive == true, I would like the button to cast ("spell", "Inferno Blast") instead of ("spell", "Fireball"), but it doesn't work if I place that into the correct part of the if statements.

Any thoughts?

1条回答
家丑人穷心不美
2楼-- · 2019-08-08 21:32

As Mud said, you cannot rebind buttons in combat anymore. Blizzard made this change to prevent bots from being able to automate combat. Notably, in order to cast a spell you need to use one of the secure templates, and these secure templates only allow modification of the attributes that control what they do when you're not in combat. So you cannot have one button change spells mid-combat. Similarly, they also prevent you from modifying attributes like their position or visibility, so you cannot move buttons under the mouse either.

The best you can do is display a visual indicator of what spell should be cast, but rely on the user to actually press the correct button.

查看更多
登录 后发表回答