• 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 Error on line 177 "attempt to index local `items`"

Hellrage

Worr
Joined
Oct 30, 2007
Messages
2,477
Reaction score
5
Location
Sweden
Error "attempt to index local `items`" on line 177 which looks like this:
for i = 1, #items do
This is the script
Lua:
local BACKPACK = 0
local ITEM = 1
local ITEMS = 2
local SLOT=3

local SLOT_HEAD = 1
local SLOT_NECKLACE = 2
local SLOT_BACKPACK = 3
local SLOT_ARMOR = 4
local SLOT_RIGHT = 5
local SLOT_LEFT = 6
local SLOT_LEGS = 7
local SLOT_FEET = 8
local SLOT_RING = 9
local SLOT_AMMO = 10

local STORAGE = 1000

local defaultItems = 
{	
	[5]=
{
		{type=ITEM, itemId=2152, count=47},
		{type=ITEM, itemId=2120, count=1},
		{type=ITEM, itemId=2554, count=1},
		{type=BACKPACK, bpId=2001, bpCount=7, itemId=2006, count=7},
		{type=BACKPACK, bpId=2003, bpCount=4, itemId=8067, count=1},
		{type=BACKPACK, bpId=2002, bpCount=3, itemId=8066, count=1},	
		{type=ITEMS, bpId=1998,
			[1]={itemId=2310, count=3},
			[2]={itemId=2261, count=3},
			[3]={itemId=2293, count=3},
			[4]={itemId=2293, count=3},
			[5]={itemId=2293, count=3},
			[6]={itemId=2305, count=2},
			[7]={itemId=2546, count=50},
			[8]={itemId=2456, count=1},
			[9]={itemId=2164, count=20},
			[10]={itemId=2167, count=1},
			[11]={itemId=2198, count=50},
			[12]={itemId=2197, count=5}
		},
		{type=SLOT, slotId=SLOT_RIGHT, itemId=2519, count=1},
		{type=SLOT, slotId=SLOT_LEFT, itemId=2187, count=1},
		{type=SLOT, slotId=SLOT_NECKLACE, itemId=2201, count=200},
		{type=SLOT, slotId=SLOT_HEAD, itemId=2491, count=1},
		{type=SLOT, slotId=SLOT_ARMOR, itemId=2486, count=1},
		{type=SLOT, slotId=SLOT_LEGS, itemId=2647, count=1},
		{type=SLOT, slotId=SLOT_FEET, itemId=2643, count=1},
		{type=SLOT, slotId=SLOT_RING, itemId=2164, count=20},
		{type=SLOT, slotId=SLOT_AMMO, itemId=2789, count=21}
	},
	[6]=
	{
		{type=ITEM, itemId=2152, count=43},
		{type=ITEM, itemId=2120, count=1},
		{type=ITEM, itemId=2554, count=1},
		{type=BACKPACK, bpId=2001, bpCount=7, itemId=2006, count=7},
		{type=BACKPACK, bpId=2003, bpCount=4, itemId=8067, count=1},
		{type=BACKPACK, bpId=2002, bpCount=3, itemId=8066, count=1},	
		{type=ITEMS, bpId=1998,
			[1]={itemId=2310, count=2},
			[2]={itemId=2261, count=3},
			[3]={itemId=2278, count=3},
			[4]={itemId=2293, count=3},
			[5]={itemId=2293, count=3},
			[6]={itemId=2293, count=3},
			[7]={itemId=2305, count=2},
			[8]={itemId=2546, count=50},
			[9]={itemId=2456, count=1},
			[10]={itemId=2164, count=20},
			[11]={itemId=2167, count=1},
			[12]={itemId=2198, count=50},
			[13]={itemId=2197, count=5}
		},
		{type=SLOT, slotId=SLOT_RIGHT, itemId=2519, count=1},
		{type=SLOT, slotId=SLOT_LEFT, itemId=2181, count=1},
		{type=SLOT, slotId=SLOT_NECKLACE, itemId=2201, count=200},
		{type=SLOT, slotId=SLOT_HEAD, itemId=2491, count=1},
		{type=SLOT, slotId=SLOT_ARMOR, itemId=2489, count=1},
		{type=SLOT, slotId=SLOT_LEGS, itemId=2647, count=1},
		{type=SLOT, slotId=SLOT_FEET, itemId=2643, count=1},
		{type=SLOT, slotId=SLOT_RING, itemId=2214, count=20},
		{type=SLOT, slotId=SLOT_AMMO, itemId=2673, count=48}
	},
	[7]=
	{
		{type=ITEM, itemId=2152, count=51},
		{type=ITEM, itemId=2293, count=3},
		{type=ITEM, itemId=2293, count=3},
		{type=ITEM, itemId=2120, count=1},
		{type=ITEM, itemId=2554, count=1},
		{type=BACKPACK, bpId=2001, bpCount=4, itemId=2006, count=7},
		{type=BACKPACK, bpId=2003, bpCount=3, itemId=8067, count=1},
		{type=BACKPACK, bpId=2002, bpCount=6, itemId=8066, count=1},	
		{type=ITEMS, bpId=1987,
			[1]={itemId=2543, count=100},
			[2]={itemId=2543, count=100},
			[3]={itemId=2543, count=100},
			[4]={itemId=2543, count=100}
		},
		{type=SLOT, slotId=SLOT_LEFT, itemId=2455, count=1},
		{type=SLOT, slotId=SLOT_RIGHT, itemId=2516, count=1},
		{type=SLOT, slotId=SLOT_NECKLACE, itemId=2171, count=1},
		{type=SLOT, slotId=SLOT_HEAD, itemId=2497, count=1},
		{type=SLOT, slotId=SLOT_ARMOR, itemId=2476, count=1},
		{type=SLOT, slotId=SLOT_LEGS, itemId=2647, count=1},
		{type=SLOT, slotId=SLOT_FEET, itemId=2643, count=1},
		{type=SLOT, slotId=SLOT_RING, itemId=2124, count=1},
		{type=SLOT, slotId=SLOT_AMMO, itemId=2543, count=92}
	},

	[8]=
	{
		{type=ITEM, itemId=2120, count=1},
		{type=ITEM, itemId=2554, count=1},
		{type=BACKPACK, bpId=2001, bpCount=3, itemId=2006, count=7},
		{type=BACKPACK, bpId=2004, bpCount=1, itemId=2313, count=3},
		{type=BACKPACK, bpId=2002, bpCount=8, itemId=8066, count=1},	
		{type=ITEMS, bpId=1988,
			[1]={itemId=2261, count=3},
			[2]={itemId=2261, count=3},
			[3]={itemId=2261, count=3},
			[4]={itemId=2261, count=3},
			[5]={itemId=2305, count=2},
			[6]={itemId=2305, count=2},
			[7]={itemId=2305, count=2},
			[8]={itemId=2305, count=2},
			[9]={itemId=2310, count=3},
			[10]={itemId=2207, count=1},
			[11]={itemId=2562, count=0},
			[12]={itemId=2553, count=1},
		},
		{type=SLOT, slotId=SLOT_RIGHT, itemId=2534, count=1},
		{type=SLOT, slotId=SLOT_LEFT, itemId=2407, count=1},
		{type=SLOT, slotId=SLOT_NECKLACE, itemId=2171, count=1},
		{type=SLOT, slotId=SLOT_HEAD, itemId=2475, count=1},
		{type=SLOT, slotId=SLOT_ARMOR, itemId=2476, count=1},
		{type=SLOT, slotId=SLOT_LEGS, itemId=2477, count=1},
		{type=SLOT, slotId=SLOT_FEET, itemId=2643, count=1},
		{type=SLOT, slotId=SLOT_RING, itemId=2207, count=1},
		{type=SLOT, slotId=SLOT_AMMO, itemId=2152, count=64}
	}
}

