OnPlayerText Help
#1

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;
}
Reply
#2

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;
}
Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)