Thread Tools Display Modes
02-04-14, 03:07 PM   #1
urbley
A Deviate Faerie Dragon
Join Date: Feb 2014
Posts: 10
Question Target NPC

Hi everyone,

This is my first thread here so forgive me if it's in the wrong section. I've been a WoW player for a long time and have always enjoyed writing little macros to make life easier but I've never really been compelled (until now) to dive into addons.

I guess there really hasn't been a need to as the likes of Curse pretty much has everything we need for day to day playing. Or so I thought.... I won't waffle though. On to business.

We have an alt raid group banging through SoO flex and always seem to have a problem on Nazgrim. It's the add priority of course. A combination of dodging the ravagers, the yellow **** on the ground and trying to pick out those shamans is a real pain. I'm sure you all know the score :P

I started writing out a little macro to check for each add by name, target it and set a raid icon i.e.

Code:
/target [@Kor'kron Warshaman,nodead] Kor'kron Warshaman; SetRaidTarget("target", 8)
but ran out of characters to cover all the permutations of the adds that can spawn.

So now I've been looking at an addon as an alternative. I was devastated to discover that the one api function that would make this all possible for me, TargetUnit, is protected

I've seen mentions here and there regarding using a "secure frame" to achieve this but unfortunately I haven't been able to find a working example or any other references. Obviously I wouldn't expect any of you to write it out for me but unfortunately my ninja Google skills are letting me down on this occasion and would really appreciate a little direction. Has anyone seen this or something similar?

If you've taken the time to read this I hope you enjoyed the read and really appreciate any help you can offer

Edit: Sorry I forgot to mention. If this has been covered elsewhere on the forums and I've simply failed to find it, massive apologies.
  Reply With Quote
02-04-14, 03:27 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Getting easy-to-understand documentation on how to make a "secure" macro in Lua is not easy, so here we go:
Same macro as the one you provided, written in Lua

Lua Code:
  1. local button = CreateFrame("Button", "MyButton", UIParent, "SecureActionButtonTemplate")
  2. button:Hide()
  3. button:SetAttribute("type", "macro")
  4. button:SetAttribute("macrotext", "/target [@Kor'kron Warshaman,nodead] Kor'kron Warshaman; SetRaidTarget('target', 8)")

Now you can make a new macro (ingame) that does this:
Code:
/click MyButton
  Reply With Quote
02-04-14, 04:09 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, the syntax in your macro is not quite correct -- you can't add arbitrary Lua code on a /target line; you need a second line beginning with /run. Here's a better way to write that:

Code:
/cleartarget
/targettexact Kor'kron War Shaman
/run SetRaidTarget("target", 8)
/targetlasttarget
This will (1) clear your current target, (2) target the Kor'kron War Shaman, but not target anything else with a similar name if it's not spawned, (3) set an icon on your current target, which will do nothing if you didn't successfully target the shaman, and (4) go back to your previous target.

Other than that, as I'm not familiar with the fight in question, I'm not entirely clear on what you're actually looking to do, overall. You mention that you ran out of space in your macro, but the example you posted is nowhere near the 255 character limit. Without more details I can't really offer any advice on how to write an addon to solve the problem.

If there are multiple adds, and you want to mark each with a different icon, your boss mod (assuming you're using one) may already have options to do that, or you could also try one of the automatic marking addons that already exist, such as MagicMarker.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-04-14, 04:59 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You can give my addon priority Target a try.
It was made for exactly those types of scenarios and you can customize / create priority lists so you can adapt it to your needs.
  Reply With Quote
02-04-14, 06:58 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Following Phanx, if you want to use that macro in my example, you have to use \n instead of newlines, like so:

Lua Code:
  1. button:SetAttribute("macrotext", "/cleartarget\n/targettexact Kor'kron War Shaman\n/run SetRaidTarget('target', 8)\n/targetlasttarget")
  Reply With Quote
02-04-14, 07:40 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can also use [[ double square brackets ]] to form a literal string.

Code:
button:SetAttribute("macrotext", [[
/cleartarget
/targettexact Kor'kron War Shaman
/run SetRaidTarget("target", 8)
/targetlasttarget]])
Apparently the forum's Lua highlighting doesn't recognize this syntax -- tsk tsk Dolby! -- so here is some manual highlighting.

Anyway, this is often more convenient for writing multi-line strings than mashing it all together, using the \n escape code, and escaping quotation marks or replacing them with single quotes. Literal strings don't interpret escape codes (so you can't use \n inside one) and the first linebreak is ignored if it's the first character in the string, so the above example doesn't actually start with a blank line.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-05-14, 01:19 PM   #7
urbley
A Deviate Faerie Dragon
Join Date: Feb 2014
Posts: 10
Thanks for the replies everyone. Seen them this morning but was in work so I've been dying to get home and give this a try all day

I'll let you all know how it goes.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Target NPC


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