• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TFS 1.5 strange problem with npcs [C]: in function '__newindex' table index is nil

johnsamir

Banned User
Joined
Oct 13, 2009
Messages
555
Solutions
5
Reaction score
98
Location
Nowhere
Have certain npcs with problem like for example dermot. the npc work
but when i try to get the key this error appear in the server console
Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/Dermot.lua:onCreatureSay
data/npc/scripts/lib/npcsystem/npchandler.lua:642: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/npc/scripts/lib/npcsystem/npchandler.lua:642: in function 'say'
        data/npc/scripts/Dermot.lua:56: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:420: in function 'onCreatureSay'
        data/npc/scripts/Dermot.lua:8: in function <data/npc/scripts/Dermot.lua:8>

Lua Script Error: [Npc interface]
data/npc/scripts/Dermot.lua:onCreatureSay
data/npc/scripts/lib/npcsystem/npchandler.lua:642: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/npc/scripts/lib/npcsystem/npchandler.lua:642: in function 'say'
        data/npc/scripts/Dermot.lua:56: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:420: in function 'onCreatureSay'
        data/npc/scripts/Dermot.lua:8: in function <data/npc/scripts/Dermot.lua:8>
the strange part is this error
Code:
data/npc/scripts/Dermot.lua:56: in function 'callback'
when i go to that line at dermot.lua is this:
Code:
npcHandler:say('Do you want to buy the dungeon key for 2000 gold?')

npcHandler:say work on the other npcs so is a little strange
and many other npcs does work with the same lua structure, as boat npc, or magicshop too and they are working as stated before.

this is full dermot.lua
Code:
    -- NPC Converter System - developed by Utroz <[email protected]>
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)    npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)    npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)    npcHandler:onCreatureSay(cid, type, msg) end
function onThink()    npcHandler:onThink() end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am the magistrate of this isle.'})

keywordHandler:addKeyword({'entrance'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The entrance is near here.'})

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    -- The Postman Missions Quest
    if msgcontains(msg, 'present') and getPlayerStorageValue(cid, 231) == 0 then
    npcHandler:say('I don\'t understand what you are talking about.')
    topic = 0
 
    elseif msgcontains(msg, 'present') and getPlayerStorageValue(cid, 231) == 1 then
    npcHandler:say('You have a present for me?? Really?')
    topic = 2
 
    elseif msgcontains(msg, 'yes') and getPlayerItemCount(cid, 2331) >= 1 and topic == 2 then
    doPlayerRemoveItem(cid,2331,1)
    setPlayerStorageValue(cid,231,2)
    npcHandler:say('Thank you very much!')
    topic = 0
 
    elseif msgcontains(msg, 'yes') and topic == 2 then
    npcHandler:say('What? There is no present, at least none for me! Stop this foolish jokes!')
    topic = 0
 
    elseif msgcontains(msg, '') and topic == 2 then
    npcHandler:say('Hmm, maybe next time.')
    topic = 0
 
    elseif msgcontains(msg, 'key') then
    npcHandler:say('Do you want to buy the dungeon key for 2000 gold?')
    topic = 1
 
    elseif msgcontains(msg, 'yes') and getPlayerMoney(cid) >= 2000 and topic == 1 then
    npcHandler:say('Now you own the key to the dungeon.')
    doPlayerRemoveMoney(cid, 2000)
    key = doPlayerAddItem(cid, 2089,1)
    doSetItemActionId(key,3940)
    doSetItemSpecialDescription(key, "(Key: 3940)")
    topic = 0
 
    elseif msgcontains(msg, 'yes') and getPlayerMoney(cid) < 2000 and topic == 1 then
    npcHandler:say('You\'ve not enough money to buy the key.')
    topic = 0
 
    elseif msgcontains(msg, '') and topic == 2 then
    npcHandler:say('Hmm, maybe next time.')
    topic = 0
    end
 
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Edit:
changed
Lua:
topic
for this
Code:
npcHandler.topic[cid]
same error

any idea? why table index is nil
 
Last edited:
OP
OP
J

johnsamir

Banned User
Joined
Oct 13, 2009
Messages
555
Solutions
5
Reaction score
98
Location
Nowhere

edit at your liking
worked good just changed
Lua:
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "present") then
        if player:getStorageValue(231) == 2 then
            npcHandler:say("You have a present for me?? Realy?", cid)
            npcHandler.topic[cid] = 1
        end
    elseif msgcontains(msg, "key") then
        npcHandler:say("Do you want to buy the dungeon key for 2000 gold?", cid)
        npcHandler.topic[cid] = 2
    elseif msgcontains(msg, "yes") then
        if npcHandler.topic[cid] == 1 then
            if player:removeItem(2331, 1) then
                npcHandler:say("Thank you very much!", cid)
                player:setStorageValue(231, 3)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 2 then
            if player:removeMoney(2000) then
                npcHandler:say("Here it is.", cid)
                local key = player:addItem(2087, 1)
                if key then
                    key:setActionId(3940)
                end
            else
                npcHandler:say("You don't have enough money.", cid)
            end
            npcHandler.topic[cid] = 0
        end
    end
    return true
end
and replaced the storage value.

thank evil puncker


im a bit anxious about what could be wrong. The order numbers of npcHandler.topic[cid] ?
 
Top