Quantcast
Channel: Addons from WowAce.com
Viewing all articles
Browse latest Browse all 2479

LibBagUtils-1.0

$
0
0

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

localLBU=LibStub("LibBagUtils-1.0")forbag,slotinLBU:Iterate("BANK","Major Healing Potion")doLBU: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.:

forbag,slot,linkinLBU:Iterate("BAGS")do-- loop all slotsforbag,slot,linkinLBU: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)
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.

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:

localcomparator,arg1,arg2=LBU:MakeLinkComparator(myItemString)for_,itemLinkinpairs(myItems)doifcomparator(itemLink,arg1,arg2)thenprint(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.:

forbaginLBU: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.


Viewing all articles
Browse latest Browse all 2479

Trending Articles