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

Lua [TFS 1.3] Making my quest npc more "smooth" - formattingwise

croix

Member
Joined
Aug 26, 2011
Messages
123
Reaction score
13
My quest NPCs are working atm, but they're not really smooth since (this npc for example) will always say
Code:
My friend Rihanna has gone missing, last time I saw her was under the sewers here in the city! Can you please help me find her?
and firstly after the character says "help" the npc message will change, next time i visit the NPC he will still start by saying these words.

How do I edit my formatting so it loads storage when character says hi and actually responds with what I want the NPC to respond?

Code:
Have you found her yet?
- if the quest is started but not finished, etc

Any help is appreciated! - Here's my .lua, the version is tfs 1.3 for tibia 8.6 (nekiro downgrade.)

Lua:
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

-- QUEST --
function Task1(cid, message, keywords, parameters, node)

local stor1 = 25578 -- this is the same STOR1 from quests.xml

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if getPlayerStorageValue(cid,stor1) < 0 then
                npcHandler:say('I will be waiting for you! I hope you can find her..',cid)
            setPlayerStorageValue(cid, stor1, 1)
    elseif getPlayerStorageValue(cid, stor1) == 1 then
                npcHandler:say('Have you found her?',cid)
    elseif getPlayerStorageValue(cid, stor1) == 4 then
                npcHandler:say('Thank you for finding her! Now I need to put my moves in.. Here, take this a reward!',cid)
            doPlayerAddItem(cid, 2647, 1)
            doPlayerAddItem(cid, 2463, 1)
            setPlayerStorageValue(cid, stor1, 5)
                 doSendMagicEffect(getCreaturePosition(cid), 13)
    elseif getPlayerStorageValue(cid, stor1) == 5 then
                npcHandler:say('Thank you for finding Rihanna!',cid)
    end
end

local node1 = keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "My friend Rihanna has gone missing, last time I saw her was under the sewers here in the city! Can you please help me find her?"})
      node1:addChildKeyword({'yes'}, Task1, {})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Very well then.', reset = true})

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

function onCreatureAppear(cid)              npcHandlernCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandlernCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandlernCreatureSay(cid, type, msg)    end
function onThink()                          npcHandlernThink()                        end

local storage_1 = 25578

local function greetCallback(cid)
    local player = Player(cid)
    local storage = player:getStorageValue(storage_1)
    if storage < 0 then
        npcHandler:setMessage(MESSAGE_GREET, "My friend Rihanna has gone missing...
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandlernCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandlernCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandlernCreatureSay(cid, type, msg)    end
function onThink()                          npcHandlernThink()                        end

local storage_1 = 25578

local function greetCallback(cid)
    local player = Player(cid)
    local storage = player:getStorageValue(storage_1)
    if storage < 0 then
        npcHandler:setMessage(MESSAGE_GREET, "My friend Rihanna has gone missing! Can you {help}?")
        return true
    elseif storage < 5 then
        npcHandler:setMessage(MESSAGE_GREET, "Have you found her?")
        return true
    elseif storage == 5 then
        npcHandler:setMessage(MESSAGE_GREET, "Thank you for finding Rihanna!")
        return true
    end
    npcHandler:setMessage(MESSAGE_GREET, "Hello! How can I help you?") -- should never see this message, based on how your npc is setup
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
  
    local player = Player(cid)
    local storage = player:getStorageValue(storage_1)

    -- starting quest
    if msgcontains(msg, "help") and storage < 0 then
        npcHandler:say("My friend Rihanna has gone missing, last time I saw her was under the sewers here in the city! Can you please help me find her?", cid)
        npcHandler.topic[cid] = 1
      
    -- starting quest yes/no reply from player
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            player:setStorageValue(storage_1, 1)
            npcHandler:say("I will be waiting for you! I hope you can find her..", cid)
        else
            npcHandler:say("Very well then.", cid)
        end
        npcHandler.topic[cid] = 0
      
    -- if player has started but not finished quest yet
    elseif storage > 0 and storage < 5 then
        if msgcontains(msg, "yes") then
            if storage == 4 then
                player:addItem(2647, 1)
                player:addItem(2463, 1)
                player:setStorageValue(storage_1, 5)
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                npcHandler:say("Thank you for finding her! Now I need to put my moves in.. Here, take this a reward!", cid)
            else               
                npcHandler:say("It doesn't seem like you've found her? Please continue your quest to find her..!", cid)
            end
        else
            npcHandler:say("Please continue your quest to find her! I will be so grateful..", cid)
        end

    end
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = nil
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())
 
Last edited by a moderator:
Solution
Try this. Let me know if you need any explanations.

Lua:
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 storage_1 = 25578

local function greetCallback(cid)
    local player = Player(cid)
    local storage = player:getStorageValue(storage_1)
    if storage < 0 then
        npcHandler:setMessage(MESSAGE_GREET, "My friend Rihanna has gone missing! Can you {help}?")
        return true
    elseif storage < 5 then
        npcHandler:setMessage(MESSAGE_GREET, "Have you found her?")
        return true
    elseif storage == 5 then
        npcHandler:setMessage(MESSAGE_GREET, "Thank you for finding Rihanna!")
        return true
    end
    npcHandler:setMessage(MESSAGE_GREET, "Hello! How can I help you?") -- should never see this message, based on how your npc is setup
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local player = Player(cid)
    local storage = player:getStorageValue(storage_1)

    -- starting quest
    if msgcontains(msg, "help") and storage < 0 then
        npcHandler:say("My friend Rihanna has gone missing, last time I saw her was under the sewers here in the city! Can you please help me find her?", cid)
        npcHandler.topic[cid] = 1
       
    -- starting quest yes/no reply from player
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            player:setStorageValue(storage_1, 1)
            npcHandler:say("I will be waiting for you! I hope you can find her..", cid)
        else
            npcHandler:say("Very well then.", cid)
        end
        npcHandler.topic[cid] = 0
       
    -- if player has started but not finished quest yet
    elseif storage > 0 and storage < 5 then
        if msgcontains(msg, "yes") then
            if storage == 4 then
                player:addItem(2647, 1)
                player:addItem(2463, 1)
                player:setStorageValue(storage_1, 5)
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                npcHandler:say("Thank you for finding her! Now I need to put my moves in.. Here, take this a reward!", cid)
            else               
                npcHandler:say("It doesn't seem like you've found her? Please continue your quest to find her..!", cid)
            end
        else
            npcHandler:say("Please continue your quest to find her! I will be so grateful..", cid)
        end

    end
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = nil
end

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

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

Damn, didn't expect a working solution lol. Thanks alot, i'll be testing it asap.
 
It sure did! You just forgot npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback), but other than that so! :)
I wasn't sure if that was required and deleted it. :lul
I'll edit my post and add that in.
 
I wasn't sure if that was required and deleted it. :lul
I'll edit my post and add that in.

The thought that you removed it actually crossed my mind because of the spacing between
Lua:
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
:D
 
Back
Top