• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Lua Function] Recursive Container Finding

feverdog

Active Member
Joined
Mar 10, 2008
Messages
229
Reaction score
36
Hello guys, I was doing a function for getting all containers inside a parent container have but it seems that it only gets backpacks inside the main backpack and it doesn't do the recursion towards the backpacks inside the backpacks inside the main backpack, and so on.. is there a catch I do not know here??

Code:
function jlibs.getAllContainers(container)
   
   local containers = {}

   function getContainers(container)
   
      if(isItemContainer(container.itemid)) then
         table.insert(containers, container)
      end
      
      items = jlibs.getContainerItems(container) 
      if not (items) then
         return
      end
      
      for k, v in pairs(items) do
         if (isItemContainer(v.itemid)) then getContainers(v) end
      end
      
      return containers
   end
         
   return getContainers(container)
end
 
Back
Top