That's probably by design. The items are not actually moved immediately, your commands are carried out after your handler exits.
Some time ago I wrote my own function for finding an empty slot, which allows me to start the search after the previous one:
Lua Code:
local function findEmptySlotInBag(bagId, prevIndex, lastIndex)
local slotIndex = prevIndex or -1
while slotIndex < lastIndex do
slotIndex = slotIndex + 1
if GetItemType(bagId, slotIndex) == ITEMTYPE_NONE then
return slotIndex
end
end
return nil
end
-- usage
local numSlots = GetBagSize(BAG_BANK)
local emptyIndex = findEmptySlotInBag(BAG_BANK, nil, numSlots - 1)
while emptyIndex do
-- we have an empty slot in bank
... put something in there
emptyIndex = findEmptySlotInBag(BAG_BANK, emptyIndex, numSlots - 1)
end
-- bank full