Macros: Essential Information

This is a “how-to” guide, not a history lesson. Historical API changes, while interesting in their own right, are not relevant for the purpose of this guide.

If you can provide any current examples (current meaning exists in game as of 8.0, not necessarily related to BfA content), I am happy to amend that portion. Otherwise, it stands as is - the commands are functionally identical, in that they are used the same way and the result (i.e. what action is taken by the player) is the same regardless of which command you use.

Again, happy to modify this if you can provide examples. /run executes the code that follows the same as if that code was dropped in an addon.lua file, properly called by a .toc file, and there was a command or event to execute the code at the given time.

Circumventing the character limit with /click chains does not remove the 255 character limit per statement. You can’t pass vars between macros, even /click chained macros, so the point stands.

This is also way more in depth than I want to go here - this is meant to be comprehensive information about macros, not about scripting in Lua.

I will definitely add /click to the slash command section, as it ought to be covered.

Will do, this was an oversight.

An oversight - see above.

I will make a note of that. When I have more time, I will pull a listing and include them all, but for now I will just link to your post.

CastRandom, UseRandom, and CastSequence Silliness

/castrandom SharedNameBetweenItemAndSpell,SomeSpell,SomeItem

That will make use of the ITEM preferentially in the first step, not the spell.

The handler for /userandom literally is just a pointer to the handler for /castrandom as you can see from lines 1246 to 1258 of ChatFrame.lua:

SecureCmdList["CASTRANDOM"] = function(msg)
    local actions, target = SecureCmdOptionParse(msg);
  if ( actions ) then
    local action = ExecuteCastRandom(actions);
    local name, bag, slot = SecureCmdItemParse(action);
    if ( slot or GetItemInfo(name) ) then
      SecureCmdUseItem(name, bag, slot, target);
    else
      CastSpellByName(action, target);
    end
  end
end
SecureCmdList["USERANDOM"] = SecureCmdList["CASTRANDOM"];

/castsequence makes preferential use of items over spells or abilities as well.

The portion of the handler that manages this is lines 998 to 1021 of ChatFrame.xml:

  -- Execute the sequence!
  local item, spell = entry.items[entry.index], entry.spells[entry.index];
  if ( item ) then
    local name, bag, slot = SecureCmdItemParse(item);
    if ( slot ) then
      local spellID;
      if ( name ) then
        local spellName;
        spellName, spellID = GetItemSpell(name);
        spell = strlower(spellName or "");
      else
        spell = "";
      end
      entry.spellNames[entry.index] = spell;
      entry.spellID[entry.index] = spellID;
    end
    if ( IsEquippableItem(name) and not IsEquippedItem(name) ) then
      EquipItemByName(name);
    else
      SecureCmdUseItem(name, bag, slot, target);
    end
  else
    CastSpellByName(spell, target);
  end

I haven’t been able to determine a consistent pattern for #showtooltip as it seems to give different results for item or spell/ability in different situations and I haven’t located the code that governs it (it may not be visible to use).

Do you have any example where the /use vs /cast issue is relevant? Any items and spells that share a name and could conceivably both be usable by the same character at the same time?

When I say functionally identical, I mean they perform the same function in the same way. Which they do.

You seem to be missing the point of this guide: a quick, easy to digest write-up of some of the most common macro questions that come in this forum on a day to day basis. I’m not writing scripting guide, or a dissection of chatframe.lua, that is way outside scope for what I am trying to do here.

1 Like

I haven’t noticed anything in BFA yet but in Legion DKs had both a Horn of Winter item and talent.

1 Like

You could just adjust the TargetPriorityPvp CVar instead:
1 - default
2 - prioritize all pvp targets
3 - prioritize players only

/run SetCVar("TargetPriorityPvp", 3)

Has no effect outside of PVP so there’s no need to unset it.

Changelog 20181118:

  • Added [this, and that] vs [this][or that] explanation. (Elvenbane)
  • Clarified /use vs /cast. (Ehiztari)
  • Added explanation of /click. (Ehiztari)
  • Added script to dump all valid /commands to Tips and Tricks. (Ehiztari)
  • Removed outdated PvP tab targeting tip, instead use the TargetPriorityPvp CVar (Elvenbane)
2 Likes

That looks very good, @Adreaver. Thank you for making the updates and for putting the time in to create this.

I deleted all of my conversational posts from the thread except one that seemed to offer relevant data for those wishing to dig deeper and I edited it to be a stand-alone post.

2 Likes

I thought /userandom was still broken? Have I missed something, cause my random mount macros are still not working (they summon a new mount only after a reload)

It is, as far as I am aware.

1 Like

@adreaver can you help me make a macro. i would say its a rather long one

With Classic now being a thing, I’m going to add a section to the guide on spell ranks and how (and why) to use them.

TL;DR until I have it tested thoroughly and written up:

  • /cast Spell will attempt to cast the highest possible rank.
  • /cast Spell(Rank #) will attempt to cast the specified rank.

I recommend using this macro:

#showtooltip
/cast Spell

for all your primary spells while leveling - this will automatically update when you learn new ranks without you having to remember to drag the higher rank spell on to your action bars.

1 Like

Remove the space between spell and rank or it won’t function properly.

/cast Spell(Rank #)

1 Like

um, anyone have a macro for classic so it will either dispel magic/cure disease into one button on a priest? i don’t want it to be mouse over. just those two so i can cut down on hotkeys for pve.

Not possible without modifiers.

no i am willing to press the button twice for both actions. ie dispell magic, if no dispell then cure disease. i have seen similar macros but they all have mouse over commands in them, i don’t want those.

ie. #showtooltip
/cast [mod:alt] !Mass Dispel; [spec:3,@mouseover,help,nodead] Purify Disease; [@mouseover,help,nodead] Purify; [@mouseover,harm,nodead] [harm] Dispel Magic; [spec:3] Purify Disease; Purify

Not possible, see above. The macro you used as an example, which I wrote, doesn’t apply because the spells function differently in Classic than they do in Retail.

lame. guess i will just try classic decursive addon instead. thanks for the response.

Let me ask here, Macro pros.

Can’t use /targetenemy or /targetenemyplayer

The scenario
A group of mobs, or players. You tab target a mob in the distance, yet there is a mob right in front of you. You go to attack that close mob but realize your target is stuck on the far mob.

Using //cleartarget, can you add any modifier that one the press of the macro it figures out that far mob IS NOT ATTACKING YOU and clears that target allowing you to attack the mob right next to you?

/cleartarget
/startattack
/cast sinister strike

The above will clear that far mob, but once you attack your mob next to you, on each successive attack it clears your target you are attacking and retargets it, clear/retarget, until its dead.

If /cleartarget can be modded to understand not to clear if target is attacking you, i’d be golden.

Possible?