• 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())
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,610
Solutions
395
Reaction score
3,724
Change
Lua:
if string.lower(msg) == messages[i].words then
for
Lua:
if table.contains(messages[i].words, string.lower(msg)) then
 
OP
OP
Eazzy

Eazzy

New Member
Joined
Mar 25, 2019
Messages
8
Solutions
1
Reaction score
1
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.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,610
Solutions
395
Reaction score
3,724
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())
 
Top