Clear Chat
#1

hi i want clear only players chat not admins

Help = +Rep

Код:
COMMAND:clearchat(playerid, params[])
{
	if(playerData[playerid][playerLoggedIn])
	{
		if(playerData[playerid][playerLevel] >= 3)
		{
			for(new i = 0; i < 50; i++) 
			{
			    SendClientMessageToAll(COLOR_WHITE," ");
			}
			
			SendClientMessageToAll(COLOR_WHITE, "{A9C4E4}An administrator has cleared the chat.");	

			new log[250];
			format(log, sizeof(log), "%s(%i) cleared the chat", playerData[playerid][tempAdminName], playerid);
			SendAdminText(playerid, log);			
		}
		else
		{
			return 0;
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}You must be logged in to use commands.");
	}
	return 1;
}
Reply
#2

You're using a loop, therefore it will loop through ALL players and send the message to every single player.

More on Loops: https://sampwiki.blast.hk/wiki/Loops
Reply
#3

I have re-coded the way you clear the chat, The chat is only cleared out for players [not Admins].

Note; I am not sure if you are using foreach, So i have used a standard player looping on this code, This is a bad method. Use foreach.

PHP код:
COMMAND:clearchat(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 3)
        {
            for(new 
i=0i<MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i))
                {
                    if(
playerData[i][playerLevel] == 0)
                    {
                        for(new 
050x++)
                        {
                            
SendClientMessage(iCOLOR_WHITE," ");
                        }
                    }
                }
            }
            
SendClientMessageToAll(COLOR_WHITE"{A9C4E4}An administrator has cleared the chat.");
            new 
log[250];
            
format(logsizeof(log), "%s(%i) cleared the chat"playerData[playerid][tempAdminName], playerid);
            
SendAdminText(playeridlog);
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_WHITE"{B7B7B7}[SERVER] {FFFFFF}You must be logged in to use commands.");
    }
    return 
1;

Reply
#4

Thanks +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)