SA-MP Forums Archive
OnPlayerText Help - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerText Help (/showthread.php?tid=206054)



[SOLVED]OnPlayerText Help - [BFT]eagles22 - 02.01.2011

I need help with OnPlayerText. I am trying to limit the globalchatradius and then send a message to the player who typed if nobody is within range. It works good except when i type something i get a message saying that i typed Eagle
i will include a screenshot
Код:
public OnPlayerText(playerid, text[])
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	format(text, 128, "%s : %s", name, text);
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	for (new i=0; i<MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
			if(IsPlayerInRangeOfPoint(i,200.0,x,y,z))
			{
	        SendClientMessage(i, GetPlayerColor(playerid), text);
	        }
		}
		else
		{
			return SendClientMessage(playerid, COLOR_WHITE, "[SERVER] : Nobody heard you, please use /shout or /me!");
		}
	}
	return 0;
}



Re: OnPlayerText Help - JaTochNietDan - 02.01.2011

I don't know why it's saying Eagle, but there's a logical problem with your code anyway.

It'll stop running as soon as it hits a player that is not connected, therefore anyone with an ID higher than that of the not connected ID, will not hear the text.

Instead I suggest you use a counter to check how many people received the message, and if none, then tell him that nobody heard you, for example.

pawn Код:
public OnPlayerText(playerid, text[])
{
    new name[MAX_PLAYER_NAME], counter;
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(text, 128, "%s : %s", name, text);
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for (new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i,200.0,x,y,z))
            {
                SendClientMessage(i, GetPlayerColor(playerid), text);
                counter++;
            }
        }
    }
    if(counter < 2) SendClientMessage(playerid, COLOR_WHITE, "[SERVER] : Nobody heard you, please use /shout or /me!"); // Note we're checking if it's less than 2, because the player will always hear himself speak, but that doesn't mean someone else heard him.
    return 0;
}



Re: OnPlayerText Help - [BFT]eagles22 - 02.01.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
I don't know why it's saying Eagle, but there's a logical problem with your code anyway.

It'll stop running as soon as it hits a player that is not connected, therefore anyone with an ID higher than that of the not connected ID, will not hear the text.

Instead I suggest you use a counter to check how many people received the message, and if none, then tell him that nobody heard you, for example.

pawn Код:
public OnPlayerText(playerid, text[])
{
    new name[MAX_PLAYER_NAME], counter;
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(text, 128, "%s : %s", name, text);
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for (new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i,200.0,x,y,z))
            {
                SendClientMessage(i, GetPlayerColor(playerid), text);
                counter++;
            }
        }
    }
    if(counter < 2) SendClientMessage(playerid, COLOR_WHITE, "[SERVER] : Nobody heard you, please use /shout or /me!"); // Note we're checking if it's less than 2, because the player will always hear himself speak, but that doesn't mean someone else heard him.
    return 0;
}
Thank you, that code worked perfectly.