Thread Tools Display Modes
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
11-22-07, 08:13 AM   #2
Teif
A Deviate Faerie Dragon
Join Date: May 2006
Posts: 12
The "player" ID always refers to you, as such it will always target you when you use that. The "target" ID is only valid, when you already have something on target.

the call to setAttribute("unit", "target") does not mean it will store whatever you have on target at that time as the new target for the button. It means that whenever you click/enter the button, it will look at the unit ID behind the identifier "target", meaning whatever you have on target at that time.

Example:

You do /df settarget 1 while you have "Large Boar" on target.
Your AddOn writes: DotFrames: target 1 set to: Large Boar.

You then target a "Venomtail Scorpid" and want to switch back to the boar using your stored target, so you hover over the button.
The button then evaluates the "target" ID and finds, that your current target is Venomtail Scorpid, and that is then set as your new target.

I hope that helped clarify why your code isn't working as you would like it to.

To get it to work I think you'd have to create a number of macros (as many as you want stored targets) and then edit those macros with your console command and having your button trigger the macro instead of targeting. The reason for this is that patch 2.3 introduced the /targetexact command, which does what your mod is trying to do.

You could then do something along the lines of:
Code:
function DotFrames_OnLoad(frame)
   -- setting up the first unit frame button
   DotFrames_UnitFrame1:SetAttribute("type1", "macro")
   DotFrames_UnitFrame1:SetAttribute("macrotext", "/targetexact nil")

   -- set up the other unit frame buttons

   SlashCmdList["DotFrames"] = DotFrames_OnCommand
   SLASH_DotFrames1            = "/dotframes"
   SLASH_DotFrames2            = "/df"
end

function DotFrames_OnCommand(command)
   if (InCombatLockdown()) then return end

   local cmdValues= strsplit(" ", command)
   if (cmdValues[1] == "settarget") then
      local number = tonumber(cmdvalues[2])
      if (number > 0) and (number < 6) then
         -- The number is within the allowed range, edit the macro for this target
         local unitFrame = getglobal("DotFrames_UnitFrame"..number)
         unitFrame:SetAttribute("macrotext", "/targetexact "..UnitName("target"))
      end
   end
end
So going back to the example from earlier we have the situation:

You do /df settarget 1 while you have "Large Boar" on target.
Your AddOn writes: DotFrames: target 1 set to: Large Boar.

the macro stored in your UnitFrame1 button is now: "/targetexact Large Boar"

You then target a "Venomtail Scorpid" and want to switch back to the boar using your stored target 1, so you click the button.

The button fires the macro, which should make you target a "Large Boar" (not necessarily the same Large Boar as before though).

Hope this helped any.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Setting target in a SecureUnitButtonTemplate


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