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"[, dontClearOnFail[, count]])
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"
- 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)
- 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.
- 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.
------------------------------------------------------------------------
r20 | mikk | 2009-10-03 16:56:27 +0000 (Sat, 03 Oct 2009) | 1 line
Changed paths:
A /tags/1.0.19 (from /trunk:19)
Tagging as 1.0.19
------------------------------------------------------------------------
r19 | mikk | 2009-10-03 16:56:01 +0000 (Sat, 03 Oct 2009) | 4 lines
Changed paths:
M /trunk/LibBagUtils-1.0/LibBagUtils-1.0.lua
M /trunk/LibBagUtils-1.0.toc
- Fix funky case where we could fail to :PutItem() something because a bag was full of (temporarily) internally-locked slots.
- LoadOnDemand
- More locals, less GETGLOBALs
------------------------------------------------------------------------
r17 | mikk | 2009-09-13 12:43:05 +0000 (Sun, 13 Sep 2009) | 3 lines
Changed paths:
M /trunk/LibBagUtils-1.0/LibBagUtils-1.0.lua
- Add wrapper function for GetContainerNumFreeSlots() that actually Does The Right Thing for the keyring. (Actually return the number of free slots, not just 0. And returns the right family!)
- Add GetContainerFamily() that returns the bag family (AND the right family for the keyring)
And they say bag handling is straightforward, sheesh...
------------------------------------------------------------------------
r15 | mikk | 2009-09-04 07:51:18 +0000 (Fri, 04 Sep 2009) | 1 line
Changed paths:
M /trunk/LibBagUtils-1.0/LibBagUtils-1.0.lua
Do away with the idea of a bag list cache. It seemed nice, but I totally forgot about the event reception ordering problem. (I.e. addons reacting to BANK_OPENED before the lib has time to react to it and so forth)
------------------------------------------------------------------------
Installation Guide
- Exit "World of Warcraft" completely
- Download the mod you want to install
- Make a folder on your desktop called "My Mods"
- Save the .zip/.rar files to this folder.
- If, when you try to download the file, it automatically "opens" it... you need to RIGHT click on the link and "save as..." or "Save Target As".
- Extract the file - commonly known as 'unzipping'
Do this ONE FILE AT A TIME!
- Windows
- Windows XP has a built in ZIP extractor. Double click on the file to open it, inside should be the file or folders needed. Copy these outside to the "My Mods" folder.
- WinRAR: Right click the file, select "Extract Here"
- WinZip: You MUST make sure the option to "Use Folder Names" is CHECKED or it will just extract the files and not make the proper folders how the Authors designed
- Mac Users
- StuffitExpander: Double click the archive to extract it to a folder in the current directory.
- Verify your WoW Installation Path
That is where you are running WoW from and THAT is where you need to install your mods.
- Move to the Addon folder
- Open your World of Warcraft folder. (default is C:\Program Files\World of Warcraft\)
- Go into the "Interface" folder.
- Go into the "AddOns" folder.
- In a new window, open the "My Mods" folder.
- The "My Mods" folder should have the "Addonname" folder in it.
- Move the "Addonname" folder into the "AddOns" folder
- Start World of Warcraft
- Make sure AddOns are installed
- Log in
- At the Character Select screen, look in lower left corner for the "addons" button.
- If button is there: make sure all the mods you installed are listed and make sure "load out of date addons" is checked.
- If the button is NOT there: means you did not install the addons properly. Look at the above screenshots. Try repeating the steps or getting someone who knows more about computers than you do to help.
Translations
When you download a mod, please be sure that the mod is compatible with your translation of wow. Some mods only work on the US versions, while some only work on some of the various European versions. These variations are called "Localizations".
TOC Numbers (Out of Date Mods)
When Blizzard patches WoW, they change the Interface number. This means that all mods will be "out of date" unless or until the author releases a new version for that interface. Some people go into the .toc files and update the numbers themselves, but this is STRONGLY advised against as it will cause problems locating possible incompatibilities addons. When you log into WoW after a patch, you DO NOT have to delete your interface directory. All you have to do is simply tell WoW to ignore the interface numbers and load all the mods anyway. All you have to do is, while at the "character select" screen, look in the lower left corner and click on the "addons" button. A window will pop up listing all your installed mods.
If you look in the upper left corner of that window there should be a box that says "Load Out of Date AddOns". You want to CHECK this box. Now simply go into WoW normally and all your mods should load. As of the 1.9 patch, you will have to do this after EVERY patch/update that Blizzard posts! If you encounter any problems with a mod after a patch, please be sure to let the author of the mod know so they can fix it.
See also: About "Out Of Date AddOns"
Mac Support
WoW addons are not platformed based. As such, they can be used on either Mac or PC. You can extract both .zip and .rar files on a Mac using StuffitExpander.
Directory Structure
World of Warcraft
|_ Interface
|_AddOns
|_*AddonName*
|_ *AddonName*.toc
|_ *AddonName*.xml
|_ *AddonName*.lua
|_ (possibly others as well)...