Thread Tools Display Modes
06-22-06, 10:29 AM   #1
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
TargetNearestEnemy() doesn't?

Hi there. I'm playing with some lua that cycles through enemies looking for a certain debuff. However I'm running into problems with the cycling bit...

If I stand in a spot and tab through targets, I get different results than if I run /script TargetNearestEnemy(). In some cases, a mob standing right in front of me will never target with TargetNearestEnemy() though tab will catch it. Is there something else I need to do like clear the target inbetween calls?

Thanks...
  Reply With Quote
06-22-06, 11:35 AM   #2
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Unless you're running some strange custom AddOn, you're likely mistaken, I say this because Tab is bound to the TARGETNEARESTENEMY binding, and that's defined as:

<Binding name="TARGETNEARESTENEMY" header="TARGETING">
TargetNearestEnemy();
</Binding>
  Reply With Quote
06-22-06, 11:56 AM   #3
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
Hmm, I'll have to test it again. What I did was position myself so that tab went back and forth between 2 mobs. Then I started running /script TargetNearestEnemy() and the target didn't change. I'll have to disable all my other addons on try a clean test I guess...
  Reply With Quote
06-22-06, 12:28 PM   #4
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
I found this in the patch notes for 1.7:
"TargetNearest* script functions will only work in response to a button click or a key binding, to discourage addons which scan the battlefield for targets."

Seems like that explains my issue.
  Reply With Quote
06-22-06, 03:55 PM   #5
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
Hitting enter to execute a command in the ChatBox counts as a hardware event as of 1.10. Clicking on a macro always has.
  Reply With Quote
06-22-06, 04:06 PM   #6
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
Good to know. I'll have to retest in-game then...

Out of curiousity, what is considered a 'hardware' or 'key-press' event in an addon? For instance, if I click a button in an addon gui and that calls functions in my addon, is the code within those functions considered within a hardware event?
  Reply With Quote
06-22-06, 06:33 PM   #7
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
Functions triggered by a keybinding (when called because of the bound key being pressed), those called from a Button's OnClick (when you have clicked the button with your mouse) event handler and script called when you press enter on the ChatBox are considered hardware events.
  Reply With Quote
06-22-06, 07:40 PM   #8
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
Interesting. So I did more testing and the difference I was seeing between tabbing and typing /script TargetNearestEnemy() was simply the timeout before the tab cycle is reset. If I hit tab , wait 10-15 secs, then hit tab again my target does not change.

I wrote the following macro:
/script for i=1,10 do TargetNearestEnemy(); DEFAULT_CHAT_FRAME:AddMessage(UnitName("target")); showAllUnitDebuffs(); end

where showAllUnitDebuffs() is:
function showAllUnitDebuffs()
local i = 1
while (UnitDebuff("target", i)) do
DEFAULT_CHAT_FRAME:AddMessage(UnitDebuff("target", i));
i = i + 1;
end
end

and that all works great if I run it by putting the macro in the toolbar.

Now, however, standing in the same spot and using:
<OnMouseDown>
SearchTargetMob()
</OnMouseDown>

where SearchTargetMob() is doing the same for loop as the macro, it looks like my target isn't switching. I had 3 mobs in my tab cycle, 1 with a unique name, and I could see in the output that the unique named mob was never getting targetted.

Any ideas why this behavior is different within my addon?
  Reply With Quote
06-23-06, 03:19 AM   #9
dafire
Premium Member
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 216
I guess you need a hardware event for every call of the function so you can't loop through targets with just one keypress.

It was blizzards intention to break addons that scan several targets to find out and target the weakest for example ..

Last edited by dafire : 06-23-06 at 03:22 AM.
  Reply With Quote
06-23-06, 10:20 AM   #10
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
The OnMouseDown and OnMouseUp events are NOT hardware events. The only mouse click event handler that is considered to be a hardware event is OnClick which only buttons and CheckButtons are allowed to have.

Last edited by Esamynn : 06-23-06 at 10:24 AM.
  Reply With Quote
06-23-06, 12:18 PM   #11
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
Gotycha, I'll try OnClick and see if that works.

Thanks for all the help!
  Reply With Quote
06-23-06, 07:10 PM   #12
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
Yet another question (I actually am trying to find answers on wowwiki and the like before I post, I swear)...

Does the 'Frame' widget actually trigger OnClick events? I noticed you can't do a RegisterForClick() on it. Just wondering, I can always just add a button to the frame...
  Reply With Quote
06-26-06, 11:12 AM   #13
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
Only the "Button" type and its derivative the "CheckButton" are allowed to have OnClick handlers. (They are also the only types that support :RegisterForClick())
  Reply With Quote
06-26-06, 12:05 PM   #14
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by dafire
I guess you need a hardware event for every call of the function so you can't loop through targets with just one keypress.
Unless they changed something and didn't tell us in 1.11, it does NOT have that level of restriction.

It was blizzards intention to break addons that scan several targets to find out and target the weakest for example ..
The intention was to break those that did this constantly via a timer or event trigger. They dont mind you hitting a key to scan through.
  Reply With Quote
06-26-06, 12:32 PM   #15
madtiller
A Murloc Raider
Join Date: Dec 2005
Posts: 8
I changed my tests around over the weekend to have my routine triggered by a keypress using hotkeys and it works great. I guess if I want an actual ui for the addon, I'll simply have to create a button so I can use the OnClick event.

Thanks all!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » TargetNearestEnemy() doesn't?


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