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

NPC responding to default messages

Grehy

Killroy
Joined
Nov 21, 2008
Messages
2,631
Reaction score
33
Location
United States
This is the script;

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = 9391
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Did you bring me what I requested?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("You have already brought me what I asked for.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveItem(cid, 9971, 1) == TRUE) then
			npcHandler:say("Thank you very much. Here is your reward.", cid)
			doPlayerAddItem(cid, 2522, 1)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("That is not the item I requested from you.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Ok.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

If I say mission in default chat without saying hi, it will start the dialog. How can I fix this so it only responds to NPC channel messages besides hi?
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = 9391
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Did you bring me what I requested?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("You have already brought me what I asked for.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveItem(cid, 9971, 1) == TRUE) then
			npcHandler:say("Thank you very much. Here is your reward.", cid)
			doPlayerAddItem(cid, 2522, 1)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("That is not the item I requested from you.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Ok.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Should be good now:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
        --[[
        REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
        ]]--
        local storage = 9391
   if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'yo') then
      npcHandler:say('Hello, to take your quest say {quest}', cid)
        if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
                if(getPlayerStorageValue(cid, storage) < 1) then
                        npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
                        setPlayerStorageValue(cid, storage, 1)
                elseif(getPlayerStorageValue(cid, storage) == 1) then
                        npcHandler:say("Did you bring me what I requested?", cid)
                        talkState[talkUser] = 1
                elseif(getPlayerStorageValue(cid, storage) == 2) then
                        npcHandler:say("You have already brought me what I asked for.", cid)
                end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
                if(doPlayerRemoveItem(cid, 9971, 1) == TRUE) then
                        npcHandler:say("Thank you very much. Here is your reward.", cid)
                        doPlayerAddItem(cid, 2522, 1)
                        setPlayerStorageValue(cid, storage, 2)
                        talkState[talkUser] = 0
                else
                        npcHandler:say("That is not the item I requested from you.", cid)
                        talkState[talkUser] = 0
                end
        elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
                npcHandler:say("Ok.", cid)
                talkState[talkUser] = 0
        end
   end
        return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Btw you should edit your xml file for the 'hi' shittttz
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local storage = 9391

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
	elseif msgcontains(msg, 'quest') or msgcontains(msg, 'mission') then
		local v = getPlayerStorageValue(cid, storage)
		if v < 1 then
			npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif v == 1 then
			npcHandler:say("Did you bring me what I requested?", cid)
		elseif v == 2 then
			npcHandler:say("You have already brought me what I asked for.", cid)
		end
		Topic[cid] = v == 1 and 1 or 0
	elseif Topic[cid] == 1 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 9971, 1) then
				npcHandler:say("Thank you very much. Here is your reward.", cid)
				doPlayerAddItem(cid, 2522, 1)
				setPlayerStorageValue(cid, storage, 2)
			else
				npcHandler:say("That is not the item I requested from you.", cid)
			end
		else
			npcHandler:say("Ok.", cid)
		end
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Should be good now:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
        --[[
        REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
        ]]--
        local storage = 9391
   if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'yo') then
      npcHandler:say('Hello, to take your quest say {quest}', cid)
        if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
                if(getPlayerStorageValue(cid, storage) < 1) then
                        npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
                        setPlayerStorageValue(cid, storage, 1)
                elseif(getPlayerStorageValue(cid, storage) == 1) then
                        npcHandler:say("Did you bring me what I requested?", cid)
                        talkState[talkUser] = 1
                elseif(getPlayerStorageValue(cid, storage) == 2) then
                        npcHandler:say("You have already brought me what I asked for.", cid)
                end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
                if(doPlayerRemoveItem(cid, 9971, 1) == TRUE) then
                        npcHandler:say("Thank you very much. Here is your reward.", cid)
                        doPlayerAddItem(cid, 2522, 1)
                        setPlayerStorageValue(cid, storage, 2)
                        talkState[talkUser] = 0
                else
                        npcHandler:say("That is not the item I requested from you.", cid)
                        talkState[talkUser] = 0
                end
        elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
                npcHandler:say("Ok.", cid)
                talkState[talkUser] = 0
        end
   end
        return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Btw you should edit your xml file for the 'hi' shittttz

He doesn't reply to mission at all now

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

local Topic = {}
local storage = 9391

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
	elseif msgcontains(msg, 'quest') or msgcontains(msg, 'mission') then
		local v = getPlayerStorageValue(cid, storage)
		if v < 1 then
			npcHandler:say("Greetings. I need you to bring me a very old artifact. I'm sure Killroy will give you one.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif v == 1 then
			npcHandler:say("Did you bring me what I requested?", cid)
		elseif v == 2 then
			npcHandler:say("You have already brought me what I asked for.", cid)
		end
		Topic[cid] = v == 1 and 1 or 0
	elseif Topic[cid] == 1 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 9971, 1) then
				npcHandler:say("Thank you very much. Here is your reward.", cid)
				doPlayerAddItem(cid, 2522, 1)
				setPlayerStorageValue(cid, storage, 2)
			else
				npcHandler:say("That is not the item I requested from you.", cid)
			end
		else
			npcHandler:say("Ok.", cid)
		end
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Works, could you explain what was wrong with mine and what you changed to fix it?
 
Code:
	if [B][COLOR="Red"]not[/COLOR][/B] npcHandler:[B][COLOR="Red"]isFocused[/COLOR][/B](cid) then
		return false
	.. the rest of code
also, learn to diff
 
Back
Top