• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Bug in NPC (answering in global chat and npc chat at same time)

1268995

Member
Joined
Sep 9, 2010
Messages
422
Reaction score
13
When i talk to any npc of server, they answer in global chat + npc chat... they answer 2 time..
how can i change that? 8.60

Edit: npc answer in both channels only in message_greet
 
Last edited:
@Nothxbye , i changed the code and let this way:

Code:
    -- 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 parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
                    msg = self:parseMessage(msg, parseInfo)
                   npcHandler:say('message', cid)
                else
                    return
                end
            else
                return
            end
        end
        self:changeFocus(cid)
    end

AND DO NOT WORK...
 
Try this....
Code:
    -- 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 parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg)
                else
                    return
                end
            else
                return
            end
        else
        self:changeFocus(cid)
        end
    end
 
and try this...

Code:
    -- Makes sure the npc un-focuses the furrently focused player, and greets the next player in the queue is it is not empty.
    function NpcHandler:unGreet()
        if(self.focus == 0) then
            return
        end
        local callback = self:getCallback(CALLBACK_FAREWELL)
        if(callback == nil or callback()) then
            if(self:processModuleCallback(CALLBACK_FAREWELL)) then
                if(self.queue == nil or not self.queue:greetNext()) then
                    local msg = self:getMessage(MESSAGE_FAREWELL)
                    local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg)
                    self:releaseFocus()
                end
            end
        end
    end
 
If none of this worked. Try deleting:
--In greet function
if(self:processModuleCallback(CALLBACK_GREET)) then
--in farwell
if(self:processModuleCallback(CALLBACK_FARWELL)) then


or try changing it with
--in greet
if(self:processModuleCallback(CALLBACK_GREET) ~= nil) then
--in farwell
if(self:processModuleCallback(CALLBACK_FARWELL) ~= nil) then
 
@Limos , do not work... he THE FIRST PAR OF npcchandler:

