• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC MODULES ERROR: attempt to index a function value: getSpectators

Thaian Citizen

Hexenjäger
Joined
Apr 5, 2013
Messages
144
Solutions
4
Reaction score
17
Location
germany
Hello everyone, when I go to any npc and type something my server prints this error:
(further down you see the part of npcsystem/modules.lua that is refered to)

Code:
attempt to index a function value
stack traceback:
    [C]: in function 'getSpectators'
    data/npc/scripts/lib/npcsystem/modules.lua:275: in function <data/npc/scripts/lib/npcsystem/modules.lua:272>
    (tail call): ?
    data/npc/scripts/lib/npcsystem/keywordhandler.lua:176: in function 'processNodeMessage'
    data/npc/scripts/lib/npcsystem/keywordhandler.lua:133: in function 'processMessage'
    data/npc/scripts/lib/npcsystem/npchandler.lua:296: in function 'onCreatureSay'
    data/npc/scripts/spellsfree.lua:8: in function <data/npc/scripts/spellsfree.lua:8>

Here the modules.lua
Code:
        -- Custom message matching callback function for greeting messages.
        function FocusModule.messageMatcher(keywords, message)
                local spectators = Game.getSpectators(getCreaturePosition(getNpcId()), false, false, 0, 7, 0, 7)
                for i, word in pairs(keywords) do
                        if(type(word) == 'string') then
                                if(string.find(message, word) and not string.find(message, '[%w+]' .. word) and not string.find(message, word .. '[%w+]')) then
                                        if(string.find(message, getCreatureName(getNpcId()))) then
                                                return true
                                        end

                                        for i, uid in ipairs(spectators) do
                                                if(string.find(message, getCreatureName(uid))) then
                                                        return false
                                                end
                                        end

                                        return true
                                end
                        end
                end

                return false
        end

othire distro / edited / npc's yet untouched - only added advanced jiddo npc system (module)
(needed the advanced because regular othire was missing sellspell stuff for example)

I tried a few things but I can't really understand the misstake or I simply don't see it so I am kinda helpless when it comes to making up possible solutions
 
Hello everyone, when I go to any npc and type something my server prints this error:
(further down you see the part of npcsystem/modules.lua that is refered to)

Code:
attempt to index a function value
stack traceback:
    [C]: in function 'getSpectators'
    data/npc/scripts/lib/npcsystem/modules.lua:275: in function <data/npc/scripts/lib/npcsystem/modules.lua:272>
    (tail call): ?
    data/npc/scripts/lib/npcsystem/keywordhandler.lua:176: in function 'processNodeMessage'
    data/npc/scripts/lib/npcsystem/keywordhandler.lua:133: in function 'processMessage'
    data/npc/scripts/lib/npcsystem/npchandler.lua:296: in function 'onCreatureSay'
    data/npc/scripts/spellsfree.lua:8: in function <data/npc/scripts/spellsfree.lua:8>

Here the modules.lua
Code:
        -- Custom message matching callback function for greeting messages.
        function FocusModule.messageMatcher(keywords, message)
                local spectators = Game.getSpectators(getCreaturePosition(getNpcId()), false, false, 0, 7, 0, 7)
                for i, word in pairs(keywords) do
                        if(type(word) == 'string') then
                                if(string.find(message, word) and not string.find(message, '[%w+]' .. word) and not string.find(message, word .. '[%w+]')) then
                                        if(string.find(message, getCreatureName(getNpcId()))) then
                                                return true
                                        end

                                        for i, uid in ipairs(spectators) do
                                                if(string.find(message, getCreatureName(uid))) then
                                                        return false
                                                end
                                        end

                                        return true
                                end
                        end
                end

                return false
        end

othire distro / edited / npc's yet untouched - only added advanced jiddo npc system (module)
(needed the advanced because regular othire was missing sellspell stuff for example)

I tried a few things but I can't really understand the misstake or I simply don't see it so I am kinda helpless when it comes to making up possible solutions
Post spellsfree.lua
 
Okay I saw something in my spellsfree.lua which I removed (marked red)
Code:
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 node1 = keywordHandler:addKeyword({'find person'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn find person for 80 gp?'})
    node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'find person', vocation = {1, 5} , price = 80, level = 8})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
local node2 = keywordHandler:addKeyword({'light'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light for 100 gp?'})
    node2:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light', vocation = {1, 5} , price = 100, level = 8})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
local node3 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
    node3:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = {1, 5} , price = 170, level = 8})
    node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
npcHandler:addModule(FocusModule:new())

But now leaves me with this error:
Code:
attempt to call a nil value
stack traceback:

Lua Script Error: [Npc interface]
data/npc/scripts/spellsfree.lua

data/npc/scripts/spellsfree.lua:11: attempt to index global 'keywordHandler' (a nil value)
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/spellsfree.lua
 
Okay I saw something in my spellsfree.lua which I removed (marked red)
Code:
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 node1 = keywordHandler:addKeyword({'find person'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn find person for 80 gp?'})
    node1:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'find person', vocation = {1, 5} , price = 80, level = 8})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
local node2 = keywordHandler:addKeyword({'light'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light for 100 gp?'})
    node2:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light', vocation = {1, 5} , price = 100, level = 8})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
local node3 = keywordHandler:addKeyword({'light healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to learn light healing for 170 gp?'})
    node3:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, premium = false, spellName = 'light healing', vocation = {1, 5} , price = 170, level = 8})
    node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Cant you handle the power of the spell?', reset = true})
npcHandler:addModule(FocusModule:new())

But now leaves me with this error:
Code:
attempt to call a nil value
stack traceback:

Lua Script Error: [Npc interface]
data/npc/scripts/spellsfree.lua

data/npc/scripts/spellsfree.lua:11: attempt to index global 'keywordHandler' (a nil value)
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/spellsfree.lua
Something is wrong with your npc system its not creating the keywordhandler, you probably made something wrong when adding this "jiddo npc system" or it doesnt work.
 
Well yea I think the same, but it seems there are no more ressources and stuff for that, must be too outdated...
Guess I have to take the bite and reveserse to othire standard and code the spell selling part on my own ..
 
Back
Top