Anti text spam
#1

Hello, i need a small script which stores the last message player sent in chat, and then compare it with the one he sent now, in case both are same, a message should be sent to him "do not repeat yourself".

Thanks.
Reply
#2

PHP код:
new pLastMsg[100][MAX_PLAYERS];
public 
OnPlayerText(playeridtext[])
{
    
format(pLastMsg[playerid], 100text);
    if(!
strcmp(textpLastMsg[playerid], true))
    {
        
//Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    
}

Reply
#3

cant talk, it keeps saying do not repeat yourself (message i had put into condition)
Reply
#4

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
new pLastMsg[100][MAX_PLAYERS];
public 
OnPlayerText(playeridtext[])
{
    
format(pLastMsg[playerid], 100text);
    if(!
strcmp(textpLastMsg[playerid], true))
    {
        
//Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    
}

it wont work because you store the text to a var and then check both the vars are same or not (that logic make no sense man) it will not allow him to type anything.
you can do the intialising after checking
PHP код:
public OnPlayerText(playeridtext[])
{
    
    if(!
strcmp(textpLastMsg[playerid], true))
    {
        
//Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    
}
     
format(pLastMsg[playerid], 100text);

Reply
#5

Try this.

PHP код:
new ChatTime[MAX_PLAYERS],
    
ChatText[MAX_PLAYERS][144];
public 
OnPlayerDisconnect(playeridreason)
{
    
ChatTime[playerid] = 0;
    
format(ChatText[playerid], 144"");
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
    if((
GetTickCount() - ChatTime[playerid]) < 1000)
    {
        
SendClientMessage(playerid0xFF0000FF"Message has been blocked");
        return 
0;
    }
    if(
strlen(text) == strlen(ChatText[playerid]) && !strcmp(ChatText[playerid], text,  false))
    {
        
SendClientMessage(playerid0xFF0000FF"Your message has been blocked as spam");
        
format(ChatText[playerid], 144"%s"text);
        return 
0;
    }
    
ChatTime[playerid] = GetTickCount();
    
format(ChatText[playerid], 144"%s"text);
    return 
1;

Reply
#6

Код:
new LastMsg[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
	LastMsg[playerid] = 0;
}

public OnPlayerText(playerid, text[]) 
{
	if(strfind(LastText[playerid], text, false) != -1)
	{
		LastMsg[playerid]++;
		if(LastMsg[playerid] >= 2) // If he repeats it twice
		{
			SendClientMessage(playerid, COLOR_RED, "Don't repeat your message.");
			return false;
		}
		else
			LastMsg[playerid] = 0;
		strmid(LastText[playerid], text, 0, strlen(text), sizeof(LastText[]));
	}
}
Reply
#7

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
it wont work because you store the text to a var and then check both the vars are same or not (that logic make no sense man) it will not allow him to type anything.
you can do the intialising after checking
PHP код:
public OnPlayerText(playeridtext[])
{
    
    if(!
strcmp(textpLastMsg[playerid], true))
    {
        
//Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    
}
     
format(pLastMsg[playerid], 100text);

Oh lol what a mistake, strcmp must be first i just wrote it fast, try Sreyas code, it should work
Reply
#8

pawn Код:
new pLastMsg[MAX_PLAYERS][129 char];

public OnPlayerConnect(playerid)
{
    pLastMsg[playerid] = !"fghsfhdf";
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(!strcmp(text, pLastMsg[playerid], true))
    {
        //Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    }
    strpack(pLastMsg[playerid], text, sizeof(pLastMsg[]));
    return 1;
}
Reply
#9

Quote:
Originally Posted by Affan
Посмотреть сообщение
Код:
new LastMsg[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
	LastMsg[playerid] = 0;
}

public OnPlayerText(playerid, text[]) 
{
	if(strfind(LastText[playerid], text, false) != -1)
	{
		LastMsg[playerid]++;
		if(LastMsg[playerid] >= 2) // If he repeats it twice
		{
			SendClientMessage(playerid, COLOR_RED, "Don't repeat your message.");
			return false;
		}
		else
			LastMsg[playerid] = 0;
		strmid(LastText[playerid], text, 0, strlen(text), sizeof(LastText[]));
	}
}
Where did you define LastText ... ?
Reply
#10

Affan's code is wrong..
Try this
PHP код:
new pLastMsg[100][MAX_PLAYERS];
public 
OnGameModeInit()
{
    for(new 
ij=MAX_PLAYERSi<ji++) { format(pLastMsg[i], 100"!9sd4f"); }
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
    if(!
strcmp(textpLastMsg[playerid], true))
    {
        
//Have wrote the same message
        //Do something
        //return 0; to prevent sending the message
    
}
     
format(pLastMsg[playerid], 100text);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)