Making certain phrases exempt from chat.

So I wrote a script that essentially just plays a /vo/ file when a certain phrase is said. What I’m having trouble with is making it so that the phrases aren’t shown in chat.
For example, you type “oh dear” and it plays someone from half life saying saying oh dear, but it doesn’t appear in chat.

Any guidance would be appreciated, I’m new to lua and I couldn’t really use the wiki for this purpose.

Thanks.

After the hook is triggered and you’ve ran your code return “”

so something like

if args = cake the
do all the play sound crap
return “”
end

http://gmodwiki.net/Lua/Hooks/Base/PlayerSay

Adjust it to your needs I guess.



function handlePlayerSay(player, message)
     if(string.find(message, "Word") ~= 0) then
          -- play sound
          return "";
     end

     return message;
end

hook.Add("PlayerSay", "sethhack", handlePlayerSay);


A more elaborate way:

[lua]
local emotes = {}
emotes[“hi”] = {“vo/npc/female01/hi01.wav”, “vo/npc/female01/hi02.wav”, “vo/npc/male01/hi01.wav”, “vo/npc/male01/hi02.wav”}
emotes[“hello”] = “vo/coast/odessa/nlo_cub_hello.wav”
emotes[“gtfo”] = {“vo/npc/female01/gethellout.wav”, “vo/npc/male01/gethellout.wav”}

– Precache the sound files.
for _, snds in pairs (emotes) do
if (type(snds) == “table”) then
for __, snd in pairs (snds) do
util.PrecacheSound(snd)
end
else
util.PrecacheSound(snds)
end
end

hook.Add(“PlayerSay”, “Emotes”, function(ply, say, team)
if (emotes[say]) then
local snds = emotes[say]
if (type(snds) == “table”) then
ply:EmitSound(table.Random(snds), 100, 100)
else
ply:EmitSound(snds, 100, 100)
end

	return ""
end

end)
[/lua]

This way you can create emotes with multiple sound files.

this is what i ended up with, if anyone is interested



USay = {} 

USay.WordList = {
["hes here"] = "vo/streetwar/nexus/male01/c17_10_heshere.wav";
["Let us out"] = "vo/streetwar/nexus/male01/c17_10_letusout.wav";
--etc
}

function USay.ChatFunction( ply, text )
   if ply:IsValid() then
      for k,v in pairs(USay.WordList) do
         if string.find( text, k ) then
			ply:EmitSound(USay.WordList[k])
            return ""
         end
      end
   end
end
hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction)

string.find Does not return 1/true if it succeeds, it returns the position of the found text.
If not, it returns 0.

It returns nil, not 0. His code is fine, because if integer returns true.