Well for your final result, you don't need to find all the items in the players backpack.. Just the backpack itself.
So a quick loop through all the inventory slots, copy the items, send to depot, then remove the items from the player.
In the video example, I've attached the code to my amulet of loss.
View attachment 82077
Lua:
local usePlayerTown = true -- if set to false, then will use 'no town' depot (aka: linked depots.. instead of 'thais depot')
local townId = usePlayerTown and player:getTown():getId() or 0
local depot = player:getDepotChest(townId, true)
for slot = 1, 10 do
local thing = player:getSlotItem(slot)
if thing then
local copiedItem = thing:clone()
depot:addItemEx(copiedItem, INDEX_WHEREEVER, FLAG_NOLIMIT)
thing:remove()
end
end