Macro that targets only enemies in combat

Macro that targets only enemies in combat - Top view of various multicolored toys for fight arranged on pink background as representation of game

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.




Pictures about "Macro that targets only enemies in combat"

Macro that targets only enemies in combat - Man in  Camouflage Army Uniform Holding Rifle
Macro that targets only enemies in combat - Soldier Holding Black Assault Rifle
Macro that targets only enemies in combat - Photo of Man Wearing Green Combat Uniform Holding Rifle



How do you make a target macro wow?

This performs a search for all nearby units whose name begins with name. If multiple targets correspond to the given name, this will select the nearest of the targets. The macro will only select the player himself if no other targets match the given name.



Automatically Target Enemies or Friendlies with Reticle-Based Spells Using Macros




More answers regarding macro that targets only enemies in combat

Answer 2

Added some correctness to Jutschge's answer ;)

/run local a=0;TargetNearestEnemy();while (UnitAffectingCombat("target")~=true and a < 10) do TargetNearestEnemy();a=a+1;end

I added a try number limit to 10 too, to avoid infinite loop.

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Anna Shvets, Kony Xyzx, Lukas, Lukas