View Single Post
11/20/14, 03:14 AM   #8
brekal
Guest
Posts: n/a
thanks for your replies.

First I tried out circonians suggestion - but unfortunately it didn't work.

So I tried his second suggestion - to go through the inventory and save all free slots in an extra table.

When I then move the item I iterate through the table of free stlots. I had there some issues too. Because when I started at the first element sometimes it did not get the right destSlots. So I decided to start at the last element and this works fine.

I know that my solution is not the smartest but at least it is working for my purposes

Here ist the actual code:

Lua Code:
  1. function LootManager.GetIngredientsFromBank()
  2.     if LootManager.savedVars.getBankIngredients ~= true then
  3.         return
  4.     end
  5.    
  6.     local name
  7.     local item
  8.     local slotId
  9.     local count
  10.     local bagId = BAG_BANK
  11.     local slots = GetBagSize(bagId)
  12.     local bag_Dest = BAG_BACKPACK
  13.    
  14.     LootManager.FindEmptySlotInBag()   
  15.     local slotId_Bag = LootManager.emptySlotsInBag[1]
  16.    
  17.     for i=0, slots - 1 do
  18.         slotId = i
  19.         name = zo_strformat(SI_UNIT_NAME, GetItemName(bagId, slotId))
  20.         item, count = GetItemInfo(bagId, slotId)
  21.  
  22.         if slotId_Bag ~= nil then
  23.             if name == LootManager.savedVars.ingredient1 then
  24.                 LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
  25.                 slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-1]
  26.             end
  27.  
  28.             if name == LootManager.savedVars.ingredient2 then  
  29.                 LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
  30.                 slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-2]
  31.             end
  32.        
  33.             if name == LootManager.savedVars.ingredient3 then
  34.                 LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
  35.                 slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-3]
  36.             end
  37.         else
  38.             d("Fehler: Slot-ID ist nil")
  39.             break
  40.         end
  41.     end
  42.    
  43.     LootManager.emptySlotsInBag = {}
  44. end
  45.  
  46. ------------------------------------------------------------------------------------------
  47. ------------------------------------------------------------------------------------------
  48.  
  49. function LootManager.MoveItem(srcBag, srcSlot, destBag, destSlot, quantity)
  50.     ClearCursor()
  51.         if CallSecureProtected("PickupInventoryItem", srcBag, srcSlot, quantity) then
  52.             CallSecureProtected("PlaceInInventory",destBag, destSlot)
  53.         end
  54.     ClearCursor()  
  55. --  d("Moved: " .. zo_strformat(SI_UNIT_NAME, GetItemName(srcBag, srcSlot)) .. " x " .. quantity .. " to inventory")
  56. --  d("SrcBag: " .. srcBag .. " SrcSlot: " .. srcSlot .. " DestBag: " .. destBag .. " DestSlot: " .. destSlot .. " Quantity: " .. quantity)
  57. end
  58.  
  59. ------------------------------------------------------------------------------------------
  60. ------------------------------------------------------------------------------------------
  61.  
  62. function LootManager.FindEmptySlotInBag()
  63.     local bagSize = GetBagSize(BAG_BACKPACK)
  64.     local name
  65.    
  66.     for i = 0, bagSize - 1 do
  67.         name = zo_strformat(SI_UNIT_NAME, GetItemName(BAG_BACKPACK, i))
  68.         if name == "" then
  69.             table.insert(LootManager.emptySlotsInBag, i)   
  70.         end
  71.     end
  72.  
  73. end


I also do not understand why this delay should cause the problem because I only delay the movement of the item, not the FindFirstEmptySlotInBag-function. The interesting thing about this is, that dumping the values (as I do in line 44 and 45 of my original post) shows the correct item name and srcSlot - the only thing that stays the same is the destSlot.

I did not find any article on esoui-wiki about this "RequestMoveItem" function that Garkin suggested - do you have more infos about it?
  Reply With Quote