Public chat


I'm trying to fix a public chat where the players color are the player of their nickname when they chat in the public chat. However when i try to fix this with SendPlayerMessageToAll, the message comes up x times as how many players are online. So if two players are online, the message comes up two times..


CMD:o(playerid, params[])
	if (g_StatusOOC && PlayerData[playerid][pAdmin] < 2)
	    return SendErrorMessage(playerid, "An administrator has disabled global OOC chat.");

	if (isnull(params))
	    return SendSyntaxMessage(playerid, "/o [global OOC]");

	if (PlayerData[playerid][pDisableOOC])
	    return SendErrorMessage(playerid, "You must enable OOC chat first.");

    if (strlen(params) < 128)
        foreach (new i : Player) if (!PlayerData[i][pDisableOOC] && PlayerData[i][pCreated]) {
		SendPlayerMessageToAll(playerid, params);
	return 1;
I've tried to format it and some other ways, but it comes always out with the same output or errors. However this code does not give error, but i have the problem mentioned above.

Change SendPlayerMessageToAll to SendClientMessagel(i, -1, params);

That will make just the message appear, and not name.
I want it Name (ID): Message

And the name with the player color. It works with the code above i've presented, however it sends the message more then one time. It sends the message x users online. So the same message comes up like two times, if there are two online.

SendPlayerMessageToPlayer sends the message with the name at the beginning and the color of the player but it has : after the name (at the same color) and not the player's ID so you'd still need to format it.

If you use SendClientMessage as Onfroi suggested, you will still need to format it and get the player's name too.

Forum Jump:

Users browsing this thread: 1 Guest(s)