General > Developers Corner
Admin sounds, tools and other code chat.
JamminR:
--- Quote from: jay209015 on April 12, 2008, 06:28:36 PM ---Tested, but still this code only censors word2. Any idea as to why?
--- Code: ---WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
for _, v in ipairs( WordD ) do
if string.find( text, v, 1, true) then
WordC = string.Replace(text,v,"****")
else
WordC = (text)
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
--- End quote ---
I really hate lightbulb moments that show my stupidity.
I have a very good idea why.
This is 100% sillyness on my part (and maybe even others who attempted to help), nothing on you, as it is a mistake that a new coder (of _any_ language) could make.
WordC gets replaced with non-replaced "text" every single time it comes across a non-tabled word.
--- Code: ---WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
WordC = text
for _, v in ipairs( WordD ) do
if string.find( WordC, v, 1, true) then
WordC = string.Replace(WordC, v,"****")
end
end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
--- End code ---
That should work. Hope you understand the difference. Your loop was setting WordC back to straight text on words not in the table.
jay209015:
Again, same thing. Only censors word2 and breaks the ulx chat commands. Console doesn't return any errors, and I've ran lua_run PrintTable(WordD) and it shows everything as it should be. When we get this finished though I would like to see it released as a module with ulx because offensive language can get to be intolerable at times.
JamminR:
--- Quote from: jay209015 on April 13, 2008, 08:39:36 AM ---Again, same thing. Only censors word2 and breaks the ulx chat commands. Console doesn't return any errors, and I've ran lua_run PrintTable(WordD) and it shows everything as it should be. When we get this finished though I would like to see it released as a module with ulx because offensive language can get to be intolerable at times.
--- End quote ---
I tried it in singleplayer. The last code I gave you works fine, except yes, it breaks ULX chat commands.
I don't think it should break ALL chat hooks, but apparently not returning nil does.
I do not know why your examples aren't working.
Where are you testing this? What are you modifying? If testing on a dedicated server, are you restarting the server (not just the map) each change you make so that lua cache can be rebuilt?
I first said "This is a test of word1 word2"
It returned JamminR: this is a test of **** ****
I then said " This is a test of word1 and word2"
It returned JamminR: This is a test of **** and ****
Though you are more than welcome to make a release on your own, we will not add a word filter to ULX.
We've considered this a few times in the past and realized that it would be an effort in futility. As soon as you censor one word on a server, what I call the Gmod immature level increases 10 fold, and many on a server would start trying to find ways around the censor instead of building. I've seen it before with IRC chat bots back in the early 90s. People would get kicked from an IRC channel if they said a bad word, so instead, they'd rejoin and the only chat they'd do for 10 minutes or more (until a real admin banned them) would be to start replacing letters with numbers/symbols to represent another letter. It wouldn't surprise me one bit if 'leet speech' was invented by people doing such work arounds. Though you could increase the word table, that would start slowing down the script.
jay209015:
Ok, thank you very much. I didn't restart the server, I just did the map. Also do you know of a way I can keep it from breaking the ulx chat commands, and how do I make it an addon?
JamminR:
I do not know how to prevent it from breaking other chat commands. You may wish to look into ULX to see how we do it, as I don't remember off the top of my head.
Addons are like virtual gmod folders.
Your folder would be something like the following
<addon_name>
in <addon_name> is required an info.txt. Look up one of your other addons for how that file is formatted.
Then, in <addon_name> folder, you place what folders/files that would be added to the Gmod folder if we were manually adding them.
In this case, you would need
<addon_name>/lua
<addon_name>/lua/autorun
<addon_name>/lua/autorun/filename.lua
There are other ways for larger lua files, where you just make the autorun link to those files but your script probably doesn't require a separate load.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version