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

Solved [TFS 1.2] Addoner

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
I need help with my addoner npc. I'm trying to make it working on TFS 1.2.
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/[Addons].lua:onCreatureSay
data/npc/scripts/[Addons].lua:27: bad argument #1 to 'maxn' (table expected, got nil)
stack traceback:
        [C]: ?
        [C]: in function 'maxn'
        data/npc/scripts/[Addons].lua:27: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessage'
        data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeMessage'
        data/npc/lib/npcsystem/keywordhandler.lua:161: in function 'processMessage'
        data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
        data/npc/scripts/[Addons].lua:7: in function <data/npc/scripts/[Addons].lua:7>
http://pastebin.com/Vku26aCN
 
Last edited:
Just add this right above line 27
Code:
    if type(itemsTable) ~= "table" then
        return false
    end

So the code should look like this
Code:
    local itemsTable = parameters.items
    local items_list = ''
   
    if type(itemsTable) ~= "table" then
        return false
    end
   
    if table.maxn(itemsTable) > 0 then
        for i = 1, table.maxn(itemsTable) do
            local item = itemsTable[i]
            items_list = items_list .. item[2] .. ' ' .. Item:getName(item[1])
            if i ~= table.maxn(itemsTable) then
                items_list = items_list .. ', '
            end
        end
    end
 
If you don't understand how the table works, how do you expect to rewrite the whole script?
I didn't go through code all i did was resolve the error.
Hmm.. Maybe because i know the rest. Never saw an explaination how exactly tables work and here probably i have to put another table.
I will try to make this without table if no one will help.
 
Hmm.. Maybe because i know the rest. Never saw an explaination how exactly tables work and here probably i have to put another table.
I will try to make this without table if no one will help.
That is because you never bothered to look.
http://lua-users.org/wiki/TablesTutorial
There are many resources to learn lua the above link is just 1 of 100's of thousands of pages on the web.
 
I can't pass this error ._.
Someone please help with this addoner.
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/[Addons].lua:onCreatureSay
data/npc/scripts/[Addons].lua:22: bad argument #1 to 'maxn' (table expected, got nil)
stack traceback:
        [C]: ?
        [C]: in function 'maxn'
        data/npc/scripts/[Addons].lua:22: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessage'
        data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeMessage'
        data/npc/lib/npcsystem/keywordhandler.lua:161: in function 'processMessage'
        data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
        data/npc/scripts/[Addons].lua:7: in function <data/npc/scripts/[Addons].lua:7>
 
I need atleast explain how table works so maybe i could rewrite whole script.

So its failing here right:
Code:
local itemsTable = parameters.items
local items_list = ''
if table.maxn(itemsTable) > 0 then

If you pop the following code into your script, above those lines:
Code:
print(parameters.items)

As per the error you are getting, you will find parameters.items is returning nil.
(nil will be printed in your TFS console window.)

| The question is why is the data empty?​

Firstly, where is the data coming from?
Here:

| function playerBuyAddonNPC(cid, item, message, keywords, parameters, node)
Cool, secondly; where is that data parsed from?
Here, depending on what the player says:

| local outfit_node = keywordHandler:addKeyword({'first citizen'}, playerBuyAddonNPC,{premium =true, cost =0, items ={{5878,100}},outfit_female =136, outfit_male =128, addon =1, storageID =10001})​

So with all of this is mind, you should be able to get your head around how the script is supposed to work.
Can't really help anymore than this as I'm not familiar with the npchandler system and CBF digging through the ORTS source for examples.
 
Last edited:
Addoner.lua
http://pastebin.com/KiHx9g4T

Can you help me giving one cast system or one script dicer for tfs 1.2? My skype is: viking.mu
Thank you! Add me to skype, we will see if i can help you.

So its failing here right:
Code:
local itemsTable = parameters.items
local items_list = ''
if table.maxn(itemsTable) > 0 then

If you pop the following code into your script, above those lines:
Code:
print(parameters.items)

As per the error you are getting, you will find parameters.items is returning nil.
(nil will be printed in your TFS console window.)

| The question is why is the data empty?​

Firstly, where is the data coming from?
Here:

| function playerBuyAddonNPC(cid, item, message, keywords, parameters, node)
Cool, secondly; where is that data parsed from?
Here, depending on what the player says:

| local outfit_node = keywordHandler:addKeyword({'first citizen'}, playerBuyAddonNPC,{premium =true, cost =0, items ={{5878,100}},outfit_female =136, outfit_male =128, addon =1, storageID =10001})​

So with all of this is mind, you should be able to get your head around how the script is supposed to work.
Can't really help anymore than this as I'm not familiar with the npchandler system and CBF digging through the ORTS source for examples.
Well. I knew that before, it's basic to understand things like this. Still with that info i didn't knew how to fix it. Looks like i'll need more time to work with tables and stuff like this.
 
I know it's an old thread and it's marked as SOLVED, but I found the issue here and, as I found this thread through google, I think it would be nice to help others also looking for it.

The problem was in the function arguments. The right order, in line 10, should be playerBuyAddonNPC(cid, message, keywords, parameters, node), with no "item" argument. That's why the parameters were always returning nil.

Also, in order to get the addon item name in line 35, you should use ItemType(item[1]):getName()
 
Back
Top