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:
function LootManager.GetIngredientsFromBank()
if LootManager.savedVars.getBankIngredients ~= true then
return
end
local name
local item
local slotId
local count
local bagId = BAG_BANK
local slots = GetBagSize(bagId)
local bag_Dest = BAG_BACKPACK
LootManager.FindEmptySlotInBag()
local slotId_Bag = LootManager.emptySlotsInBag[1]
for i=0, slots - 1 do
slotId = i
name = zo_strformat(SI_UNIT_NAME, GetItemName(bagId, slotId))
item, count = GetItemInfo(bagId, slotId)
if slotId_Bag ~= nil then
if name == LootManager.savedVars.ingredient1 then
LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-1]
end
if name == LootManager.savedVars.ingredient2 then
LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-2]
end
if name == LootManager.savedVars.ingredient3 then
LootManager.MoveItem(bagId, slotId, bag_Dest, slotId_Bag, count)
slotId_Bag = LootManager.emptySlotsInBag[table.getn(LootManager.emptySlotsInBag)-3]
end
else
d("Fehler: Slot-ID ist nil")
break
end
end
LootManager.emptySlotsInBag = {}
end
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
function LootManager.MoveItem(srcBag, srcSlot, destBag, destSlot, quantity)
ClearCursor()
if CallSecureProtected("PickupInventoryItem", srcBag, srcSlot, quantity) then
CallSecureProtected("PlaceInInventory",destBag, destSlot)
end
ClearCursor()
-- d("Moved: " .. zo_strformat(SI_UNIT_NAME, GetItemName(srcBag, srcSlot)) .. " x " .. quantity .. " to inventory")
-- d("SrcBag: " .. srcBag .. " SrcSlot: " .. srcSlot .. " DestBag: " .. destBag .. " DestSlot: " .. destSlot .. " Quantity: " .. quantity)
end
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
function LootManager.FindEmptySlotInBag()
local bagSize = GetBagSize(BAG_BACKPACK)
local name
for i = 0, bagSize - 1 do
name = zo_strformat(SI_UNIT_NAME, GetItemName(BAG_BACKPACK, i))
if name == "" then
table.insert(LootManager.emptySlotsInBag, i)
end
end
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?