function onLogin(cid)
	if isPlayer(cid) == TRUE then
		if getPlayerStorageValue(cid, STORAGE) == -1 then
			local items = defaultItems[getPlayerVocation(cid)]
			if getPlayerSlotItem(cid, 3).uid == 0 then
				local mainBackpack = doPlayerAddItem(cid, 1988, 1)
				for i = 1, #items do
					if (items[i].type == ITEM) then
						doAddContainerItem(mainBackpack, items[i].itemId, items[i].count)
					elseif (items[i].type == BACKPACK) then
						local bp = mainBackpack
						local bpInside = doAddContainerItem(bp, items[i].bpId, 1)
						for j=1, items[i].bpCount do
							bp = bpInside
							if (j < items[i].bpCount) then
								bpInside = doAddContainerItem(bp, items[i].bpId, 1)
							else
								doAddContainerItem(bp, items[i].itemId, items[i].count)
							end
							for g=1, 19 do
								doAddContainerItem(bp, items[i].itemId, items[i].count)
							end
						end
					elseif (items[i].type == ITEMS) then
						local bp = doAddContainerItem(mainBackpack, items[i].bpId, 1)
						for j=1, #items[i] do
							doAddContainerItem(bp, items[i][j].itemId, items[i][j].count)
						end
					end
				end
			end
			for i = 1, #items do
				if (items[i].type == SLOT) then
					if getPlayerSlotItem(cid, items[i].slotId).uid == 0 then
						doPlayerAddItem(cid, items[i].itemId, items[i].count)
					end
				end
			end
			setPlayerStorageValue(cid, STORAGE, 1)
		end
	end
	registerCreatureEvent(cid, "KillProtection")
 	return TRUE
end
 
Last edited:
Back
Top