View Single Post
05-24-22, 10:41 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
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:
  1. local ignore,foundspot={[0]={},[1]={},[2]={},[3]={},[4]={},}
  2. for k, v in pairs(EquipmentSlots) do
  3.    PickupInventoryItem(v)
  4.    foundspot = false
  5.    if CursorHasItem() then
  6.       for bag = 4, 0, -1 do
  7.          for slot = 1, GetContainerNumSlots(bag) do
  8.             if not ignore[bag][slot] and not GetContainerItemID(bag, slot) then
  9.                if bag == 0 then
  10.                   PutItemInBackpack()
  11.                else
  12.                   PutItemInBag(bag+19)
  13.                end
  14.                ignore[bag][slot] = true
  15.                foundspot = true
  16.                break
  17.             end
  18.          end
  19.          if foundspot then
  20.             break
  21.          end
  22.       end
  23.    end
  24. end


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.

Last edited by Kanegasi : 05-25-22 at 06:58 AM. Reason: slots within a bag start at 1
  Reply With Quote