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

C++ attempt to index global 'tasks' (a nil value)

Joined
Feb 10, 2021
Messages
25
Reaction score
6
Lua Script Error: [Npc interface]
data/npc/scripts/Raymond Striker.lua:eek:nCreatureSay
data/npc/scripts/Raymond Striker.lua:17: attempt to index upvalue 'pirate' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/Raymond Striker.lua:17: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:415: in function 'onCreatureSay'
data/npc/scripts/Raymond Striker.lua:10: in function <data/npc/scripts/Raymond Striker.lua:10>

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local pirate = tasks["pirate ghost"]

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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    elseif (msgcontains(msg, "task")) then
        if (getPlayerStorageValue(cid, pirate.storage) == -1) then
            selfSay("The pirates on Nargor are becoming more and more of a threat to us each day. I wish someone could get rid of them once and for all, but unfortunately they just keep coming! ...", cid)
            selfSay("Only a dead pirate is a good pirate. I think killing a large number of them would definitely help us to make Sabrehaven a safer place. ...", cid)
            selfSay("It doesn't matter how long it takes, but... would you be willing to kill 3000 pirates for us?", cid)
            Topic[cid] = 15
        elseif (getPlayerStorageValue(cid, pirate.storage) == pirate.amount) then
            selfSay("Hey, great. You've done well! As a small reward I give you some coins from our treasure box. Also, let me tell you an interesting piece of information. ...", cid)
            selfSay("One our of spies told us about a secret hideout somewhere on Nargor. Supposedly, one of the four pirate leaders can be found there sometimes. If you dare go there, you might be able to face him or her in one on one combat. ...", cid)
            selfSay("Beware though - prepare yourself well and only flee if you must. This might be your only chance to get into there, so be careful and don't die!", cid)
        end
    elseif (msgcontains(msg, "yes") and Topic[cid] == 15) then
        selfSay("Perfect. I know it sounds a lot, but really, take your time. You won't do it for nothing, I promise.", cid)
        setPlayerStorageValue(cid, pirate.storage, 0)
        Topic[cid] = 0
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
What is this supposed to be?
getPlayerStorageValue(cid, pirate.storage)
is it defined somewhere, in a lib?... if it is not anywhere, add it this way so that it is checked before the function, you have to do:

1. Replace everything that contains this:
pirate.storage

With this:
pirateStorage

2. Above the function:
function creatureSayCallback(cid, type, msg)

Add this with your local storage:
local pirateStorage = XXXX -- number of any storage
 
but how do I create a storage number? local pirateStorage = XXXX -- number of any storage ,

I honestly don't know how to do that
 
Last edited:
You are missing table "tasks" u will have more problems with other npc's quest's (from copied data pack) if u dont find this Table, it shouldbe somewhere on lib from data pack that you copied this npc
 
Last edited:
Back
Top