• Chat Filter Sound Help
    13 replies, posted
Hey guys, I made a small chatfilter.. Heres my code. [lua] function Fuck(ply, say, teamsay) if string.find(say, "fuck") == 1 then ply:EmitSound(Sound("/content/Sound/Beep.wav"),500) end end [/lua] And, if I say fuck in chat, there wont sound a beep, whats wrong with it?
You haven't hooked that function to any event, so it is never called. [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSay]Gamemode.PlayerSay [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=MakeR;21265521]You haven't hooked that function to any event, so it is never called. [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSay]Gamemode.PlayerSay [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE] I hooked it and such, but it doesnt seem to work after all, this is what I got by now: [lua] function Fuck(ply, say, teamsay) if string.find(say, "fuck") == 1 then ply:EmitSound(Sound("GmodHotel/content/Sound/Beep.wav"),500) end end hook.Add("PlayerSay","Fuck_ChatHook",Fuck) [/lua] Whats wrong?
Are you sure that the sound exists? And that hook would ONLY trigger if you said fuck as the first thing in the sentence, you don't have to use the ==, then it would trigger in all cases someone says fuck somewhere in their sentence. Jamie is right, and I don't think you even need the Sound() around it, wiki explains alot of it > [b][url=http://wiki.garrysmod.com/?title=Entity.EmitSound]Entity.EmitSound [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Isn't sound relative to the sound directory? Try [lua]ply:EmitSound(Sound("Beep.wav"),500) [/lua]
[QUOTE=Jamie932;21268166]Isn't sound relative to the sound directory? Try [lua]ply:EmitSound(Sound("Beep.wav"),500) [/lua][/QUOTE] Yes! It works, but, is there any way to NOT show the "fuck" letters, and just only play the sound?
I think, but am not sure, you just return true on PlayerSay.. or maybe it's return false. Could also be another hook I'm thinking of.
Return an empty string to prevent the text from showing in the chat.
Incase you do not understand what MakeR is saying, it's just this. [lua] function Fuck(ply, say, teamsay) if string.find(say, "fuck") == 1 then ply:EmitSound(Sound("Beep.wav"),500) end return "" end hook.Add("PlayerSay","Fuck_ChatHook",Fuck) [/lua] But do you not think that this would be a bit inefficient? I mean, if they say a paragraph containing the word fuck, then their whole paragraph will cease to exist.
Then use string.gsub to take out all of the fucks, then return that new string.
Just noticed you can just remove the == 1 part on the if statement.
This should be what you want. [code] function Fuck(ply, say, teamsay) if string.find(say, "fuck") then ply:EmitSound(Sound("Beep.wav"),500) local blockedfuck = string.gsub(say, "fuck", "****") end return blockedfuck end hook.Add("PlayerSay","Fuck_ChatHook",Fuck) [/code]
[QUOTE=Wintergrove;21282296]This should be what you want. [code] function Fuck(ply, say, teamsay) if string.find(say, "fuck") then ply:EmitSound(Sound("Beep.wav"),500) local blockedfuck = string.gsub(say, "fuck", "****") end return blockedfuck end hook.Add("PlayerSay","Fuck_ChatHook",Fuck) [/code][/QUOTE] It's returning blockedfuck even when it hasn't found a 'fuck' in the chat. You also don't need the Sound() around the sound string, that will pre-cache the sound every time someone says fuck. [lua]hook.Add("PlayerSay", "BockFuck", function(ply, say, teamsay) if string.find(say, "fuck") then ply:EmitSound("Beep.wav", 500) return say:gsub("fuck", "****") end end)[/lua]
[QUOTE=MakeR;21282358]It's returning blockedfuck even when it hasn't found a 'fuck' in the chat. You also don't need the Sound() around the sound string, that will pre-cache the sound every time someone says fuck. [lua]hook.Add("PlayerSay", "BockFuck", function(ply, say, teamsay) if string.find(say, "fuck") then ply:EmitSound("Beep.wav", 500) return say:gsub("fuck", "****") end end)[/lua][/QUOTE] Wow, ty. works good!
Sorry, you need to Log In to post a reply to this thread.