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

Solved NPC msgcontains in default chat

Karain

Jack of all trades
Joined
Jul 9, 2009
Messages
338
Solutions
3
Reaction score
147
Location
Egypt
Hello, i ran into a problem where NPCs will not respond to keywords in default channel with msgcontains(msg, "text"), they only respond in NPC channel tho.

Is there a way to make the listen to both default channel and NPC channel?

it feels like i am missing something obvious to make it work.. but i've been at it for hours...

Thanks in advance.
 
Code:
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 function greetCallback(cid)
    local player = Player(cid)
self:say("hello there kid, Would you like to have some candy?", cid)
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
   if npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            npcHandler.topic[cid] = 2
            self:say("Great! you came to the right place", cid)
--code for candy shop
        end
    end
    return true
end

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

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, "Goodbye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Goodbye!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 

Attachments

NPCs will only respond to "hi" in default channel and any further keyword in npc channel.

If you want to change that you have to edit:
if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then
in npchandler.lua
 
Thanks a lot Summ.

I replaced in npchandler.lua

Code:
if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then

with

Code:
if self:isFocused(cid) and (msgtype == TALKTYPE_PRIVATE_PN or TALKTYPE_SAY) or not self:isFocused(cid) then

and it worked fine!
 
Back
Top