ID:264240
 
Problem description:
Whenever I say that "farget" word, it says it added 745 to my SwearCount and booted me from the game. Why?! It's only supposed to add 25! >.<

Code:
mob
tmp/SpamNumber = 0
tmp/SpamMax = 4
tmp/SpamTime = 30
tmp/SwearCount = 0


proc/SwearFilter(msg)
var/list/BannedWords = list("ace"=90)
var/list/VulgarSwears = list("farget"=25)
var/Count = 0
var/Index
var/Swear
for(Swear in VulgarSwears)
Index = findtext(msg,Swear)
while(Index)
Count += VulgarSwears[Swear]
Index = findtext(msg,Swear,Index+length(Swear))
for(Swear in BannedWords)
Index = findtext(msg,BannedWords)
while(Index)
Count += BannedWords[Swear]
Index = findtext(msg,Swear,Index+length(Swear))
return Count


mob/verb
World\-Chat(msg as text)
set hidden = 1
set src = usr
if(usr.Muted)
alert("You are muted! Shut up!")
return
if(!msg) return
if(length(msg) > 150)
alert("Your messege is too long. Please shorten it!")
return
if(!usr.Staff)
if((++usr.SpamNumber) >= SpamMax)
world<<"<center>[usr] has been kicked from the game for either spamming messages or talking too fast!"
del(usr)
return
spawn(SpamTime) --usr.SpamNumber
var/SwearScore = SwearFilter(msg)
if(SwearScore > 0)
usr.SwearCount += SwearScore
usr<<"<font size=+1><font color=red>Your warning level has gone up [SwearScore]!"
if(usr.SwearCount >= 100)
world<<"<center>[usr] has been kick from the game for either excessive swearing or using out of date insults!"
del(usr)
return
else usr.SwearCount-=10
msg = copytext(msg,1,findtext(msg,"\n"))
world<<"<b>[usr.GuildTag ? "<b>\[[usr.GuildTag]\]</b>" : ""] [usr]:</b> [html_encode(msg)]"
</<b>
Is anyone going to help me? :( I know it seems like a lot of coding, but I really do need someone to look over it for me.
In response to Mizukouken Ketsu
Hmm.. I dont see why this is happening, ill try it 1 sec

Edit: when i do this, I get 115 (which is 25,fargen + 90,ace)
        while(Index)
Count += VulgarSwears[Swear]
Index = findtext(msg,Swear,Index+length(Swear))

Because you're adding to the count in each iteration of your while loop.

Try
        Count += VulgarSwears[Swear]
while(Index)
Index = findtext(msg,Swear,Index+length(Swear))
In response to Nickr5
I did that and it said it went up 1,690 and booted me. I don't know about you, but that's worse than 745 >_>
In response to Nickr5
Nickr5 wrote:
>         while(Index)
> Count += VulgarSwears[Swear]
> Index = findtext(msg,Swear,Index+length(Swear))
>

Because you're adding to the count in each iteration of your while loop.

Try
>         Count += VulgarSwears[Swear]
> while(Index)
> Index = findtext(msg,Swear,Index+length(Swear))
>


Mizukouken Ketsu wrote:
I did that and it said it went up 1,690 and booted me. I don't know about you, but that's worse than 745 >_>
In response to Nickr5
Nickr5 wrote:
>         while(Index)
> Count += VulgarSwears[Swear]
> Index = findtext(msg,Swear,Index+length(Swear))
>

Because you're adding to the count in each iteration of your while loop.

Well yes, it's obviously supposed to. The point is to add to the count each time it's found.

Try
>         Count += VulgarSwears[Swear]
> while(Index)
> Index = findtext(msg,Swear,Index+length(Swear))
>


That will add to the count once whether it's found or not. Not good.

Lummox JR
In your second loop, you have:

Index = findtext(msg,BannedWords)


That should be:

Index = findtext(msg,Swear)


I'm not sure why you actually need two loops and two separate lists though. They do the same thing, so you're better off combining them. It looks like you've probably modified my spam code from my Dream Tutor article, but part of that code was meant to keep the distinction between words you should look for whole, and words that you should filter anywhere. You're not doing the whole-word check though.

The reason the whole-word check matters of course is that some swear words appear as components in other non-swear words. This isn't true of the F-bomb, which is a cuss word everywhere you would ever encounter it, but you might for example have a problem talking about a certain species of mushroom or a common lake fish if you don't do a whole-word check on some of the others.

Lummox JR
In response to Lummox JR
Oops, guess I didn't read it carefully enough.
In response to Lummox JR
Vielen Dank, Lummox! ^-^