• 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 [SQLite] -=[TFS]=- 0.4 8.60 ERROR FIRSTITEMS CONSOLE SHOW ERRO

samuel157

/root
Joined
Mar 19, 2010
Messages
447
Solutions
3
Reaction score
49
Location
São Paulo, Brazil
GitHub
Samuel10M
Lua:
[12/09/2023 21:52:19] [Error - CreatureScript Interface]
[12/09/2023 21:52:19] data/creaturescripts/scripts/firstitems.lua:onLogin
[12/09/2023 21:52:19] Description:
[12/09/2023 21:52:20] data/creaturescripts/scripts/firstitems.lua:55: bad argument #1 to 'maxn' (table expected, got nil)
[12/09/2023 21:52:20] stack traceback:
[12/09/2023 21:52:20]     [C]: in function 'maxn'
[12/09/2023 21:52:21]     data/creaturescripts/scripts/firstitems.lua:55: in function <data/creaturescripts/scripts/firstitems.lua:53>
 
Solution
Lua:
local firstItems = {}
firstItems[0] = { 2173, 2525, 2428, 2124, 2460, 2478, 2643 }
firstItems[1] = { 2173, 2525, 2190, 2124, 2460, 2478, 2643 }
firstItems[2] = { 2173, 2525, 2182, 2124, 2460, 2478, 2643 }
firstItems[3] = { 2173, 2525, 2389, 2124, 2460, 2478, 2643 }
firstItems[4] = { 2173, 2525, 2428, 2124, 2460, 2478, 2643 }

function onLogin(cid)
    if getPlayerStorageValue(cid, 30001) == -1 then
        local vocation = getPlayerVocation(cid)
        if vocation ~= nil then
            local vocationId = vocation - 1
            local items = firstItems[vocationId]
            
            if items ~= nil then
                for i = 1, #items do
                    doPlayerAddItem(cid, items[i], 1)
                end
            else...
YES @Fjorda

Lua:
local firstItems = {}
firstItems[0] =
{
2173,
2525,
2428,
2124,
2460,
2478,
2643
}
firstItems[1] =
{
2173,
2525,
2190,
2124,
2460,
2478,
2643
}
firstItems[2] =
{
2173,
2525,
2182,
2124,
2460,
2478,
2643
}
firstItems[3] =
{
2173,
2525,
2389,
2124,
2460,
2478,
2643
}
firstItems[4] =
{
2173,
2525,
2428,
2124,
2460,
2478,
2643
}

function onLogin(cid)
if getPlayerStorageValue(cid, 30001) == -1 then
for i = 1, table.maxn(firstItems[getPlayerVocation(cid)]) do
doPlayerAddItem(cid, firstItems[getPlayerVocation(cid)][i], 1)
end
if getPlayerSex(cid) == 0 then
doPlayerAddItem(cid, 2465, 1)
else
doPlayerAddItem(cid, 2465, 1)
end
local bag = doPlayerAddItem(cid, 10518, 1)
doAddContainerItem(bag, 2160, 100)
doAddContainerItem(bag, 2554, 1)
doAddContainerItem(bag, 2120, 1)
doAddContainerItem(bag, 7618, 1)
doAddContainerItem(bag, 2383, 1)
doAddContainerItem(bag, 2553, 1)
setPlayerStorageValue(cid, 30001, 1)
end
return TRUE
end
 
Lua:
local firstItems = {}
firstItems[0] = { 2173, 2525, 2428, 2124, 2460, 2478, 2643 }
firstItems[1] = { 2173, 2525, 2190, 2124, 2460, 2478, 2643 }
firstItems[2] = { 2173, 2525, 2182, 2124, 2460, 2478, 2643 }
firstItems[3] = { 2173, 2525, 2389, 2124, 2460, 2478, 2643 }
firstItems[4] = { 2173, 2525, 2428, 2124, 2460, 2478, 2643 }

function onLogin(cid)
    if getPlayerStorageValue(cid, 30001) == -1 then
        local vocation = getPlayerVocation(cid)
        if vocation ~= nil then
            local vocationId = vocation - 1
            local items = firstItems[vocationId]
            
            if items ~= nil then
                for i = 1, #items do
                    doPlayerAddItem(cid, items[i], 1)
                end
            else
                print("Vocation not found in firstItems.")
            end
            
            if getPlayerSex(cid) == 0 then
                doPlayerAddItem(cid, 2465, 1)
            else
                doPlayerAddItem(cid, 2465, 1)
            end
            
            local bag = doPlayerAddItem(cid, 10518, 1)
            doAddContainerItem(bag, 2160, 100)
            doAddContainerItem(bag, 2554, 1)
            doAddContainerItem(bag, 2120, 1)
            doAddContainerItem(bag, 7618, 1)
            doAddContainerItem(bag, 2383, 1)
            doAddContainerItem(bag, 2553, 1)
            
            setPlayerStorageValue(cid, 30001, 1)
        else
            print("Vocation not found.")
        end
    end
    return true
end

or

Lua:
local firstItems = {}
firstItems[0] =
{
    2173,
    2525,
    2428,
    2124,
    2460,
    2478,
    2643
}
firstItems[1] =
{
    2173,
    2525,
    2190,
    2124,
    2460,
    2478,
    2643
}
firstItems[2] =
{
    2173,
    2525,
    2182,
    2124,
    2460,
    2478,
    2643
}
firstItems[3] =
{
    2173,
    2525,
    2389,
    2124,
    2460,
    2478,
    2643
}
firstItems[4] =
{
    2173,
    2525,
    2428,
    2124,
    2460,
    2478,
    2643
}

function onLogin(cid)
    if getPlayerStorageValue(cid, 30001) == -1 then
        local vocation = getPlayerVocation(cid)
        if vocation ~= nil and vocation >= 0 and vocation <= 4 then
            for i = 1, #firstItems[vocation] do
                doPlayerAddItem(cid, firstItems[vocation][i], 1)
            end
        end
        doPlayerAddItem(cid, 2465, 1)
        local bag = doPlayerAddItem(cid, 10518, 1)
        doAddContainerItem(bag, 2160, 100)
        doAddContainerItem(bag, 2554, 1)
        doAddContainerItem(bag, 2120, 1)
        doAddContainerItem(bag, 7618, 1)
        doAddContainerItem(bag, 2383, 1)
        doAddContainerItem(bag, 2553, 1)
        setPlayerStorageValue(cid, 30001, 1)
    end
    return true
end
 
Solution
Back
Top