General > Developers Corner

Admin sounds, tools and other code chat.

<< < (11/31) > >>

Chironex:
I can't test this and i'm too lazy to start scripting now (02:30) but:

Let's say text is: Hello i'm a noob mingebag

--- Code: -----a table of bad words that will be replaced
bad_words_table = { "noob", "mingebag" }

--split the text into words:
typed_words_table = text.Explode(" ")

--search for bad words in what the player typed:
for _, v in pairs ( typed_words_table ) do
    -- if the current word is a bad word,
    if bad_words_table[v:lower()] then
        -- replace the bad word with stars:
        text:Replace( v, string.rep( "*", v:len() ) )
    end
end

--- End code ---
text should now be: Hello i'm a **** ********


Edit:
Or maybe simply something like this? :

--- Code: -----a table of bad words that will be replaced
bad_words_table = { "noob", "mingebag" }

for _, v in pairs ( bad_words_table ) do
    text:Replace( v, string.rep( "*", v:len() ) )
end

--- End code ---

Despite the fact that this code is smaller than the first, it's probably less efficient if you have a big table for bad words (you will most likely have a big one to cover all possibles bad words!), as it search every bad words in the text, while the first code compare every words of the text with bad words (less iterations). So yes, probably less efficient but more powerful because it will replace even "nooby" by "****y" while the first code won't detect "nooby" as the bad word "noob".

jay209015:
This is what I got from what you were saying.


--- Code: ---function WFilter( ply, text, toall )
TextD = { "word1", "word2" }
TextC = text.Explode(" ")
for _, v in pairs ( TextC )
    if WordD[v:lower()] then
        text:Replace( v, string.rep( "*", v:len() ) )
    end
end
return text
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---

Didn't work, but could just be something I did.

Chironex:
Yes, you use WordD inside the loop but TextD ouside...also don't return anything

jay209015:
Nice catch there, thank you.

==EDIT==

Code with the change, but still doesn't work.


--- Code: ---function WFilter( ply, text, toall )
TextD = { "word1", "word2" }
TextC = text.Explode(" ")
for _, v in pairs ( TextC )
    if TextD[v:lower()] then
        text:Replace( v, string.rep( "*", v:len() ) )
    end
end
return text
hook.Add( "PlayerSay", "WFilter", WFilter )
--- End code ---

JamminR:
Let's keep it simple for now guys.
Kyzer, he's not that experienced yet.


--- Code: ---WordD = { "word1" , "word2" }
function WFilter( ply, text, toall )
local WordC = nil
         for _, v in ipairs( WordD ) do
             if string.find( text, v, 1, true) then --#1 <-- See text?
                text = string.Replace(text, v, "****") --#2 text will be changed, and text in line above (#1) will be changed to include (drum roll) the **** of word1
                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 ---

Also, though I appreciate you wanting to share your release, could you not use it as a signature? Thanks.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version