WoW:Item equipping

Basics

/script PickupContainerItem(bag, slot)

Bags count from 0 to 4 from the right, 0 being your backpack and 4 being your leftmost pack. Slots are numbered starting at the topmost, leftmost slot and counting left to right, top to bottom. For example, a 10-slot pack is numbered like this:

X X 1 2
3 4 5 6
7 8 9 10

To access the first slot on the rightmost bag, the script would be /script PickUpContainerItem (4, 1);

The basic command works like this:

  • If no item in cursor:
    • If item in bag:slot - picks up the item and puts it on the cursor.
    • If no item in bag:slot - does nothing
  • If item on cursor
    • If item in bag:slot - switches the item in the bag:slot with the one on the cursor.
    • If no item in bag:slot - puts down item from cursor into bag:slot

/script PickupInventoryItem(inventorySlot)

Picks up/puts down/switches item into the specified slot.

See InventorySlots for ids and mappings.


Better method:

/script UseContainerItem(bag, slot);

Will automatically equip the item referenced by bag,slot, placing any existing already equipped item in the bag slot.


Yes, this is undoubtedly easier... until you start dealing with dualwielding. At which point UseContainerItem stops being nice. -- Sarf


Please be very careful when using the UseContainerItem(bag,slot) command. If you are talking to a vendor and use this macro (assuming no safety measures in the script) then all your macro items will be sold. Just managed to sell 7 items to a vendor. Fortunately, I was able to retrieve the last item and blizzard restored the other equipment items for me.


For those of us that are prone to doing this you can do a check to see if you are interacting with an NPC. example weaponswap(2H <-> 1H/OH):

/script TargetUnit("npc"); 
if ( UnitName("target") == nil or not UnitIsUnit("target","npc") ) 
then 
  if ( not CursorHasItem() ) then
    PickupInventoryItem(offHandInventory);
    PickupContainerItem(offHandBag,offHandSlot);
    UseContainerItem(mainHandBag,mainHandSlot);
    UseContainerItem(offHandBag,offHandSlot);
  end
end

-- Trinkit


The best method for ensuring that you do not accidentally sell anything to a vendor is:

/script CloseMerchant();

The aforementioned if-then script can still fail if you are in a vendor window and target another entity, whereas the CloseMerchant script will always close any merchant window. It's also much shorter, so you can fit more lines of item swapping into the character-limited macro box. --TheRayven

Multiple commands

There is a problem when executing multiple Pickup commands because they execute instantaneously on your client, which is not always synched with the server.

Therefore, follow these simple guidelines:

  1. Check if the cursor has an item on it and execute all your pickup commands on the same line.
    Example:
    if ( not CursorHasItem() ) then PickupContainerItem(...); ... end
  2. Pickup items once, and drop them once for one macro.

Good luck!


Weapon swapping scripts

NOTE: When copying the scripts, make sure they end up on ONE line. Also, you will NEED to change the offhandBag, offhandBagSlot and mainhandBag, mainhandBagSlot names to actual numbers, as the scripts will NOT fit in a macro as it is.

From mainhand/offhand to mainhand/offhand

Script to swap items in both hands to other items in both hands. offhandBag, offhandBagSlot and mainhandBag, mainhandBagSlot need to be specified (duh).

/script if ( not CursorHasItem() ) then PickupContainerItem(mainhandBag, mainhandBagSlot); PickupInventoryItem(16); PickupContainerItem(mainhandBag, mainhandBagSlot); PickupContainerItem(offhandBag, offhandBagSlot); PickupInventoryItem(17); PickupContainerItem(offhandBag, offhandBagSlot); end

From mainhand to mainhand/offhand

Script to switch from item in main hand to other items in both hands. offhandBag, offhandBagSlot and mainhandBag, mainhandBagSlot need to be specified (duh). Weapon in main hand will end up in mainhandBag, mainhandBagSlot.

/script if ( not CursorHasItem() ) then PickupContainerItem(mainhandBag, mainhandBagSlot); PickupInventoryItem(16); PickupContainerItem(mainhandBag, mainhandBagSlot); PickupContainerItem(offhandBag, offhandBagSlot); PickupInventoryItem(17); if ( CursorHasItem() ) then PickupContainerItem(offhandBag, offhandBagSlot); end end

From mainhand/offhand to mainhand

Script to switch from items in both hands to one item in the main hand. offhandBag, offhandBagSlot and mainhandBag, mainhandBagSlot need to be specified (duh). Weapons will end up on the slots specified.

/script if ( not CursorHasItem() ) then PickupInventoryItem(17); if ( CursorHasItem() ) then PickupContainerItem(offhandBag, offhandBagSlot); end PickupContainerItem(mainhandBag, mainhandBagSlot); PickupInventoryItem(16); PickupContainerItem(mainhandBag, mainhandBagSlot); end

From mainhand to mainhand

Script to switch from item in main hand to another item in the main hand. mainhandBag, mainhandBagSlot need to be specified (duh). The equipped weapon will end up on mainhandBag, mainhandBagSlot.

/script if ( not CursorHasItem() ) then PickupContainerItem(mainhandBag, mainhandBagSlot); PickupInventoryItem(16); PickupContainerItem(mainhandBag, mainhandBagSlot); end

With Cosmos

If you are using Cosmos, you can use the following commands :

/saveset <Number>
/loadset <Number>