AntiSpam - wutta
#1

pawn Код:
if(strcmp(LastMessage[playerid],text,true) == 0) {
            switch(PlayerInfo[playerid][pSpam]) {
                case 0: {
                    PlayerInfo[playerid][pSpam]++;
                }
                case 1: {
                    SendClientMessage(playerid,red,"Calm down, don't spam! :D");
                    PlayerInfo[playerid][pSpam]++;
                    return 0;
                }
                case 2: {
                    SendClientMessage(playerid,red,"Anti-spam warning, next is a kick!");
                    PlayerInfo[playerid][pSpam]++;
                    return 0;
                }
                case 3: {
                    SendClientMessage(playerid,red,"You've been kicked for spam!");
                    new spamtext[128], spamname[30];
                    PlayerInfo[playerid][pSpam] = 0;
                    GetPlayerName(playerid,spamname,sizeof(spamname));
                    format(spamtext,sizeof(spamtext),"ANTISPAM: %s has been kicked for spam.",spamname);
                    SendClientMessageToAll(red,spamtext);
                    Kick(playerid);
                    return 0;
                }
            }
        } else {
            format(LastMessage[playerid],128,"%s",text);
            PlayerInfo[playerid][pSpam] = 0;
        }
The problem is:
Whatever I say, it keeps increasing the PlayerInfo[playerid][pSpam].
So I type: "hi", then I type "test" then it returns "Calm down, don't spam "

What's this? O.o

Before you rewrite / share your code, I just need to correction :]
Reply
#2

It'll increase forever - that's how you've scripted it, you need to script a timer to run in conjunction with it so that a value is removed every X second (or create another variable which stores the last time a message was sent and compare it to the current time).
Reply
#3

Then how do I prevent a player to send the same message twice?
Reply
#4

Oh, my apologies - I misunderstood your code. Make sure you copy 'text' to LastMessage[playerid] after this switch statement, and then also make sure that you're copying it correctly.

Also, use this code for copying your string instead of your current method:
pawn Код:
strcat(LastMessage[playerid], text, 128);
Reply
#5

Nice thanks, it works now. I put the formatting outside of the else { }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)