World-of-warcraft – Macro that targets only enemies in combat

world of warcraft

Is there a way to select only enemies already in combat via macro?

/targetenemy

switches to the next enemy (like the TAB-Key)

As far as I know there is no condition to check if it is in combat.

There is an API call to test it:

affectingCombat = UnitAffectingCombat("unit");

Is this usable in Macros?

Best Answer

You can't use a simple command in macros to check this condition. The only conditional check for whether something is in combat or not is [combat] or [nocombat] and this only checks whether the player is in or out of combat.

You can however call scripts with a macro but of course you'll have an annoying character limit.

The commant /run or /script allows you to execute commands in the WoW scripting language through a macro.

I'm not very familiar with the language itself (maybe you'll find more information on GameDev.SE) but it certainly is possible to achieve this through a macro although it might be more effective to write a small add-on.

Now as I said. I don't know a lot about the WoW scripting language but I could imagine that the macro looks something like this:

/run if UnitAffectingCombat("nearestenemy") == true then TargetNearestEnemy(); end

Here you can find the article of WoWwiki about using scripts in macros.