velocitraptor
devFuel = feedback
- Joined
- Jun 3, 2016
- Messages
- 23
- Reaction score
- 20
Hi, this is my first post, i want to share a remake i did to a function who @Summ made here
This is a function to find an item on a container or a container list, of course you could add a player to check on his/her equipment too.
Here is it:
This is a function to find an item on a container or a container list, of course you could add a player to check on his/her equipment too.
Here is it:
Code:
function Game.getContainerItemsById(containerList, itemId, player)
local containers = {}
local items = {}
local containerAux --temporal var to store a new container
local itemAux --temporal var to store new item
for i = 1, #containerList do
itemAux = containerList[i]
if (itemAux:isContainer()) then
table.insert(containers, itemAux)
end
end
if (player) then
for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
local itemAux = player:getSlotItem(i)
if (itemAux) then
if (itemAux:isContainer()) then
table.insert(containers, itemAux)
else
if (itemAux:getId() == itemId) then
table.insert(items, itemAux)
end
end
end
end
end
while #containers > 0 do
local containerAux = containers[1]
for i = 0, containerAux:getSize() - 1 do
itemAux = containerAux:getItem(i)
if (itemAux:isContainer()) then
table.insert(containers, itemAux)
else
if (itemAux:getId() == itemId) then
table.insert(items, itemAux)
end
end
end
table.remove(containers, 1)
end
return items
end