Unequip all items
Hi all
I am trying to unequip all items into any empty bag slot. The problem is that I can unequip all items into my bags or into my backpack but not all into any empty slot in both. This is the code I am trying to run; Lua Code:
If I have enough bagspace the items move into the bags, but if I do not have enough space the leftover items do not drop into the backpack. I have tried splitting it into 2 separate chunks runnig one after the other with the same results. It is the backpack one that seems to break it, it will fill the backpack then say "not enough space" and then stop altogether. Does anyone have any advice/help for me? Cheers |
PutItemInBag wants an InventorySlotId, not a slot in a bag. 20, 21, 22, and 23 are the bag slots. You should also break out of the inner loops once you put the item in a bag.
Lua Code:
Edit: Fizzlemizz makes a good point. Based on your wording, it does look like you would rather fill other bags with the unequipped gear before your backpack. I reversed the bag loop so your backpack is searched last. Edit2: Added CursorHasItem and an ignore table to keep track of spots filled by the code. |
Bag 0 is the backpack so checking there first for empty slots is probably not what you're looking for.
Code:
for bag = 1, 4 do In a tight loop, the bag inventory doesn't update in time so you the get the "That bag is full" notification which can cause the process to break. Best to wait for the bag update event before processing the next item: Lua Code:
Edit: I didn't notice Kanegasi had made changes before doing this... |
Hi Kanegasi and Fizzlemizz
Thanks for your answers. Fizzlemizz, I can see the wait makes a lot of sense, it is something I should have picked up myself :( I do have a couple of questions about your solutions. You both used; Lua Code:
And Kanegasi you set up a table to record all placed items; Lua Code:
|
Kanegasi mentioned that PutItemInBag requires a bag id. (InventorySlotId) not a bag number and these start at 20 (bag 1+19 = 20).
Using the table keeps track of where you put the last item instead of using the event method. Checking GetContainerItemID in a tight loop can return nil for a slot that has only just been filled in the previous loop(s) until the system catches up and sends the event which could cause a "Bag is full" message. |
Fizzlemizz, I left this thread open on my phone's browser just after your post, so I didn't catch your edits either lol.
Anyways, to expand on InventorySlotId: https://wowpedia.fandom.com/wiki/InventorySlotId And PutItemInBag: https://wowpedia.fandom.com/wiki/API_PutItemInBag Basically, your character's entire "inventory" is actually your equipped items, your equipped bags (where items are saved elsewhere), your 28 base bank slots, and then your equipped bank bags. On retail, this counts all the way to 86. 0 is the old unused ammo slot, 1 is your head, 2 is your neck, 19 is your tabard, 20 is the first bag next to your backback, 21-23 is the next three. I'm honestly not sure what 24-51 is, then 52-79 is your base bank, and finally 80-86 is your bank bags. Also, Fizzlemizz nailed the table explanation. It's a temporary table that starts off blank every time you use this code and is a quick solution to track slots where your unequipped items get dropped into. The slots may actually not line up depending on how you have new items enter your bags, but it still works in the end because the loop will find the, say for example, four empty slots and the table will treat those spots filled in the eyes of this loop when it dumps four of your pieces in. |
Hi Kanegasi and Fizzlemizz
Thanks for the further explainations, I do really appreciate your help. You two absolutely rock :banana: Cheers |
Quote:
IIRC when the added the 4 extra backpack slots for having an authenticator, they repurposed they keyring system for those slots. Counting up the number of slots in spots 24 - 51 gives you 28, which would be the 28 unassigned numbers you see there. I'm completely pulling this out of my ass and my be completely wrong, but it all makes sense to me. |
Hi all
I didn't want to create a new thread for this issue, instead, I have resurrected this post; (Yes, I am a necromancer). Using Kanegasi's code did correctly remove all items and placed them in my bags/backpack; Lua Code:
Since the launch of Wrath and Dragonflight 10.05 the code has stopped working, (even after adding the C_Container. where required), and it throws no errors at all. The code still works in flawlessly Classic. How do I get this running again? |
I wrote my own script to do this a long time ago and decided to dust it off and make some improvements. It should work with Classic Era, Wrath Classic, and Dragon Flight.
Lua Code:
|
Hi SDPhantom
Thaks fopr your chunk, it absolutley works in Wrath and Retail. I should have mentioned that I ended up using Kanegasi's chunk as I could skip items just by removing specific items from the EquipmentSlots table. Is there a way to skip/ignore items using your code? |
It can with a few tweaks. I added notes for educational purposes and fixed skipping free container slots if it encounters an empty inventory slot.
Lua Code:
|
Hi SDPhantom
Thanks for your code, it works as intended; and the comments are very much appreciated as I am still learning and the comments really help me. I do have a question regarding line 41. I thought in lua there was no requirement to end a line with ; yet if I remove the line close the function breaks. Why does this happen? |
Lua can have ambiguity errors where the compiler gets confused about what part of a line is supposed to do. Since the next line starts with a set of parenthesis, the compiler wouldn't know if it's a set of parameters for a function call continuing from the previous line or a new expression. Remember, Lua is whitespace agnostic and whitespace is allowed between a function reference and the argument list. Newlines don't explicitly define new statements, that's the semicolon's job.
Most times, the compiler is smart and can determine this on its own, but there are a few edge cases where this can happen. In this case, we want it to be recognized as an expression because it fetches the function we want for the next set of parenthesis to call. Lua 5.1 Reference Manual §2.5.8 Quote:
|
Hi SDPhantom
Thanks for your explanation, it is really appreciated.:) |
All times are GMT -6. The time now is 07:47 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI