- Joined
- Nov 17, 2010
- Messages
- 6,796
- Solutions
- 581
- Reaction score
- 5,360
Finds all of the items in a container, and returns it as a table.
Example usage; Grabbing all of the items inside a players depot.
Lua:
function getListOfContainerItems(container)
if not container:isContainer() then
return false
end
local containers, items = {}, {}
table.insert(containers, container)
while #containers > 0 do
for i = 0, containers[1]:getSize() - 1 do
local item = containers[1]:getItem(i)
table.insert(items, item)
if item:isContainer() then
table.insert(containers, item)
end
end
table.remove(containers, 1)
end
return items
end
Example usage; Grabbing all of the items inside a players depot.
Lua:
local actions_test = Action()
function actions_test.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local townId = 1
local depotChest = player:getDepotChest(townId)
local depotList = getListOfContainerItems(depotChest)
local itemList = ""
for i = 1, #depotList do
if itemList ~= "" then
itemList = itemList .. ", "
end
itemList = itemList .. depotList[i]:getId()
end
print(itemList)
return true
end
actions_test:id(2173)
actions_test:register()