Disable the chat for a certain player
#1

Hello! I'm wondering if there are any ways to disable the chat for a certain player? For example if a player writes /disablechat they would not be able to see anything that other players write. How can I do this?
Reply
#2

Add this on top:
pawn Code:
new AllowChat[MAX_PLAYERS];
This under OnPlayerText:
pawn Code:
public OnPlayerText(playerid, text[]){
//SendClientMessageToAll(0xffffffff,text); //disabled this, and replaced by the following loop:
new MaxPlayers=GetMaxPlayers();
for(new id=0;id<MaxPlayers;id++)
{
    if(AllowChat[id]==1)// dont forget to set this to 1 when spawning!
    {
        SendClientMessage(id,0xffffffff,text);
    }
    return 1;
}
And this is your command:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/disablechat", cmdtext, true) == 0)
    {
        if(AllowChat[playerid] == 1)
        {
            AllowChat[playerid]=0;
        }
        else
        {
            AllowChat[playerid]=1;
        }
        return 1;
    }
    return 0;
}
Reply
#3

pawn Code:
public OnPlayerText(playerid, text[]){
//SendClientMessageToAll(0xffffffff,text); //disabled this, and replaced by the following loop:
new MaxPlayers=GetMaxPlayers();
for(new id=0;id<MaxPlayers;id++)
{
    if(AllowChat[id]==1)// dont forget to set this to 1 when spawning!
    {
        SendClientMessage(id,0xffffffff,text);
        return 0; // You also need to return 0 here so that it doesn't continue and show their text anyway
    }
    return 1;
}
You need to return 0 as well, otherwise it'll show them the error message, and also still return their chat text, instead of stopping it.
Reply
#4

Quote:
Originally Posted by Burridge
View Post
pawn Code:
public OnPlayerText(playerid, text[])
{
    new MaxPlayers=GetMaxPlayers();
    for(new id=0;id<MaxPlayers;id++)
    {
        if(AllowChat[id]==1)// dont forget to set this to 1 when spawning!
        {
            SendClientMessage(id,0xffffffff,text);
            return 0; // You also need to return 0 here so that it doesn't continue and show their text anyway
        }
        return 1;
    }
    return 0;
}
Wouldnt this script make all the messages white?
Reply
#5

Alternative way:
Press F1 while in-game you will get some shortcuts key. Which has chat disabling key which you want. I think its F9.
Reply
#6

Quote:
Originally Posted by Faisal_khan
View Post
Alternative way:
Press F1 while in-game you will get some shortcuts key. Which has chat disabling key which you want. I think its F9.
Yeah but I want to only disable the chat and have the HUD left.

Btw would it be a good idea to use SendPlayerMessage instead of SendClientMessage?

EDIT: SendPlayerMessageToPlayer*
Reply
#7

SendClientMessage will be a better option. Cause SendPlayerMessageToPlayer is very different from SCM.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)