/clearchat
#1

There are a lot of spammers that come in and just spam.... Is there a command that clears the chat so it doesn't get flooded

Please write the code below



Thanks
Reply
#2

pawn Код:
CMD:clearchat ( playerid , params [] )
{
    for ( new i = 0 ; i < 50 ; i ++ )
    SendClientMessageToAll ( green , " " ) ;

    return 1 ;
}
Reply
#3

This comes up...
Код:
C:\Documents and Settings\hidden_user\My Documents\GTA SA Server\gamemodes\cnr.pwn(1465) : warning 203: symbol is never used: "clearchat"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Reply
#4

Quote:

for(new i = 0; i < 50; i++) SendClientMessageToAll(COLOR_WHITE," "); return 1;

This just spams spaces, so that u cannot see anything which was spammed earlier.
Reply
#5

Код:
if(strcmp(cmd, "/cc", true) == 0) // By Cavetchi
	{
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] < 1)
            {
                SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command.");
                return 1;
            }
            for(new i = 0; i < MAX_PLAYERS; i++)
            ClearChatbox(i, 100);
            SendClientMessageToAll(COLOR_LIGHTBLUE, "Chat has been Cleared!");

			format(string, sizeof(string), "[ADMIN]: %s has Cleared the Chat", sendername);
			ABroadCast(COLOR_LIGHTRED,string, 5);
			new y, m, d;
			new h,mi,s;
			getdate(y,m,d);
			gettime(h,mi,s);
			format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has Cleared the Chat",d,m,y,h,mi,s,sendername);
			ChatLog(string);
			AdminLog(string);
		}
		return 1;
	}
Reply
#6

pawn Код:
YCMD:cc(playerid, params[], help)
    {
        #pragma unused params, help
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 1 || PlayerInfo[playerid][pHelper] >= 1)
            {
                ClearChatboxToAll(playerid,100);
                GameTextForAll("Chat cleared!", 1000,1);
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(string, sizeof(string), "Admin %s has cleared the chat.",sendername);
                SendClientMessageToAll(COLOR_LIGHTRED, string);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "You do not have permission to use that command!");
                return 1;
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "You Must be logged in to use this command!");
        }
    }
YCMD is the best. Change the admin variable with yours...
Reply
#7

Код:
if (strcmp(cmdtext,"/clearchat", true , 10) == 0)//--- only use if neccesery
	{
 	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,red,"You need to be Rcon To Use This Command!");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
    SendClientMessageToAll(yellow," ");
	SendClientMessageToAll(yellow," ");
	new string[64], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    format(string,sizeof string,"Admin %s Has now Cleared the chat!",pName);
    SendClientMessageToAll(yellow,string);
	return 1;
	}
maybe too long sry
Reply
#8

There's two ways you can handle it,
1) The easy way, which Beljulji's code showed - which is sending messages to everyone and clearing everyone's chat.
2) You can use what everyone said, which is also a shorter code, which I'd choose,
pawn Код:
for(new i = 0; i < 50; i++) SendClientMessageToAll(COLOR_WHITE," "); return 1;
However another way to prevent spammers, is having commands such as /mute, for admins or rcon admins, or better yet a small little system within your script to actually prevent spamming - which you can choose to either mute them for a certain amount of time, or kick them, which is something I would do + the clearchat command.

This is a good example of anti-spam;
https://sampforum.blast.hk/showthread.php?tid=169530
Reply
#9

Its easy to create..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)