WoW:USERAPI EquipItemByLink: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
m (Move page script moved page USERAPI EquipItemByLink to USERAPI EquipItemByLink without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{userfunc}}
{{userfunc}}
__NOTOC__
Equips the first matching item found in the player's bags (including the bank and bank bags).


Equips the first matching item found in the player's bags.
Checks the bank first, then carry-ons, then bank bags.


  local function EquipItemByLink(link)
  local function EquipItemByLink(link)
for bag=0,4 do
  for bag=BANK_CONTAINER, NUM_BAG_SLOTS+NUM_BANKBAGSLOTS do
for slot=1,GetContainerNumSlots(bag) do
    for slot=1,GetContainerNumSlots(bag) do
local item = GetContainerItemLink(bag, slot)
      local item = GetContainerItemLink(bag, slot)
if item and item == link then
      if item and item == link then
if CursorHasItem() or CursorHasMoney() or CursorHasSpell() then ClearCursor() end
        if CursorHasItem() or CursorHasMoney() or CursorHasSpell() then ClearCursor() end
PickupContainerItem(bag, slot)
        PickupContainerItem(bag, slot)
AutoEquipCursorItem()
        AutoEquipCursorItem()
return true
        return true
end
      end
end
    end
end
  end
  end
  end

Latest revision as of 04:49, 15 August 2023

This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions

Equips the first matching item found in the player's bags (including the bank and bank bags).

Checks the bank first, then carry-ons, then bank bags.

local function EquipItemByLink(link)
  for bag=BANK_CONTAINER, NUM_BAG_SLOTS+NUM_BANKBAGSLOTS do
    for slot=1,GetContainerNumSlots(bag) do
      local item = GetContainerItemLink(bag, slot)
      if item and item == link then
        if CursorHasItem() or CursorHasMoney() or CursorHasSpell() then ClearCursor() end
        PickupContainerItem(bag, slot)
        AutoEquipCursorItem()
        return true
      end
    end
  end
end