06.01.2014, 13:52
Hi all! I am wondering if there is a way to hide other players chat to the player and he will be unable to see their chat but can see SenDClientMessage(s). Is it possible, if yes how?
//Create a variable where you'll store wheather the chat should be blocked or not.
new ChatBlocked[MAX_PLAYERS];
// Un-Block the chat when player connects
public OnPlayerConnect(playerid)
{
ChatBlocked[playerid] = 0;
return 1;
}
public OnPlayerText(playerid,text[])
{
//check if the player is blocked for getting chats from all players
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(ChatBlocked[i] == 1)
{
return 0;
}
else SendClientMessageToAll(GetPlayerColor(playerid),text);
}
return 1;
}
//now you can make command to (un)block the chat for player.
CMD:chatblock(playerid,params[])
{
new pID,value;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xCCCCCCCC,"You're not a RCON admin.");
if(sscanf(params,"ud",pID,value)) return SendClientMessage(playerid,0xFFFFFFFF,"USAGE: /chatblock [playerid] [value]");
if(!IsPlayerConnected(pID)) return SendClientMessage(playerid,0xCCCCCCCC,"Player is not connected.");
if(!(-1 < value < 2)) return SendClientMessage(playerid,0xCCCCCCCC,"Invalid value [0-1]");
ChatBlocked[playerid] = value;
return 1;
}
new bool:ChatBlocked[MAX_PLAYERS];
public OnPlayerText(playerid, text[])
{
// Setup local variables
new Msg[128], Name[24];
// Get the player's name
GetPlayerName(playerid, Name, 24);
// Pre-format the text to be sent
format(Msg, 128, "%s: %s", Name, text);
// Send the inputted text to all players who are NOT blocked
for (new i; i < MAX_PLAYERS; i++)
{
// If this player is allowed to see chat from other players
if (ChatBlocked[i] == false)
{
// Send the text to him
SendClientMessage(i, 0xFFFFFFFF, Msg);
}
}
// Block the text from appearing normally in everyone's chatbox
return 0;
}