• 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 mixing the msgcontains!

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,780
Solutions
31
Reaction score
2,300
Location
Sweden?
As the title says. When i say msgcontain(msg,"cyko sucks"), it goes back to msgcontain(msg,"cyko")!

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}

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 greetCallback(cid)
	Topic[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then 
                return false 
        end
  
  	if msgcontains(msg, 'cyko') then   
  	if getPlayerStorageValue(cid, storage) == -1 and getPlayerStorageValue(cid,90000) == 2 then
		npcHandler:say("I remeber that kid, he couldn't even fix a npc.",cid)
		Topic[cid] = 1
	end
	elseif Topic[cid] == 1 then
	if (msgcontains(msg, 'cyko sucks')) then
		npcHandler:say("Im pretty sure that i know he sucks.", cid)
	end   
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
 
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 greetCallback(cid)
	Topic[cid] = 0
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then 
        return false 
    end
 
    if Topic[cid] == 1 then
        if (msgcontains(msg, 'cyko sucks')) then
            npcHandler:say("Im pretty sure that i know his sucks.", cid)
        end   
  	elseif msgcontains(msg, 'cyko') then   
        if getPlayerStorageValue(cid, storage) == -1 and getPlayerStorageValue(cid,90000) == 2 then
            npcHandler:say("I remeber that kid, he couldn't even fix a npc.",cid)
            Topic[cid] = 1
        end
	end
	return TRUE
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

It does not go back to "cyko" it starts at the top of the code and goes to the bottom. So the first if statement that fits is used.
 
Ok thanks Summ, but why does it not read the whole word? Its just snapping cyko and jump to that only :S
 
If you want the exact message you can use:
if msg:lower() == "cyko sucks" then

However everything should be possible with msgcontains and I never had problems with it.
 
If you want the exact message you can use:
if msg:lower() == "cyko sucks" then

However everything should be possible with msgcontains and I never had problems with it.

msg:lower didnt work, still going to cyko
 
The order of the statements is the important thing nothing else.
You can check:
if msgcontains(msg, "cyko") then
...
elseif msg:lower() == "cyko sucks" then


and it will go to the first.

However you can exclude the second one in the first:
if msgcontains(msg, "cyko") and not msgcontains(msg, "cyko sucks") then
...
elseif msgcontains(msg, "cyko sucks") then


=> or just use a better order of your statements.
 
The order of the statements is the important thing nothing else.
You can check:
if msgcontains(msg, "cyko") then
...
elseif msg:lower() == "cyko sucks" then


and it will go to the first.

However you can exclude the second one in the first:
if msgcontains(msg, "cyko") and not msgcontains(msg, "cyko sucks") then
...
elseif msgcontains(msg, "cyko sucks") then


=> or just use a better order of your statements.

Thanks :)
 
use and?
if msgcontains(msg, "cyko") and msgcontains(msg, "sucks") then

like
LUA:
  	if msgcontains(msg, 'cyko') then   
		if getPlayerStorageValue(cid, storage) == -1 and getPlayerStorageValue(cid, 90000) == 2 then
			npcHandler:say("I remeber that kid, he couldn't even fix a npc.",cid)
			Topic[cid] = 1
		end
		if (msgcontains(msg, 'cyko') and msgcontains(msg, 'sucks')) and Topic[cid] == 1 then
			npcHandler:say("Im pretty sure that i know he sucks.", cid)
		end   
	end

or separed by topics or another value
 
Last edited:
Back
Top