• 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+ TFS 1.5 7.72 npc

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
928
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
I managed to put together a script to talk and exchange a bread for a key, but I'm not able to force the player to say morrin first. I can jump straight to the key, how do I force the player to say morrin first?
WhatsApp Image 2022-09-29 at 20.17.41.jpeg
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if (msgcontains(msg, 'morrin') and Topic[cid] >= 1) then
        npcHandler:say(" Ah, I remember that man. We made a deal, guess about what.",cid)
        Topic[cid] = 1
    end

    if msgcontains(msg, 'key') then
        npcHandler:say('Right! We can make the same deal if you give a fresh delicious roll. Do you have any?', cid)
        npcHandler.topic[cid] = 2
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 2 then
            local player = Player(cid)
            if doPlayerRemoveItem(cid,2690,1) then
                npcHandler:say('Here it is.', cid)
                local key = player:addItem(2089, 1)
                if key then
                    key:setActionId(4022)
                end
            else
                npcHandler:say('Come back when you have delicious roll.', cid)
            end
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, 'no') then
        if npcHandler.topic[cid] == 1 then
            npcHandler:say('Believe me, it\'s better for you that way.', cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:addModule(FocusModule:new())
 
Solution
I managed to put together a script to talk and exchange a bread for a key, but I'm not able to force the player to say morrin first. I can jump straight to the key, how do I force the player to say morrin first?
View attachment 70912
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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 function...
Try this.

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

-- OTServ event handling functions start
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, 'morrin') and npcHandler.topic[cid] == 0 then
        npcHandler:say(" Ah, I remember that man. We made a deal, guess about what.",cid)
        npcHandler.topic[cid] = 1
    elseif msgcontains(msg, 'key') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Right! We can make the same deal if you give a fresh delicious roll. Do you have any?', cid)
        npcHandler.topic[cid] = 2
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 2 then
            local player = Player(cid)
            if doPlayerRemoveItem(cid,2690,1) then
                npcHandler:say('Here it is.', cid)
                local key = player:addItem(2089, 1)
                if key then
                    key:setActionId(4022)
                end
            else
                npcHandler:say('Come back when you have delicious roll.', cid)
            end
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:addModule(FocusModule:new())
 
I managed to put together a script to talk and exchange a bread for a key, but I'm not able to force the player to say morrin first. I can jump straight to the key, how do I force the player to say morrin first?
View attachment 70912
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if (msgcontains(msg, 'morrin') and Topic[cid] >= 1) then
        npcHandler:say(" Ah, I remember that man. We made a deal, guess about what.",cid)
        Topic[cid] = 1
    end

    if msgcontains(msg, 'key') then
        npcHandler:say('Right! We can make the same deal if you give a fresh delicious roll. Do you have any?', cid)
        npcHandler.topic[cid] = 2
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 2 then
            local player = Player(cid)
            if doPlayerRemoveItem(cid,2690,1) then
                npcHandler:say('Here it is.', cid)
                local key = player:addItem(2089, 1)
                if key then
                    key:setActionId(4022)
                end
            else
                npcHandler:say('Come back when you have delicious roll.', cid)
            end
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, 'no') then
        if npcHandler.topic[cid] == 1 then
            npcHandler:say('Believe me, it\'s better for you that way.', cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:addModule(FocusModule:new())
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

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if msgcontains(msg, 'morrin') then
        npcHandler:say("Ah, I remember that man. We made a deal, guess about what..", cid)
        npcHandler.topic[cid] = 1

    elseif msgcontains(msg, 'key') and npcHandler.topic[cid] == 1 then
        npcHandler:say("Right! We can make the same deal if you give a fresh delicious roll. Do you have any?", cid)
        npcHandler.topic[cid] = 2

    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 2 then
        if player:removeItem(2690, 1) then
            local key = player:addItem(2088, 1)
            if key then
                key:setActionId(4022)
            end
            npcHandler:say("Oh, fine! Here you are.", cid)
        else
            npcHandler:say("it seems to me that you don't have any.", cid)
        end
            npcHandler.topic[cid] = 0

    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 then
        npcHandler:say('alright.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top