SA-MP Forums Archive
Public chat - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Public chat (/showthread.php?tid=608650)



Public chat - Swig - 03.06.2016

Howdy,

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..

Code:

Код:
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.


Re: Public chat - Onfroi - 03.06.2016

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


Re: Public chat - Swig - 03.06.2016

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.


Re: Public chat - Konstantinos - 03.06.2016

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.