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

for table help needed.

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I'm trying to use the for function but I can't quite get something simple to work :(.

Could someone make this test script work,
because it gives this error
Code:
(luaDoPlayerAddItemEx) Item not found

script
Code:
local itemTable = {
	{5785}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local p = getPlayerPremiumDays(cid)
	if (item.itemid == 1740 and item.actionid == 100) then
		for _, i in ipairs(itemTable) do
			return doPlayerGiveItem(cid, i, 1)
		end
	end
	return true
end
 
Code:
local itemTable = {
	{5785}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 and item.actionid == 100 then
		for _, i in ipairs(itemTable) do
			doPlayerAddItem(cid, i, 1)
		end
	end
	return true
end
or;
Code:
local itemTable = {
	{5785}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 and item.actionid == 100 then
		doPlayerAddItem(cid, itemTable[1], 1)
	end
	return true
end
 
Last edited:
script #1 error:
Code:
[24/05/2010 21:31:46] [Error - Action Interface] 
[24/05/2010 21:31:46] data/actions/scripts/fortestitem.lua:onUse
[24/05/2010 21:31:46] Description: 
[24/05/2010 21:31:46] (luaDoPlayerAddItem) Item not found
script #2 error:
Code:
[24/05/2010 21:30:41] data/actions/scripts/fortestitem.lua:onUse
[24/05/2010 21:30:41] Description: 
[24/05/2010 21:30:41] data/actions/scripts/fortestitem.lua:6: attempt to index global 'i' (a nil value)
[24/05/2010 21:30:41] stack traceback:
[24/05/2010 21:30:41] 	data/actions/scripts/fortestitem.lua:6: in function <data/actions/scripts/fortestitem.lua:4>

and doPlayerAddItem() is the same as doPlayerGiveItem()
 
Code:
local itemTable = {
	{5785}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 and item.actionid == 100 then
		doPlayerAddItem(cid, itemTable[1], 1)
	end
	return true
end
sry
 
:S
Code:
local itemTable = {
	{5785}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 and item.actionid == 100 then
		for _, k in ipairs(itemTable) do
			if doPlayerAddItem(cid, k, 1, true) then
				doPlayerSendTextMessage(cid, 27, "Ok.")
			end
		end
	end
	return true
end
 
Here..

PHP:
local itemTable = {
    {5785}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1740 and item.actionid == 100 then
        for _, itemid in pairs(itemTable) do
               doPlayerAddItem(cid, itemid[1], 1)
        end
    end
    return true
end
 
Last edited:
Ups ye sorry I was in hurry
I edited my script /\ UP

or just use this one:
PHP:
local itemTable = {5785}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1740 and item.actionid == 100 then
        for item = 1,#itemTable do
               doPlayerAddItem(cid, itemTable[item], 1)
        end
    end
    return true
end
 
With variables
LUA:
local itemTable = 
{
	{item = 5785, count = 1}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1740 and item.actionid == 100 then
        for i = 1, table.maxn(itemTable) do
               doPlayerAddItem(cid, itemTable[i].item, itemTable[i].count)
        end
    end
    return true
end
 
Back
Top