• 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!

Solved [LUA] How to get all items with id on inventory

Dantarrix

Member
Joined
Aug 27, 2010
Messages
546
Reaction score
18
Location
Stgo, Chile
I know that if you use this:

getPlayerItemById(cid, deepSearch, itemId[, subType])

You get the first item on inventory with a certain id...

I want to get ALL the items on inventory with a certain id...

How I do that?

Please help!
 
Last edited:
Lua:
function getAllItemsById(cid, id)
	local containers = {}
	local items = {}
	
	for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
		local sitem = getPlayerSlotItem(cid, i)
		if sitem.uid > 0 then
			if isContainer(sitem.uid) then
				table.insert(containers, sitem.uid)
			elseif not(id) or id == sitem.itemid then
				table.insert(items, sitem)
			end
		end
	end
	
	while #containers > 0 do
		for k = (getContainerSize(containers[1]) - 1), 0, -1 do
			local tmp = getContainerItem(containers[1], k)
			if isContainer(tmp.uid) then
				table.insert(containers, tmp.uid)
			elseif not(id) or id == tmp.itemid then
				table.insert(items, tmp)
			end
		end
		table.remove(containers, 1)
	end

	
	return items
end
 
Back
Top