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
[url]http://gmodwiki.net/Lua/Hooks/Base/PlayerSay[/url]
Adjust it to your needs I guess.
[CODE]
function handlePlayerSay(player, message)
if(string.find(message, "Word") ~= 0) then
-- play sound
return "";
end
return message;
end
hook.Add("PlayerSay", "sethhack", handlePlayerSay);
[/CODE]
this is what i ended up with, if anyone is interested
[CODE]
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)[/CODE]
[QUOTE=rejax;40709506]this is what i ended up with, if anyone is interested
[CODE]
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)[/CODE][/QUOTE]
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.
Sorry, you need to Log In to post a reply to this thread.