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

[Help] doScanContainer

perdigs

New Member
Joined
Aug 22, 2010
Messages
114
Reaction score
1
I need one function to scan items in container xxxx, and if the item xxxx is there transform in other.
Thanks Guys sry for the english.
 
LUA:
function doScanContainerFor(uid, id)  -- Returns a table of uid of matched item and true if item found else it returns false
local ret,containers, scan = h, {}, {} 
	for i = 0, getContainerSize(uid) do
		local v = getContainerItem(uid, i)
			if v.itemid == id then
				table.insert(scan,v.uid)
			end
			if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
				table.insert(containers, v.uid)
			end

	end
	for i = 1, #containers do
		check = doScanContainerFor(containers[i], id)
		if check  then
			for i = 1,#check do 
				table.insert(scan,check[i])
			end
		end
	end
	return #scan > 0 and true and scan or false
end

A simple example :
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)	
	local scanned = doScanContainerFor(getPlayerSlotItem(cid,3).uid, 2466)	-- this checks for backpack slot, scanning all continers inside it.
	if scanned then  -- check if there is atleast one match
			doTransformItem(scanned[1],2446)  -- this transfer the first match item with id 2446 , as the function returns a table with the uid of the match items found
	else
		doPlayerSendCancel(cid,"Fail.")
	end
    return true
end
 
dont work
but thanks

items = {
[1279] = {9999},
[1278] = {9998},
}

for i, x in pairs(items)
i need a function to scan only the slot 9.uid and
for example

local found = doScanContainerFor(slot9, i)
doTransformItem(found, x[1])

its very hard ?
 
Dude you said you need a function , so you must know what you are doing , next time ask for a script not a function i will give you another example hope you get it :
LUA:
--// Edidtable \\--

local slot = 3    --- slot id , must contain a container to check in.
local itemm = { -- item id     ,  transfrom to itemid
				[2446] = {transformto = 2466},
				[2774] = {transformto = 1192}

			  }

local transform_all_found = true  -- set to false if you want to transform only 1 item not all found items

--// function \\--
function doScanContainerFor(uid, id) -- Returns a table of uid of matched item and true if item found else it returns false
local ret,containers, scan = h, {}, {} 
	for i = 0, getContainerSize(uid) do
		local v = getContainerItem(uid, i)
			if v.itemid == id then
				table.insert(scan,v.uid)
			end
			if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
				table.insert(containers, v.uid)
			end
 
	end
	for i = 1, #containers do
		check = doScanContainerFor(containers[i], id)
		if check  then
			for i = 1,#check do 
				table.insert(scan,check[i])
			end
		end
	end
	return #scan > 0 and true and scan or false
end

--// Script \\--

function onUse(cid, item, fromPosition, itemEx, toPosition)	
	for k,v in pairs(itemm) do 
		local scanned = doScanContainerFor(getPlayerSlotItem(cid,slot).uid, k)	
		if scanned then
			if transform_all_found then
				for _,t in ipairs(scanned) do 
					doTransformItem(t,v.transformto)
				end
			else
				doTransformItem(scanned[1],v.transformto)
			end
		end
	end
    return true
end
 
Back
Top