I need a code that triggers when a player says 2 certain words anywhere in a chat sentence.

I need a code that triggers when a player says “Joshua Graham” anywhere in a chat sentence. I want to enforce the rule that nobody is allowed to mention Joshua Graham to ANYONE.

Thank you.

From the questionbot script on my server. Edit it to your needs. (All you’ll probably want to change is the prefixes [Q/A Bot]. Credits to Overv for server side chat.AddText().

Call this whatever.lua in lua/autorun, and remember to edit the first line to whatever you called it.
[lua]
if SERVER then AddCSLuaFile(“questionbot.lua”) end
local keywords = {
{ “joshua”, “graham” },
}

local answers = {
“Do not mention Joshua Graham to ANYONE!”,
}
if SERVER then
chat = { }
function chat.AddText( … )
if ( type( arg[1] ) == “Player” ) then ply = arg[1] end
umsg.Start( “AddText”, ply )
umsg.Short( #arg )
for _, v in pairs( arg ) do
if ( type( v ) == “string” ) then
umsg.String( v )
elseif ( type ( v ) == “table” ) then
umsg.Short( v.r )
umsg.Short( v.g )
umsg.Short( v.b )
umsg.Short( v.a )
end
end
umsg.End( )
end

if #keywords != #answers then
	ServerLog( "[Q/A] Bot: Terminating. #keywords != #answers" )
	return
end
function QABot( ply, strText, team )
	 --if ( string.sub(strText, 1, 4) == "/ask" or string.sub(strText, 1, 4) == "!ask" ) then
		--local plytext = string.Explode("/ask ", strText) or {"n/a", "n/a"}
		for k, v in pairs(keywords) do
			local x = 0
			for k1, v1 in pairs(keywords[k]) do
				if ( string.find( string.lower(strText), string.lower(v1) ) ) then 
					x = x + 1 
				end
			end				
			if ( x == #keywords[k] ) then
				chat.AddText( ply, Color(255,100,100), "[Q/A Bot]: ", Color(240,240,240), answers[k] )
				--ServerLog("[Q/A Bot]: Question: " .. ply:Name() .. " asked	" .. plytext[2])					
				--ServerLog("[Q/A Bot]: Answer: " .. answers[k])	
				return ""
			end	
		end
		--questiony = tostring(plytext[2]) or "n/a"
		--chat.AddText( ply, Color(255,100,100), "[Q/A Bot]: ", Color(240,240,240), "No question matched." )
		--ServerLog( "[Q/A Bot]: Question: " .. ply:Name() .. " tried to ask: " .. questiony )	
		--return ""
	  end
--end
hook.Add( "PlayerSay", "QABot", QABot )

else
usermessage.Hook( “AddText”, function( um )
local argc = um:ReadShort( )
local args = { }
for i = 1, argc / 2, 1 do
table.insert( args, Color( um:ReadShort( ), um:ReadShort( ), um:ReadShort( ), um:ReadShort( ) ) )
table.insert( args, um:ReadString( ) )
end

    chat.AddText( unpack( args ) )
end )

end
[/lua](Commented out stuff like the chat prefix, and server logging)

Thanks. I wish I could give you a friendly rating and a winner rating at the same time.

No problem. Check my post edit where I commented out the /ask prefix and such. :slight_smile:

Uh, I got a problem.
It seems to disable chat. Which function in the script disables chat?

Try the version in my post now. :slight_smile:

Someone sounds butthurt.