12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 25 ■ Taking Protected Action in Combat 489with “_on“; that is, if triggered by a change to the state-unitexists attribute,it looks <strong>for</strong> a snippet to h<strong>and</strong>le that attribute in the _onstate-unitexistsattribute. Instead <strong>of</strong> the raw name <strong>and</strong> value arguments, it calls that snippetwith the stateid argument, which is the name <strong>of</strong> the changed attribute minusthe “state-“ portion, <strong>and</strong> the newstate argument, which is the same as value.That is, if the state h<strong>and</strong>ler was triggered by a change in the state-unitexistsattribute, the stateid argument will be “unitexists“.To see one rather remarkable way you can use SecureH<strong>and</strong>lerStateTemplate, enter the following block into a fresh page in-game (if you don’thave a priest to test this with, substitute spells or items appropriate to yourcharacter):local self = AvatarCaster or CreateFrame(“Button“, “AvatarCaster“, inil, “SecureActionButtonTemplate,SecureH<strong>and</strong>lerStateTemplate“)self:Hide()self:SetAttribute(“_onstate-mouseover“, [[if newstate == “exists“ thenlocal name = self:GetName()self:SetBindingClick(false, “SHIFT-BUTTON1“, name, “shift1“)self:SetBindingClick(false, “CTRL-BUTTON1“, name, “ctrl1“)self:SetBindingClick(false, “SHIFT-BUTTON2“, name, “shift2“)self:SetBindingClick(false, “CTRL-BUTTON2“, name, “ctrl2“)elseself:ClearBindings()end ]])RegisterStateDriver(self, “mouseover“, i“[target=mouseover,exists] exists; noexists“)self:SetAttribute(“unit“, “mouseover“)self:SetAttribute(“type“, “spell“)self:SetAttribute(“*spell-shift1“, “Power Word: Fortitude“)self:SetAttribute(“*spell-shift2“, “Power Word: Shield“)self:SetAttribute(“*spell-ctrl1“, “Flash Heal“)self:SetAttribute(“*spell-ctrl2“, “Renew“)Run this script once you’ve finished it. Try holding down Shift or Control<strong>and</strong> clicking various character or monster avatars in the game-world display;observe how spells are cast on them directly without changing your target.Now, you can break down how it works.The frame is created from a combination <strong>of</strong> SecureActionButtonTemplate(so that it can actually cast spells) <strong>and</strong> SecureH<strong>and</strong>lerStateTemplate (so thatit can respond to changes in the game state). The AvatarCaster or portionsimply prevents you from creating a new frame if you need to run the scriptmore than once, such as by making an error in the script the first time. The

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!