PDA

View Full Version : SecureUnitButtonTemplate and casting spells


Aeldra
11-11-2006, 06:41 AM
On TBC I try to create a button, what cast a spell. The Problem is, it does not cast it. I get the message that it passes the right code inside the "Perclick" function, but nothing happens.
It would be great if sombody could help me.

XML file
<Button name="KeyButton" inherits="SecureUnitButtonTemplate" parent="UIParent" toplevel="true" hidden="false" frameStrata="LOW" enableMouse="true" movable="true">
<NormalTexture file="Interface\Icons\Spell_Nature_Purge"/>
<Size>
<AbsDimension x="32" y="32"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="0" y="100" />
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
this:RegisterForDrag("LeftButton");
this:SetScript("PreClick", OnPreClick);
this.title = this:CreateFontString(nil, "OVERLAY");
this.title:SetFontObject("GameFontNormal");
this.title:SetAllPoints(this);
this.title:SetText("Cast");
</OnLoad>
<OnMouseUp>
this:StopMovingOrSizing();
</OnMouseUp>
<OnDragStart>
this:StartMoving();
</OnDragStart>
<OnDragStop>
this:StopMovingOrSizing();
</OnDragStop>
</Scripts>
</Button>

LUA file
function OnPreClick(self)
local s = "PreClick ";
local spell, unit = GetBuffOnUnit();
if (spell and unit) then
self:SetAttribute("type", "spell");
self:SetAttribute("unit", unit);
self:SetAttribute("spell", spell);
s = s .. "set: " .. unit .. " -> " .. spell;
else
self:SetAttribute("type", nil);
self:SetAttribute("unit", nil);
self:SetAttribute("spell", nil);
self:SetAttribute("useparent-unit", true);
s = s .. "reseted";
end
AddMsg(s);
end