General > Developers Corner
Admin sounds, tools and other code chat.
jay209015:
K, understood about the sig. Now I see the problem with my version of the script. Thanks for everything JamminR. I liked Kyzers because it would work even if the player used uppercase letters. Also it used a * for each character. I will try to work on adding that to the script later though. Thanks again.
==EDIT==
Tested works great, now to fix it being case sensitive. I'll work on that tomorrow. So no more question from me untill I try to work it out for myself. :D
jay209015:
Ok, maybe I lied. I got bored/curious and started working on the script tonight. I got everything working but the case sensitive part. word1 = ***** , but Word1 = Word1.
I edited the comments so you could see what I thought was supposed to be happening.
--- Code: ---WordD = { "word1" , "word2" } --This is your word list
function WFilter( ply, text, toall )
local WordC = nil
for _, v in ipairs( WordD ) do
if string.find( (string.lower(text)), v, 1, true) then --#1 <-- lowers the text's case and test to see if it equals any word in the table
text = string.Replace(text, v, (string.rep( "*",string.len(v)))) --#2 text will be changed, and text in line above (#1) will be changed to include a * for each character for v
WordC = true --#3 set true...something was found.
end
end
if WordC then return text else return end --#4 If something found, return censored text.. If not, just return to let other scripts look at the text.
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
JamminR:
Since you're editing the text anyway, you could always convert it to all lower case very easily.
Might look funny punctuation wise, but hey...I don't think people swearing would care anyway.
Make your table lowercase, so as to not make the script do it.
Then, when searching in your find, use string.lower(text).
Or a another way to do it, which can sometimes look complicated is text:lower()
Just make sure to use the same in your Replace function too (Replace(<this_text_would_need_to_be_lower_too)
No worries for the help. I've learned much from others here along the way.
You're questions have also helped distract me from a frustrating issue I was having with Umotd.
I figured out how to fix a problem I was having as I went to bed last night, so it's all good now.
jay209015:
--- Quote ---Just make sure to use the same in your Replace function too (Replace(<this_text_would_need_to_be_lower_too)
--- End quote ---
that's the part I messed up on, ty. I think I posted while you were typing this :D.
Final code :D
--- Code: ---WordD = { "word1" , "word2" } --This is your word list
function WFilter( ply, text, toall )
local WordC = nil
for _, v in ipairs( WordD ) do
if string.find( string.lower(text), v, 1, true) then --#1 <-- lowers the text's case and test to see if it equals any word in the table
text = string.Replace( string.lower(text), v, (string.rep( "*",string.len(v)))) --#2 text will be changed, and text in line above (#1) will be changed to include a * for each character for v
WordC = true --#3 set true...something was found.
end
end
if WordC then return text else return end --#4 If something found, return censored text.. If not, just return to let other scripts look at the text.
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
jay209015:
Well, came up with a new problem. If it finds a word that in the list, it sets text:lower and removes all spaces.
I said:
It printed:
word1 TEST word1
*****test*****
WORD1 T e S T W o R d 1
*****test*****
hope that's clear. Here's the code.
--- Code: ---WordD = { "word1" , "word2" } -- This is your word list. These are not case sensitive, and periods are removed by script and are not necessary in wordlist.
function WFilter( ply, text, toall )
local WordC = nil
if string.find( text, ".", 1, true) then
text = string.Replace( text, ".", "") -- removes all periods
end
for _, v in ipairs( WordD ) do
if string.find( string.Replace(text:lower(), " ",""), v, 1, true) then --#1 <-- lowers the text's case and test to see if it equals any word in the table
text = (string.Replace( string.Replace(text:lower(), " ",""), v, (string.rep( "*",string.len(v))))) --#2 text will be changed, and text in line above (#1) will be changed to include a * for each character for v
WordC = true --#3 set true...something was found.
end
end
if WordC then return text else return end --#4 If something found, return censored text.. If not, just return to let other scripts look at the text.
end
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---
This one has me stumped. ???
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version