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

doScanContainer(item, tables)

Oskar1121

Excellent OT User
Joined
Jul 15, 2009
Messages
634
Reaction score
537
Location
Poland
Hello, I made some function. She/He scan us item.uid, buy only then when item is container.
PHP:
function doScanContainer(item, tables, count)
	if isContainer(item.uid) then
		for i = 0, getContainerSize(item.uid) do
			local item = getContainerItem(item.uid, i)
			if isContainer(item.uid) then
				doScanContainer(item, tables)
			end
			table.insert(count, item.type)
			table.insert(tables, item.itemid)
		end
	end
end
For example:
PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tabelka = {}
local counts = {}
doScanContainer(item, tabelka, counts)
	for i = 1, #tabelka do
		if tabelka[i] ~= 0 then
			doPlayerAddItem(cid, tabelka[i], counts[i])
		end
	end
return false
end
It give us all items which are in container.
 
Last edited:
Remove item is missing, that way you clone your items right? ex. autoloot script
 
How can i remove items from scanned container? rep++
 
PHP:
for i = 0, getContainerSize(item.uid) do
change it with:
PHP:
for i = getContainerSize(item.uid), 0 do
or player will get items in wrong order.
There is already in TFS function that copy item/container. It can also copy items action IDs ;)
Lua:
function doCopyItem(item, attributes)
	local attributes = attributes or false

	local ret = doCreateItemEx(item.itemid, item.type)
	if(attributes) then
		if(item.actionid > 0) then
			doItemSetAttribute(ret, "aid", item.actionid)
		end
	end

	if(isContainer(item.uid)) then
		for i = (getContainerSize(item.uid) - 1), 0, -1 do
			local tmp = getContainerItem(item.uid, i)
			if(tmp.itemid > 0) then
				doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
			end
		end
	end

	return getThing(ret)
end
 
The function was to scan a container not to clone items. It was just an example. Please don't judge too much on the example scripts.
 
Back
Top