Mirage Source
Client Swear Filter With Replaces - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13)
+------ Thread: Client Swear Filter With Replaces (/showthread.php?tid=2173)



Client Swear Filter With Replaces - JokeofWeek - 23-09-2008

This is based on William's tutorial. I found it a little unoptimized. So I did a little modification to it, and I also added in a replacing system. . First, in mod Globals, go add the following :

Code:
Public SwearArray() as string
Public ReplaceSwearArray() as string
.

Now, go to sub Main. At the top, declare the following variable :

Code:
Public SwearString as string

In the same sub, right after :

Code:
Call CheckTiles

add :

Code:
' Use the swear string to store the original swear words
SwearString = "ass,fuck,shit,bitch,damn,cunt,whore,piss"
SwearArray = Split(SwearString, ",")

' Use the swear string to store the replace swear words
SwearString = "donkey,luck,matress,lucky charms,cow,moo,jokeofweek,yellow"
ReplaceSwearArray = Split(SwearString, ",")

Now, to add in your own words, just add the swear word to the first string, and then add the replacement to the second string Smile

Now, just add this function (a modified version of CheckMessage) :

Code:
Public Function CheckMessage(byval Msg As String) As String
Dim i As Long

    CheckMessage = Msg

    For i = 0 To UBound(SwearArray)
           CheckMessage = Replace$(CheckMessage , SwearArray(i), ReplaceSwearArray(i), , , vbTextCompare)
    Next i
    
End Function

And there you go, you now have an optimized chat filter system which replaces swears with what you want them to. And, to quote william,:

Quote:Now search for all the different messages: adminmsg, saymsg, broadcastmsg, globalmsg, playermsg, mapmsg.

And do this on all of them:
Code:
Call GlobalMsg(ChatText)
Replace it with:
Code:
Call GlobalMsg(CheckMessage(ChatText))
And of course you shouldn't replace the saymsg call with a globalmsg call...

Good Luck And have Fun



Re: Client Swear Filter With Replaces - GIAKEN - 23-09-2008

Unfortunately, it won't work...it will only replace the last swear word in the string. Like this:

Msg = "shit whore fuck bitch" for example...

CheckMessage = "**** whore fuck bitch" but Msg is still the same so it will look for the second swear...so then

CheckMessage = "shit ***** fuck bitch" and then Msg will still equal the same thing...so you do:

Code:
Public Function CheckMessage(byval Msg As String) As String
Dim i As Long
  
    For i = 0 To UBound(SwearArray)
        CheckMessage = Replace$(Msg, SwearArray(i), ReplaceSwearArray(i), , , vbTextCompare)
        If CheckMessage  Msg Then Msg = CheckMessage
    Next i
  
End Function

Also changed i to a Long because it's the fastest type to use for loops.


Re: Client Swear Filter With Replaces - JokeofWeek - 23-09-2008

GIAKEN Wrote:Unfortunately, it won't work...it will only replace the last swear word in the string. Like this:

Msg = "shit whore fuck bitch" for example...

CheckMessage = "**** whore fuck bitch" but Msg is still the same so it will look for the second swear...so then

CheckMessage = "shit ***** fuck bitch" and then Msg will still equal the same thing...so you do:

Code:
Public Function CheckMessage(byval Msg As String) As String
Dim i As Long
  
    For i = 0 To UBound(SwearArray)
        CheckMessage = Replace$(Msg, SwearArray(i), ReplaceSwearArray(i), , , vbTextCompare)
        If CheckMessage  Msg Then Msg = CheckMessage
    Next i
  
End Function

Also changed i to a Long because it's the fastest type to use for loops.

Ah true, thanks for that first fix, hadn't thought of that. And yeah, I thought of using I as a long for the loop, I'll probably do that Smile. Thanks for that mate Smile