Disable the chat for a certain player -
[NWA]Hannes - 20.06.2012
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?
Re: Disable the chat for a certain player -
Faisal_khan - 20.06.2012
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;
}
Re: Disable the chat for a certain player -
Burridge - 20.06.2012
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.
Re: Disable the chat for a certain player -
[NWA]Hannes - 20.06.2012
Quote:
Originally Posted by Burridge
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?
Re: Disable the chat for a certain player -
Faisal_khan - 20.06.2012
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.
Re: Disable the chat for a certain player -
[NWA]Hannes - 20.06.2012
Quote:
Originally Posted by Faisal_khan
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*
Re: Disable the chat for a certain player -
Faisal_khan - 21.06.2012
SendClientMessage will be a better option. Cause SendPlayerMessageToPlayer is very different from SCM.