LibBagUtils-1.0

This project is abandoned and its default file will likely not work with the most recent version of World of Warcraft. Whether this project is out of date or its author has marked it as abandoned, this project is no longer maintained.

Several useful bag related APIs that you wish were built into the WoW API:

  local LBU = LibStub("LibBagUtils-1.0")
  
  for bag,slot in LBU:Iterate("BANK", "Major Healing Potion") do
    LBU:PutItem("BAGS")
  end

:Iterate("which"[, "lookingfor"])

which
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
OPTIONAL: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns an iterator that can be used in a for loop, e.g.:

for bag,slot,link in LBU:Iterate("BAGS") do   -- loop all slots
for bag,slot,link in LBU:Iterate("BAGSBANK", 29434) do  -- find all badges of justice

:Find("where", "lookingfor"[, notLocked])

where
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
itemLink, itemName, itemString or itemId(number)
notLocked
OPTIONAL: if true, will NOT return locked slots
Returns:
bag,slot,link or nil' on failure

Finds the first instance of what you are looking for. To find all, use :Iterate() instead.

:FindSmallestStack("where", "lookingfor"[, notLocked])

where
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
itemLink, itemName, itemString or itemId(number)
notLocked
OPTIONAL: if true, will NOT return locked slots
Returns:
bag,slot,size or nil' on failure

Finds the smallest stack of what you are looking for. To find all, use :Iterate() instead.

:PutItem("where"[, count[, dontClearOnFail]])

The easiest way to move items between bags and bank is of course to simply "click" them, but that doesn't work when you split stacks. That's when this function is handy.

PutItem is ''smart''; it will try to use specialty bags before standard bags. (But it will not try to put e.g. herb bags in herb bags. Doh.)

where
string: "BAGS", "BANK", "BAGSBANK"
count
OPTIONAL: number: if given, PutItem() will attempt to stack the item on top of another suitable stack. This is not possible without knowing the count, so if not given, it will simply be put in an empty slot. Default: nil.
dontClearOnFail
OPTIONAL: boolean: If the put operation fails due to no room, do NOT clear the cursor. Default: false. (Note that some other wow client errors WILL clear the cursor)
Returns:
bag,slot or false for out-of-room.
If called without an item in the cursor, 0,0 will be returned (slot 0 does not exist)

:LinkIsItem(fullLink, lookingfor)

fullLink
string: A full item link as given by WoW APIs
lookingfor
string: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns true if "lookingfor" matches "fullLink". Ignores in-constant info (i.e. level / wobbly 3.2 randomstats) in links.

:MakeLinkComparator("lookingfor")

lookingfor
string: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns a comparator function and two arguments, that can be used to rapidly compare several itemlinks to a set search pattern.

This comparator will

Example:

local comparator,arg1,arg2 = LBU:MakeLinkComparator(myItemString)
for _,itemLink in pairs(myItems) do
  if comparator(itemLink, arg1,arg2) then
    print(itemLink, "matches", myItemString)

:IterateBags("which", itemFamily)

which
string: "BAGS", "BANK", "BAGSBANK"
itemFamily
number: bitmasked itemFamily; will accept binary-OR:ed combinations of itemFamily values. 0 = iterate only regular bags.
nil: iterate ALL bags, including keyring and possible future "special" bags

Returns an iterator that can be used in a for loop, e.g.:

for bag in LBU:IterateBags("BAGS",0) do   -- loop all regular bags

:CountSlots("which", itemFamily)

which
string: "BAGS", "BANK", "BAGSBANK"
itemFamily
number: bitmasked itemFamily; will accept binary-OR:ed combinations of itemFamily values. 0 = iterate only regular bags.
nil: iterate ALL bags, including keyring and possible future "special" bags

Returns numFreeSlots, numTotalSlots. Note that the bank is considered to have 0 slots unless the bank frame is open.

:IsBank(bag)

Returns true if a bag is a bank bag (or the bag frame). Yes, easily coded yourself, but I did it right and used the FrameXML constants so it'll actually keep working when Blizzard adds yet another bag.

:GetContainerNumFreeSlots(bag)

Returns slots, family like you would expect. Except it actually works for the keyring also, which Blizzard's API does not.

:GetContainerFamily(bag)

Returns the bag's family. Including the correct bitmask for the keyring, which Blizzard's API does not.


Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    16515
  • Created
    Nov 22, 2008
  • Last Released File
    Oct 19, 2014
  • Total Downloads
    14,629
  • License

Categories

Members

Recent Files

WoW Retail

  • r35
    Oct 19, 2014
  • r33
    Jun 11, 2014