Author Topic: Admin sounds, tools and other code chat.  (Read 56125 times)

0 Members and 3 Guests are viewing this topic.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #45 on: April 13, 2008, 04:02:06 PM »
Upon closer look, I see why, but can you?
I feel as though I've moved away from teaching and been doing your work for you.
Hint: "text" never changes. "WordC" does. Therefore WordC censor text is always the last word in the table to get edited.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #46 on: April 13, 2008, 04:08:28 PM »
I see what you're talking about, but I don't see a way of fixing it. Unless this will work.

Code: [Select]
WordD = { "word1" , "word2" }
function WFilter( ply, text, toall )
local WordC = text
         for _, v in ipairs( WordD ) do
             if string.find( text, v, 1, true) then
                WordC = string.Replace(text,v,"****")
             else
                WordC = nil
             end
         end
if WordC then return WordC else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )

==EDIT==
Nope this one works even less. It only filters out word2 in all cases.
« Last Edit: April 13, 2008, 04:11:15 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #47 on: April 13, 2008, 04:14:39 PM »
Closer.
But, WordC will get replaced with nil on words that aren't in the table.
Making it start all over again, ending up with the same results, last word of table censored.

I recommend actually modifying 'text' each loop.
Setting WordC to "found" or "true" if anything is found.
Returning "text" instead of "WordC" in the final if WordC check.
"if WordC then return text else return end"
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #48 on: April 13, 2008, 04:19:01 PM »
Like this?


Code: [Select]
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
                WordC = found
             end
         end
         if WordC == found then
            text = string.Replace(text, v, "****")
         end
if WordC == found then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )

==EDIT==
Tested and Failed :'(
« Last Edit: April 13, 2008, 04:20:37 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #49 on: April 13, 2008, 04:29:39 PM »
Ok I changed it a little bit, but not tested yet.

Code: [Select]
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
                WordC = found
             end
             if WordC == found then
                text = string.Replace(text, v, "****")
             end
         end
if WordC then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )

==EDIT==
Tested, Failed

also tried
Code: [Select]
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
                WordC = found
                if WordC == found then
                   text = string.Replace(text, v, "****")
                end
             end
         end
if WordC then return text else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )

Same result.
« Last Edit: April 13, 2008, 05:14:24 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Admin sounds, tools and other code chat.
« Reply #50 on: April 13, 2008, 05:41:51 PM »
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: [Select]
--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
text should now be: Hello i'm a **** ********


Edit:
Or maybe simply something like this? :
Code: [Select]
--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

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".
« Last Edit: April 13, 2008, 06:08:32 PM by Kyzer »

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #51 on: April 13, 2008, 06:00:58 PM »
This is what I got from what you were saying.

Code: [Select]
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 )

Didn't work, but could just be something I did.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Admin sounds, tools and other code chat.
« Reply #52 on: April 13, 2008, 06:10:19 PM »
Yes, you use WordD inside the loop but TextD ouside...also don't return anything

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #53 on: April 13, 2008, 06:14:02 PM »
Nice catch there, thank you.

==EDIT==

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

Code: [Select]
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 )
« Last Edit: April 13, 2008, 06:16:42 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #54 on: April 13, 2008, 07:46:44 PM »
Let's keep it simple for now guys.
Kyzer, he's not that experienced yet.

Code: [Select]
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 )

Also, though I appreciate you wanting to share your release, could you not use it as a signature? Thanks.
« Last Edit: April 13, 2008, 07:50:59 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #55 on: April 13, 2008, 08:07:01 PM »
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
« Last Edit: April 13, 2008, 08:12:12 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #56 on: April 13, 2008, 08:45:27 PM »
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: [Select]
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 )
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #57 on: April 13, 2008, 08:47:58 PM »
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.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #58 on: April 13, 2008, 08:50:00 PM »
Quote
Just make sure to use the same in your Replace function too (Replace(<this_text_would_need_to_be_lower_too)

that's the part I messed up on, ty. I think I posted while you were typing this :D.

Final code :D

Code: [Select]
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 )
« Last Edit: April 13, 2008, 08:52:17 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #59 on: April 14, 2008, 08:08:28 PM »
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: [Select]
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 )

This one has me stumped.  ???

An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly