• 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+ Strange issue with Npcs messages - tfs 1.5 7,72 [npc libraries by nekiro]

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,990
Solutions
9
Reaction score
334
Location
Chile
Hello I have a very strange error in my npcs files and the error is the following:

Others players can't see what npcs replies while is talking to a player. The problem here is that my server is 7.72 so players does not talk in npcs channels the chat in main default channel
here is an example of a npc. please help
Lua:
dofile('data/npc/scripts/lib/greeting.lua')

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

-- OTServ event handling functions
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

keywordHandler:addKeyword({'kevin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "That name sounds familiar... who might that be..."})
keywordHandler:addKeyword({'postner'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "That name sounds familiar... who might that be..."})
keywordHandler:addKeyword({'postmasters guild'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Hm, I think I heard about that guild... oh wait, I am a member!"})
keywordHandler:addKeyword({'join'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Uh... oh... Uhm... Join what?"})
keywordHandler:addKeyword({'headquarter'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Its just... I mean... there was that road, oh yes, its that house at that road."})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Sorry, I'm just an illusion NPC, wait to next update to make my missions.."})
keywordHandler:addKeyword({'quest'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Sorry, I'm just an illusion NPC, wait to next update to make my missions.."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am working here at the post office. If you have questions about the Royal Tibia Mail System or the depots ask me."})
keywordHandler:addKeyword({'office'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am always in my office. You are welcome at any time."})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "My name is Benjamin."})
keywordHandler:addKeyword({'depot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The depots are very easy to use. Just step in front of them and you will find your items in them. They are free for all tibian citizens. Hail our king!"})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Oops, the king? I... can't remember his name..."})
keywordHandler:addKeyword({'tibianus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ah, King Tibianus, our wise ruler. He is sick for some time, isn't he?"})
keywordHandler:addKeyword({'quentin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ooooh, nice man, visits me often... I think."})
keywordHandler:addKeyword({'lynda'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "She is SO pretty!"})
keywordHandler:addKeyword({'harkath'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Oh, young Harkath will be a fine warrior some day."})
keywordHandler:addKeyword({'army'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "TO THE ARMS! MAN THE WALLS! FERUMBRAS IS NEAR!"})
keywordHandler:addKeyword({'ferumbras'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "TO THE ARMS! MAN THE WALLS! FERUMBRAS IS NEAR!"})
keywordHandler:addKeyword({'general'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "TO THE ARMS! MAN THE WALLS! FERUMBRAS IS NEAR!"})
keywordHandler:addKeyword({'sam'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ham? No thanks, I ate fish already."})
keywordHandler:addKeyword({'frodo'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Frodo... Frodo... ? Uhm... isn't that the man that brings me food at lunchtime?"})
keywordHandler:addKeyword({'gorn'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He sells equipment."})
keywordHandler:addKeyword({'elane'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Oh, she lives next door. I think she's a dentist, I sometimes hear some cries."})
keywordHandler:addKeyword({'muriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "This Muriel has a lot of correspondence."})
keywordHandler:addKeyword({'gregor'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Never heared of him."})
keywordHandler:addKeyword({'marvik'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He is always talking of healing me but I am fine... I fear he is a little nuts, poor man."})
keywordHandler:addKeyword({'bozo'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "He hangs around here quite often. He claimes, I inspire him."})
keywordHandler:addKeyword({'baxter'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "This naughty child, always stealing apples!"})
keywordHandler:addKeyword({'sherry'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I don't drink alcohol while on duty."})
keywordHandler:addKeyword({'lugri'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "NO! NO! NO! GO AWAY!."})
keywordHandler:addKeyword({'excalibug'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can't remember that someone named like that lives here."})
keywordHandler:addKeyword({'news'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Sorry, I don't read the letters we transmit."})
keywordHandler:addKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "This is the town you are currently in."})
keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "You can sent letters and parcels to Carlin."})
keywordHandler:addKeyword({'xodet'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The young sorcerer is a good businessman."})
keywordHandler:addKeyword({'quero'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I love his music! He is my best friend and I visit him as often as I can."})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Now it\'s |TIME|. Maybe you want to buy a watch?"})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Now it's |TIME|. Maybe you want to buy a watch?"})

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

if msgcontains(msg, 'parcel') or msgcontains(msg, 'Parcel') then
    itemname = "parcel"
    itemprice = 10
    npcHandler:say("Would you like to buy a parcel for 10 gold?", cid)
    talk_state = 8595
   
elseif msgcontains(msg, 'letter') or msgcontains(msg, 'Letter') then
    itemname = "letter"
    itemprice = 5
    npcHandler:say("Would you like to buy a letter for 5 gold?", cid)
    talk_state = 8596  
           
elseif talk_state == 8595 and msgcontains(msg, 'yes') or talk_state == 8595 and msgcontains(msg, 'Yes') then
    if doPlayerRemoveMoney(cid, 10) == true then
        npcHandler:say("Here you are. Don't forget to write the name and the address of the receiver on the label. The label has to be in the parcel before you put the parcel in a mailbox.", cid)
        doPlayerAddItem(cid, 2595)
        doPlayerAddItem(cid, 2599)
    else
    npcHandler:say("Oh, you do not have enough gold to buy a ".. itemname ..".", cid)
    end
elseif talk_state == 8596 and msgcontains(msg, 'yes') or talk_state == 8596 and msgcontains(msg, 'Yes') then
    if doPlayerRemoveMoney(cid, 5) == true then
        npcHandler:say("Here it is. Don't forget to write the name of the receiver in the first line and the address in the second one before you put the letter in a mailbox.", cid)
        doPlayerAddItem(cid, 2597)
    else
    npcHandler:say("Oh, you do not have enough gold to buy a ".. itemname ..".", cid)
    end
   
elseif talk_state == 8595 and msgcontains(msg, '') then
npcHandler:say("Ok.", cid)
elseif talk_state == 8596 and msgcontains(msg, '') then
npcHandler:say("Ok.", cid)

elseif  msgcontains(msg, 'mail') then
    npcHandler:say('Our mail system is unique! And everyone can use it. Do you want to know more about it?', 1)
    talk_state = 505  

        elseif talk_state == 505 and msgcontains(msg, 'yes') then
        npcHandler:say('The Tibia Mail System enables you to send and receive letters and parcels. You can buy them here if you want.', 1)
        talk_state = 0
        elseif talk_state == 505 and msgcontains(msg, 'no') then
        npcHandler:say('Is there anything else I can do for you?', 1)
        talk_state = 0

    -- The Postman Missions Quest  
    elseif msgcontains(msg, 'measurements') and getPlayerStorageValue(cid,234) > 0 and getPlayerStorageValue(cid,236) < 1 then
    npcHandler:say('Oh they dont change that much since in the old days as... <tells a boring and confusing story about a cake, a parcel, himself and two squirrels, at least he tells you his measurements in the end>')
    setPlayerStorageValue(cid,236,1)
    setPlayerStorageValue(cid,234,getPlayerStorageValue(cid,234)+1)
   
end      
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hmm.. it should. Did you restart OTS after that change? /reload may not work.

Problem is in this line:
If you set NPCHANDLER_TALKDELAY = TALKDELAY_NONE, it will go into that if and execute:
which sends message to everyone on screen.

Without TALKDELAY_NONE it will execute:
which will execute:
and send message only to current NPC focus.

You right. I've made the changes and just said HI to npc, and others players didn't saw the reply. BUT. If i go further on conversation, like, "buy backpack", other players do see the reply.

It's because the greeting msg don't have this condition of " IF TALKDELAY blabla" its only this:
Lua:
    -- Greets a new player.
    function NpcHandler:greet(cid)
        if cid ~= 0 then
            local callback = self:getCallback(CALLBACK_GREET)
            if callback == nil or callback(cid) then
                if self:processModuleCallback(CALLBACK_GREET, cid) then
                    local msg = self:getMessage(MESSAGE_GREET)
                    local player = Player(cid)
                    local playerName = player and player:getName() or -1
                    local parseInfo = { [TAG_PLAYERNAME] = playerName }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg, cid, true)
                else
                    return
                end
            else
                return
            end
        end
        self:addFocus(cid)
    end
Post automatically merged:

idk if this is only for me, but, i saw now that the npcs always greets with the first player name that he talked..

e.g.
i do a reload /all
with player1 i say hi to npc, he responds "hello player1" (correct)
i say hi with player2 he says "hello player1" (wrong)

i say bye with player1 he says "bye player1" (correct)
i say bye with player2 he says "bye player2" (correct)

after the first greet msg, npc always say greet msg to the first player...
i can go with any character, he always say "hello player1"
farewell msgs are OK.. idk why.
 
Last edited:
Hmm.. it should. Did you restart OTS after that change? /reload may not work.

Problem is in this line:
If you set NPCHANDLER_TALKDELAY = TALKDELAY_NONE, it will go into that if and execute:
which sends message to everyone on screen.

Without TALKDELAY_NONE it will execute:
which will execute:
and send message only to current NPC focus.
@Gesior.pl Hello, Man and how do I do if I want that NPC only interact with one player at a time? By now everyone can talk to npc even is the npc is already busy talking to another player
@mano368 maybe do you know, or have seen this before?
Lua:
19:08 GM Ratx [37]: hi
19:08 Lily: Welcome, GM Ratx.
19:08 Testi [7]: hi
19:08 Lily: Welcome, Testi.
to
Code:
19:08 GM Ratx [37]: hi
19:08 Lily: Welcome, GM Ratx.
19:08 Testi [7]: hi
19:08 Lily: Welcome, Testi.
in this case i would expect that lily the NPC would have said to testi. That she is busy. What should i do in order to achieve this?

thanks in advance
 
You right. I've made the changes and just said HI to npc, and others players didn't saw the reply. BUT. If i go further on conversation, like, "buy backpack", other players do see the reply.

It's because the greeting msg don't have this condition of " IF TALKDELAY blabla" its only this:
Lua:
    -- Greets a new player.
    function NpcHandler:greet(cid)
        if cid ~= 0 then
            local callback = self:getCallback(CALLBACK_GREET)
            if callback == nil or callback(cid) then
                if self:processModuleCallback(CALLBACK_GREET, cid) then
                    local msg = self:getMessage(MESSAGE_GREET)
                    local player = Player(cid)
                    local playerName = player and player:getName() or -1
                    local parseInfo = { [TAG_PLAYERNAME] = playerName }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg, cid, true)
                else
                    return
                end
            else
                return
            end
        end
        self:addFocus(cid)
    end
Post automatically merged:

idk if this is only for me, but, i saw now that the npcs always greets with the first player name that he talked..

e.g.
i do a reload /all
with player1 i say hi to npc, he responds "hello player1" (correct)
i say hi with player2 he says "hello player1" (wrong)

i say bye with player1 he says "bye player1" (correct)
i say bye with player2 he says "bye player2" (correct)

after the first greet msg, npc always say greet msg to the first player...
i can go with any character, he always say "hello player1"
farewell msgs are OK.. idk why.
just to complement:
this bug of the greeting msg was because my npc (al dee) was set this way:
Lua:
npcHandler:setMessage(MESSAGE_GREET, {
    'Hello, hello, |PLAYERNAME|! Please come in, look, and buy! I\'m a specialist for all sorts of {tools}. Just ask me for a {trade} to see my offers! You can also ask me for general {hints} about the game. ...',
    'You can also ask me about each {citizen} of the isle.'
})
the greet msg had 2 msgs in an array.. now, i changed to:
Lua:
npcHandler:setMessage(MESSAGE_GREET, 
    'Hello, hello, |PLAYERNAME|! Please come in, look, and buy! I\'m a specialist for all sorts of {tools}. Just ask me for a {trade} to see my offers! You can also ask me for general {hints} about the game. ...'
)
and it works fine..
Post automatically merged:

I just wanted players to see the npc's conversation xD
about that i didn't figured out a solution, i'm a little busy atm but when i have time i'll try to fix, if i get it, i'll share.
 
I got this npchandler from a tibia global 7.6 but I would need to adapt it completely, it says in the default channel from what I understand
Post automatically merged:

any spectator options in the source that could resolve the messages?
 

Attachments

Last edited:
I got this npchandler from a tibia global 7.6 but I would need to adapt it completely, it says in the default channel from what I understand
Post automatically merged:

any spectator options in the source that could resolve the messages?
with this changes mine is working fine about this..
on data/npc/lib/npcsystem/npchandler.lua
line 10
from
NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK
to
NPCHANDLER_TALKDELAY = TALKDELAY_NONE

on data/npc/lib/npcsystem/npcsystem.lua
line 43
from
NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK
to
NPCHANDLER_TALKDELAY = TALKDELAY_NONE
 
Back
Top