View Single Post
11-16-07, 01:09 PM   #1
mexicaan
A Kobold Labourer
Join Date: Apr 2007
Posts: 1
Setting target in a SecureUnitButtonTemplate

Hey,

This is my first post on this forums and I'm looking for help.
I have a button (SecureUnitButtonTemplate). I have added a console command that as soon as entered will set the target on the button to the player's target.

the XML:
Code:
<Button name="$parent_unitFrame1" inherits="SecureUnitButtonTemplate" hidden="false">
	<Size x="100" y="30"/>
	<Backdrop edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
		<EdgeSize>
			<AbsValue val="16"/>
		</EdgeSize>
		<TileSize>
			<AbsValue val="16"/>
		</TileSize>
		<BackgroundInsets>
			<AbsInset left="5" right="5" top="5" bottom="5"/>
		</BackgroundInsets>
	</Backdrop>
	<Anchors>
		<Anchor point="TOPLEFT">
			<Offset x="10" y="-5"/>
		</Anchor>
	</Anchors>
</Button>
the LUA:
Code:
--
-- Initialize the addon. Set unitframe attributes and enable console commands
--
function DotFrames_OnLoad(self)
	self:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
	self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);

	DotFrames_unitFrame1:SetAttribute("*type1", "target");
	--DotFrames_unitFrame1:RegisterForClicks("AnyUp");
	
	SLASH_DOTFRAMES1 = "/dotframes";
	SLASH_DOTFRAMES2 = "/df";
	SlashCmdList["DOTFRAMES"] = DotFrames_Command;
end

--
-- Set the unit frame targets
--
function DotFrames_Command(cmd)
	local cmdValues = strsplit(" ", cmd);

	if InCombatLockdown() ~= nill then
		return;
	end
	
	if(cmdValues[1] == "settarget") then
		local number = tonumber(cmdValues[2]);
		
		-- Make sure it's in range
		if(number > 0 and number < 6) then
			if(number == 1) then
				DotFrames_unitFrame1:SetAttribute("unit", "target");
				DEFAULT_CHAT_FRAME:AddMessage("DotFrames: target 1 set to: "..UnitName("target"));
			end;
		end
	end
end
Right now, the console command is succesfully triggered and a chat message is Shown, for example: DotFrames: target 1 set to: FeralDragonhawk Hatchling. However the button when clicked does _Not_ target the unit. What'r wrong?

PS: It might be worth noting that when I change:
Code:
DotFrames_unitFrame1:SetAttribute("unit", "target");
to:
Code:
DotFrames_unitFrame1:SetAttribute("unit", "player");
The button does succesfully target myself when I click on it.

Thanks in advance.
  Reply With Quote