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

TFS 1.X+ Quest NPC not applying storage

Eazzy

New Member
Joined
Mar 25, 2019
Messages
8
Solutions
1
Reaction score
1
Evening,
Seems i'm having trouble using the Advanced Npc Quest system from @Itutorial

Using the latest TFS 1.3.

My current code:

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

local vocation = {}
local town = {}
local destination = {}

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

--[[
    words = What the player says to the NPC
    reply = What the NPC says back.
    setStorage = If you want the NPC to set a storage to the player once he replies.
    setStorageNum = What to want to set the storage value to. eg: 1
    reqStorage = The NPC wont respond to the message unless that player has this storage set to a specific number
    reqStorageNum = The specific number of the required storage. eg: 4.
    items = You can add this to give a player items if they have the correct storage.
    exp = amount of exp given to the player.
]]--

local messages = {
    [1] = {
        words = {"yes"}, --If the player says any of these to the NPC
        reqStorage = nil, --The NPC checks this storage
        reqStorageNum = nil, -- If the reqStorage is == nil (or doesn't exist)
        reply = "Finally, I've been having trouble finding capable adventurers", --The NPC will reply with this
        setStorage = 44001, --Set his storage for the quest
        setStorageNum = 44001 -- To this value (starting the quest)
    },
        --At this point the player should of finished the quest and their storage value should of been changed to show he has completed it.
    [2] = {
        words = {"quest", "mission", "adventure", "task"},
        reqStorage = 44001,
        reqStorageNum = 44001,
        reply = "Thank you! Those bony creatures have been destorying all of our tombs.",
        setStorage = 44002,
        setStorageNum = 44002,
        items = {
            [1] = {itemid = 2152, amount = 3},
        },
        exp = 10000
    }
}


local function greetCallback(cid)
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    local player = Player(cid)
    
    if msg then
        for i = 1, #messages do
            if string.lower(msg) == messages[i].words then
                if player:getStorageValue(messages[i].reqStorage) == messages[i].reqStorageNum then
                    self:say(messages[i].reply, cid)
                    
                    if messages[i].setStorage then
                        player:setStorageValue(messages[i].setStorage, messages[i].setStorageNum)
                    end
                    
                    if messages[i].items then
                        for x = 1, #messages[i].items do
                            player:addItem(messages[i].items[x].itemid, messages[i].items[x].amount)
                        end
                    end
                    
                    if messages[i].exp then
                        player:addExperience(messages[i].exp)
                    end
                end
            end
        end
    end
    return true
end

local function onAddFocus(cid)
end

local function onReleaseFocus(cid)
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Change
Lua:
if string.lower(msg) == messages[i].words then
for
Lua:
if table.contains(messages[i].words, string.lower(msg)) then
 
Are there any errors in the console? What happens if you logout after saying yes?
No errors in console at all, I've tried relogging, creating a new account, characters and even re-compiling TFS because I quite fancy creating quests with dialogue.

Change
Lua:
if string.lower(msg) == messages[i].words then
for
Lua:
if table.contains(messages[i].words, string.lower(msg)) then
Didn't work, no error message either.

Am i doing someone wrong when setting up the NPC from my first post? I'd like to believe I'm not, but am no longer sure.
 
No errors in console at all, I've tried relogging, creating a new account, characters and even re-compiling TFS because I quite fancy creating quests with dialogue.


Didn't work, no error message either.

Am i doing someone wrong when setting up the NPC from my first post? I'd like to believe I'm not, but am no longer sure.
Do you have the required storage?

The way you have it scripted, is that if you don't have the required storage, the npc doesn't respond to you.

Let's put some replies in, so that you know what's happening.

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

local vocation = {}
local town = {}
local destination = {}

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

--[[
    words = What the player says to the NPC
    reply = What the NPC says back.
    setStorage = If you want the NPC to set a storage to the player once he replies.
    setStorageNum = What to want to set the storage value to. eg: 1
    reqStorage = The NPC wont respond to the message unless that player has this storage set to a specific number
    reqStorageNum = The specific number of the required storage. eg: 4.
    items = You can add this to give a player items if they have the correct storage.
    exp = amount of exp given to the player.
]]--

local messages = {
    [1] = {
        words = {"yes"}, --If the player says any of these to the NPC
        reqStorage = nil, --The NPC checks this storage
        reqStorageNum = nil, -- If the reqStorage is == nil (or doesn't exist)
        reply = "Finally, I've been having trouble finding capable adventurers", --The NPC will reply with this
        setStorage = 44001, --Set his storage for the quest
        setStorageNum = 44001 -- To this value (starting the quest)
    },
        --At this point the player should of finished the quest and their storage value should of been changed to show he has completed it.
    [2] = {
        words = {"quest", "mission", "adventure", "task"},
        reqStorage = 44001,
        reqStorageNum = 44001,
        reply = "Thank you! Those bony creatures have been destorying all of our tombs.",
        setStorage = 44002,
        setStorageNum = 44002,
        items = {
            [1] = {itemid = 2152, amount = 3},
        },
        exp = 10000
    }
}


local function greetCallback(cid)
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    local player = Player(cid)
    
    if msg then
        for i = 1, #messages do
            if table.contains(messages[i].words, string.lower(msg)) then
                if player:getStorageValue(messages[i].reqStorage) == messages[i].reqStorageNum then
                    self:say(messages[i].reply, cid)
                    
                    if messages[i].setStorage then
                        player:setStorageValue(messages[i].setStorage, messages[i].setStorageNum)
                    end
                    
                    if messages[i].items then
                        for x = 1, #messages[i].items do
                            player:addItem(messages[i].items[x].itemid, messages[i].items[x].amount)
                        end
                    end
                    
                    if messages[i].exp then
                        player:addExperience(messages[i].exp)
                    end
                    return true
                end
                self:say(msg .. " was found in table " .. i .. ", however the player does not have the required storage value.", cid)
                return true
            end
        end
        self:say(msg .. " is not in any of the 'words' tables.", cid)
    end
    return true
end

local function onAddFocus(cid)
end

local function onReleaseFocus(cid)
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I've got the same issue as @Eazzy , I believe?
here is the error:
Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/guide.lua:onCreatureSay
data/npc/scripts/guide.lua:82: attempt to index global 'self' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/guide.lua:82: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/guide.lua:11: in function <data/npc/scripts/guide.lua:11>

previously I tried to follow the same tutorial by @Itutorial, but ended having the same problem as fellow @nefinoo, and tried to apply the fix suggested, but did not manage anything useful, so I found this thread and got stuck again.

Lua:
[Warning - NpcScript::NpcScript] Can not load script: guide.lua
data/npc/scripts/guide.lua:33: '}' expected (to close '{' at line 26) near 'items'

Also using TFS 1.3
anyone know the fix to this issue?

thanks in advance,
Jaki
 
Back
Top