Code:
-- This file is part of Jiddo's advanced NpcSystem v3.0x. This npcsystem is free to use by anyone, for any purpuse.
-- Initial release date: 2007-02-21
-- Credits: Jiddo, honux(I'm using a modified version of his Find function).
-- Please include full credits whereever you use this system, or parts of it.
-- For support, questions and updates, please consult the following thread:
-- http://otfans.net/showthread.php?t=67810

if(NpcHandler == nil) then

    -- Constant talkdelay behaviors.
    TALKDELAY_NONE = 0 -- No talkdelay. Npc will reply immedeatly.
    TALKDELAY_ONTHINK = 1 -- Talkdelay handled through the onThink callback function. (Default)
    TALKDELAY_EVENT = 2 -- Not yet implemented

    -- Currently applied talkdelay behavior. TALKDELAY_ONTHINK is default.
    NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK



    -- Constant indexes for defining default messages.
    MESSAGE_GREET         = 1 -- When the player greets the npc.
    MESSAGE_FAREWELL     = 2 -- When the player unGreets the npc.
    MESSAGE_BUY         = 3 -- When the npc asks the player if he wants to buy something.
    MESSAGE_SELL         = 4 -- When the npc asks the player if he wants to sell something.
    MESSAGE_ONBUY         = 5 -- When the player successfully buys something
    MESSAGE_ONSELL         = 6 -- When the player successfully sells something
    MESSAGE_NEEDMOREMONEY = 7 -- When the player does not have enough money
    MESSAGE_NOTHAVEITEM = 8 -- When the player is trying to sell an item he does not have.
    MESSAGE_IDLETIMEOUT = 9 -- When the player has been idle for longer then idleTime allows.
    MESSAGE_WALKAWAY     = 10 -- When the player walks out of the talkRadius of the npc.
    MESSAGE_ALREADYFOCUSED = 11 -- When the player already has the focus of this nopc.
    MESSAGE_PLACEDINQUEUE = 12 -- When the player has been placed in the costumer queue.
    MESSAGE_DECLINE     = 13 -- When the player sais no to something.

    -- Constant indexes for callback functions. These are also used for module callback ids.
    CALLBACK_CREATURE_APPEAR     = 1
    CALLBACK_CREATURE_DISAPPEAR = 2
    CALLBACK_CREATURE_SAY         = 3
    CALLBACK_ONTHINK             = 4
    CALLBACK_GREET                 = 5
    CALLBACK_FAREWELL             = 6
    CALLBACK_MESSAGE_DEFAULT     = 7

    -- Addidional module callback ids
    CALLBACK_MODULE_INIT        = 10
    CALLBACK_MODULE_RESET        = 11


    -- Constant strings defining the keywords to replace in the default messages.
    TAG_PLAYERNAME = '|PLAYERNAME|'
    TAG_ITEMCOUNT = '|ITEMCOUNT|'
    TAG_TOTALCOST = '|TOTALCOST|'
    TAG_ITEMNAME = '|ITEMNAME|'
    TAG_QUEUESIZE = '|QUEUESIZE|'


    NpcHandler = {
        keywordHandler = nil,
        queue = nil,
        focus = 0,
        talkStart = 0,
        idleTime = 30,
        talkRadius = 5,
        talkDelayTime = 1, -- Seconds to delay outgoing messages.
        talkDelay = nil,
        callbackFunctions = nil,
        modules = nil,
        messages = {
                -- These are the default replies of all npcs. They can/should be changed individually for each npc.
            [MESSAGE_GREET]         = 'Welcome, |PLAYERNAME|! I have been expecting you.',
            [MESSAGE_FAREWELL]         = 'Good bye, |PLAYERNAME|!',
            [MESSAGE_BUY]             = 'Do you want to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
            [MESSAGE_SELL]             = 'Do you want to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
            [MESSAGE_ONBUY]         = 'It was a pleasure doing business with you.',
            [MESSAGE_ONSELL]         = 'Thank you for this item, |PLAYERNAME|.',
            [MESSAGE_NEEDMOREMONEY] = 'You do not have enough money.',
            [MESSAGE_NOTHAVEITEM]     = 'You don\'t even have that item!',
            [MESSAGE_IDLETIMEOUT]     = 'Next please!',
            [MESSAGE_WALKAWAY]         = 'How rude!',
            [MESSAGE_ALREADYFOCUSED]= '|PLAYERNAME|, I am already talking to you.',
            [MESSAGE_PLACEDINQUEUE] = '|PLAYERNAME|, please wait for your turn. There are |QUEUESIZE| customers before you.',
            [MESSAGE_DECLINE]        = 'Not good enough, is it?'
        }
    }


    -- Creates a new NpcHandler with an empty callbackFunction stack.
    function NpcHandler:new(keywordHandler)
        local obj = {}
        obj.callbackFunctions = {}
        obj.modules = {}
        obj.talkDelay = {
                message = nil,
                time = nil
            }
        obj.queue = Queue:new(obj)
        obj.keywordHandler = keywordHandler
        obj.messages = {}
        setmetatable(obj.messages, self.messages)
        self.messages.__index = self.messages
  
        setmetatable(obj, self)
        self.__index = self
        return obj
    end

    -- Re-defines the maximum idle time allowed for a player when talking to this npc.
    function NpcHandler:setMaxIdleTime(newTime)
        self.idleTime = newTime
    end

    -- Attaches a new costumer queue to this npchandler.
    function NpcHandler:setQueue(newQueue)
        self.queue = newQueue
        self.queue:setHandler(self)
    end

    -- Attackes a new keyword handler to this npchandler
    function NpcHandler:setKeywordHandler(newHandler)
        self.keywordHandler = newHandler
    end

    -- Function used to change the focus of this npc.
    function NpcHandler:changeFocus(newFocus)
        self.focus = newFocus
        self:updateFocus()
    end

    -- This function should be called on each onThink and makes sure the npc faces the player it is talking to.
    --    Should also be called whenever a new player is focused.
    function NpcHandler:updateFocus()
        doNpcSetCreatureFocus(self.focus)
    end

    -- Used when the npc should un-focus the player.
    function NpcHandler:releaseFocus()
        self:changeFocus(0)
    end

    -- Returns the callback function with the specified id or nil if no such callback function exists.
    function NpcHandler:getCallback(id)
        local ret = nil
        if(self.callbackFunctions ~= nil) then
            ret = self.callbackFunctions[id]
        end
        return ret
    end

    -- Changes the callback function for the given id to callback.
    function NpcHandler:setCallback(id, callback)
        if(self.callbackFunctions ~= nil) then
            self.callbackFunctions[id] = callback
        end
    end

    -- Adds a module to this npchandler and inits it.
    function NpcHandler:addModule(module)
        if(self.modules ~= nil) then
            table.insert(self.modules, module)
            module:init(self)
        end
    end

    -- Calls the callback function represented by id for all modules added to this npchandler with the given arguments.
    function NpcHandler:processModuleCallback(id, ...)
        local ret = true
        for i, module in pairs(self.modules) do
            local tmpRet = true
            if(id == CALLBACK_CREATURE_APPEAR and module.callbackOnCreatureAppear ~= nil) then
                tmpRet = module:callbackCreatureAppear(unpack(arg))
          
            elseif(id == CALLBACK_CREATURE_DISAPPEAR and module.callbackOnCreatureDisappear ~= nil) then
                tmpRet = module:callbackCreatureDisappear(unpack(arg))
          
            elseif(id == CALLBACK_CREATURE_SAY and module.callbackOnCreatureSay ~= nil) then
                tmpRet = module:callbackCreatureSay(unpack(arg))
          
            elseif(id == CALLBACK_ONTHINK and module.callbackOnThink ~= nil) then
                tmpRet = module:callbackOnThink(unpack(arg))
          
            elseif(id == CALLBACK_GREET and module.callbackOnGreet ~= nil) then
                tmpRet = module:callbackOnGreet(unpack(arg))
          
            elseif(id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil) then
                tmpRet = module:callbackOnFarewell(unpack(arg))
          
            elseif(id == CALLBACK_MESSAGE_DEFAULT and module.callbackOnMessageDefault ~= nil) then
                tmpRet = module:callbackOnMessageDefault(unpack(arg))
          
            elseif(id == CALLBACK_MODULE_RESET and module.callbackOnModuleReset ~= nil) then
                tmpRet = module:callbackOnModuleReset(unpack(arg))
            end
            if(not tmpRet) then
                ret = false
                break
            end
        end
        return ret
    end
Are you sure you are posting the right npchandler.lua?
This is not the npchandler.lua for TFS 0.3/0.4 8.6 versions (it's for older client versions), so unless you have in other scripts different functions that makes it respond in the NPCs channel and you use that in the NPCs, it can't be the one you are using since this npchandler.lua only makes the NPC respond in default.
 
Solved in teamviewer, his server was using a different npchandler.lua than the one he posted (there was an other lib folder added in the folder scripts for a different server and the posted npchandler.lua was from that folder).
Solution:
It's not a bug, but if you want to change it, remove this in the npchandler.lua (data/npc/lib/npcsystem/npchandler.lua) on line 346 (in function NpcHandler:greet(cid)).
Code:
self:say(msg)
This way it will only answer in the NPCs channel.
 
Back
Top