WoW LibBagUtils-1.0 addon Dragonflight/Wrath of the Lich King Classic 2024
logo
wow addon LibBagUtils-1.0

LibBagUtils-1.0

Game Version: 6.0.2
Total Downloads: 13,341
Updated: Oct 19, 2014
Created: Nov 22, 2008
download LibBagUtils-1.0Download Earlier Versions

Earlier Versions

Name Size Uploaded Game Version Downloads
r35 release 7.93 KB Oct 19, 2014 6.0.2 1,955 download LibBagUtils-1.0 r35 releaseDownload
r34 release 7.68 KB Oct 15, 2014 6.0.2 375 download LibBagUtils-1.0 r34 releaseDownload
1.0.27 release 7.73 KB Dec 1, 2011 4.3.0 3,091 download LibBagUtils-1.0 1.0.27 releaseDownload
1.0.25 release 7.84 KB Oct 12, 2011 4.2.0 1,722 download LibBagUtils-1.0 1.0.25 releaseDownload
1.0.22 release 7.71 KB Mar 27, 2011 4.0.6 1,785 download LibBagUtils-1.0 1.0.22 releaseDownload
1.0.19 release 8.09 KB Oct 3, 2009 3.2.0 2,246 download LibBagUtils-1.0 1.0.19 releaseDownload
1.0.17 release 8.07 KB Sep 13, 2009 3.2.0 445 download LibBagUtils-1.0 1.0.17 releaseDownload
1.0.15 release 8.16 KB Sep 4, 2009 3.2.0 55 download LibBagUtils-1.0 1.0.15 releaseDownload
1.0.13 release 8.74 KB Aug 14, 2009 3.2.0 62 download LibBagUtils-1.0 1.0.13 releaseDownload
1.0.11 release 8.46 KB Aug 13, 2009 3.2.0 48 download LibBagUtils-1.0 1.0.11 releaseDownload
1.0.9 release 8.21 KB Aug 12, 2009 3.2.0 46 download LibBagUtils-1.0 1.0.9 releaseDownload
1.0.7 release 7.63 KB Aug 7, 2009 3.2.0 63 download LibBagUtils-1.0 1.0.7 releaseDownload
1.0.5 release 6.53 KB Aug 5, 2009 3.2.0 53 download LibBagUtils-1.0 1.0.5 releaseDownload
r3-release release 6.62 KB Jan 10, 2009 3.0.3 70 download LibBagUtils-1.0 r3-release releaseDownload
r33 alpha 7.70 KB Jun 11, 2014 5.4.8 162 download LibBagUtils-1.0 r33 alphaDownload
r32 alpha 7.71 KB May 24, 2013 5.3.0 189 download LibBagUtils-1.0 r32 alphaDownload
r31 alpha 7.71 KB Mar 9, 2013 5.2.0 138 download LibBagUtils-1.0 r31 alphaDownload
r30 alpha 7.72 KB Dec 19, 2012 5.1.0 102 download LibBagUtils-1.0 r30 alphaDownload
r29 alpha 7.68 KB Sep 2, 2012 5.0.4 104 download LibBagUtils-1.0 r29 alphaDownload
r27 alpha 7.68 KB Dec 1, 2011 4.3.0 21 download LibBagUtils-1.0 r27 alphaDownload
r25 alpha 7.79 KB Oct 5, 2011 4.2.0 101 download LibBagUtils-1.0 r25 alphaDownload
r24 alpha 7.58 KB May 29, 2011 4.1.0 136 download LibBagUtils-1.0 r24 alphaDownload
r22 alpha 7.67 KB Mar 27, 2011 4.0.6 24 download LibBagUtils-1.0 r22 alphaDownload
r21 alpha 7.62 KB Dec 26, 2010 3.2.0 54 download LibBagUtils-1.0 r21 alphaDownload
r19 alpha 8.04 KB Oct 3, 2009 3.2.0 47 download LibBagUtils-1.0 r19 alphaDownload
r17 alpha 8.02 KB Sep 13, 2009 3.2.0 51 download LibBagUtils-1.0 r17 alphaDownload
r15 alpha 8.13 KB Sep 4, 2009 3.2.0 24 download LibBagUtils-1.0 r15 alphaDownload
r13 alpha 8.70 KB Aug 14, 2009 3.2.0 21 download LibBagUtils-1.0 r13 alphaDownload
r11 alpha 8.41 KB Aug 13, 2009 3.2.0 22 download LibBagUtils-1.0 r11 alphaDownload
r9 alpha 8.16 KB Aug 12, 2009 3.2.0 38 download LibBagUtils-1.0 r9 alphaDownload
r7 alpha 7.59 KB Aug 7, 2009 3.2.0 15 download LibBagUtils-1.0 r7 alphaDownload
r5 alpha 6.48 KB Aug 5, 2009 3.2.0 23 download LibBagUtils-1.0 r5 alphaDownload
r3 alpha 6.53 KB Nov 27, 2008 3.0.3 28 download LibBagUtils-1.0 r3 alphaDownload
r2 alpha 5.80 KB Nov 23, 2008 3.0.3 15 download LibBagUtils-1.0 r2 alphaDownload
r1 alpha 344 Bytes Nov 22, 2008 3.0.3 10 download LibBagUtils-1.0 r1 alphaDownload

Description

Share this:

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

  • Ignore the 9th "level" parameter introduced in 3.0
  • Correctly match items with changing stats in inventory vs AH/Mail/GBank – see http://www.wowpedia.org/ItemString#3.2_wotlk_randomstat_items_changing_their_suffix_factors
  • Pick the smartest way to compare available

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

Add a comment