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

Very advanced scripter needed/ Add Backpack

Summ

(\/)(;,,;)(\/) Y not?
Staff member
Global Moderator
Joined
Oct 15, 2008
Messages
4,152
Solutions
12
Reaction score
1,107
Location
Germany :O
Hello
I need a script which adds different items to a backpack, but not just in one backpack. The script should be based on a table and it should be able to add backpacks in backpacks and such..

Example of the table the script should be based on:
table = {item,item,item,{item,item},item}
the first three are just added, but the third has to be a container, in the third then the items in the array {} are added and after that again in the first backpack the last item is added..

I tried to do it, but I can't get it done.
 
Lua:
local items = {
	[2160] = {10},
	[2160] = {1},
	[2000] = {{2160, 2}, {2160, 3}},
	[2160] = {5}
}

function addItemArray(cid, items)
	local backpack = nil

	for k, v in pairs(items) do
		if isItemContainer(k) then
			backpack = doCreateItemEx(k)
			for i = 1, #v do
				doAddContainerItem(backpack, v[i][1], v[i][2])
			end
			doPlayerAddItemEx(cid, backpack, true)
		else
			doPlayerAddItem(cid, k, v, true)
		end
	end
	return true
end

Not tested..
 
Lua:
local items = {
	[2160] = {10},
	[2160] = {1},
	[2000] = {{2160, 2}, {2160, 3}},
	[2160] = {5}
}

function addItemArray(cid, items)
	local backpack = nil

	for k, v in pairs(items) do
		if isItemContainer(k) then
			backpack = doCreateItemEx(k)
			for i = 1, #v do
				doAddContainerItem(backpack, v[i][1], v[i][2])
			end
			doPlayerAddItemEx(cid, backpack, true)
		else
			doPlayerAddItem(cid, k, v, true)
		end
	end
	return true
end

Not tested..

that work super
 
Lua:
local items = {
	[2160] = {10},
	[2160] = {1},
	[2000] = {{2160, 2}, {2160, 3}},
	[2160] = {5}
}

function addItemArray(cid, items)
	local backpack = nil

	for k, v in pairs(items) do
		if isItemContainer(k) then
			backpack = doCreateItemEx(k)
			for i = 1, #v do
				doAddContainerItem(backpack, v[i][1], v[i][2])
			end
			doPlayerAddItemEx(cid, backpack, true)
		else
			doPlayerAddItem(cid, k, v, true)
		end
	end
	return true
end

Not tested..

Whre to add it :)?
 
Back
Top