Send message for near player
#1

hello,

i want that just nearby player can hear what someone else tell.

My callback OnPlayerText:
pawn Код:
if (PlayerInfo[playerid][pAdmin] == 0)
    {
        new playername[MAX_PLAYER_NAME], str[124];
        GetPlayerName(playerid, playername, sizeof(playername));
        format(str, sizeof(str), "%s [%i] dit: %s", playername, playerid, text);
        SendMessageForNearbyPlayer(playerid, str);
    }
The function SendMessageForNearbyPlayer:
pawn Код:
stock SendMessageForNearbyPlayer(playerid, text[])
{
    new Float:posX, Float:posY, Float:posZ;
    GetPlayerPos(playerid, posX, posY, posZ);
    for (new p = 0; p<MAX_PLAYERS; p++)
    {
        if (IsPlayerConnected(p))
        {
            if(IsPlayerInRangeOfPoint(p, 2, posX, posY, posZ))
            {
                SendClientMessage(p, -1, text);
            }
            else if(IsPlayerInRangeOfPoint(p, 4, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFF949494, text);
            }
            else if(IsPlayerInRangeOfPoint(p, 6, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFF373737, text);
            }
        }
    }
}

If the player is at 2 meter, i hear well, if 4, less, and 6, barely none. (white to gray/black)

But in game, the text is only white.

Sorry for my english, i'm french !
Thanks a lot
Reply
#2

-removed-
The code becomes (note that it uses foreach by ******):
pawn Код:
stock SendMessageToNearByPlayers(playerid, text[])
{
    new
        Float:pX,
        Float:pY,
        Float:pZ
    ;

    GetPlayerPos(playerid, pX, pY, pZ);

    foreach (new i : Player)
    {
        if (IsPlayerInRangeOfPoint(i, 2.0, pX, pY, pZ))
            SendClientMessage(i, 0xFFFFFFFF, text);
        else if (IsPlayerInRangeOfPoint(i, 4.0, pX, pY, pZ))
            SendClientMessage(i, 0xFF949494, text);
        else if (IsPlayerInRangeOfPoint(i, 6.0, pX, pY, pZ))
            SendClientMessage(i, 0xFF373737, text);
    }
}
Edit: I was wrong. Replaced with a working function.
Reply
#3

Yeah, awesome, thanks
Reply
#4

wow, again it doesn't work o

pawn Код:
stock SendMessageForNearbyPlayer(playerid, text[])
{
    new Float:posX, Float:posY, Float:posZ;
    GetPlayerPos(playerid, posX, posY, posZ);
    for (new p = 0; p<MAX_PLAYERS; p++)
    {
        if (IsPlayerConnected(p))
        {
            if(IsPlayerInRangeOfPoint(playerid, 6.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x3C3C3CFF, text);
            }
            else if(IsPlayerInRangeOfPoint(playerid, 4.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x6F6F6FFF, text);
            }
            else if(IsPlayerInRangeOfPoint(playerid, 2.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFFFFFF, text);
            }
        }
    }
}
It always send gray/black text
Reply
#5

up plz :/
Reply
#6

you checked the distance from the same player you did GetPlayerPos.

pawn Код:
stock SendMessageForNearbyPlayer(playerid, text[])
{
    new Float:posX, Float:posY, Float:posZ;
    GetPlayerPos(playerid, posX, posY, posZ);
    for (new p = 0; p<MAX_PLAYERS; p++)
    {
        if (IsPlayerConnected(p))
        {
            if(IsPlayerInRangeOfPoint(p, 2.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x3C3C3CFF, text);
                return 1;
            }
            else if(IsPlayerInRangeOfPoint(p, 4.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x6F6F6FFF, text);
                return 1;
            }
            else if(IsPlayerInRangeOfPoint(p, 6.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFFFFFF, text);
                return 1;
            }
        }
    }
return 1;
}
edited: added returns.
Reply
#7

Quote:
Originally Posted by stokdam
Посмотреть сообщение
you checked the distance from the same player you did GetPlayerPos.

pawn Код:
stock SendMessageForNearbyPlayer(playerid, text[])
{
    new Float:posX, Float:posY, Float:posZ;
    GetPlayerPos(playerid, posX, posY, posZ);
    for (new p = 0; p<MAX_PLAYERS; p++)
    {
        if (IsPlayerConnected(p))
        {
            if(IsPlayerInRangeOfPoint(p, 2.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x3C3C3CFF, text);
                return 1;
            }
            else if(IsPlayerInRangeOfPoint(p, 4.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x6F6F6FFF, text);
                return 1;
            }
            else if(IsPlayerInRangeOfPoint(p, 6.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFFFFFF, text);
                return 1;
            }
        }
    }
return 1;
}
edited: added returns.
You really don't need the returns inside the loop as they will just send the message to the lowest ID and stop there.
Reply
#8

Lol, thanks mate
Reply
#9

Mhhh, doesn't work, the distance work, but the color is always gray/black :/
Reply
#10

pawn Код:
stock SendMessageForNearbyPlayer(playerid, text[])
{
    new Float:posX, Float:posY, Float:posZ;
    GetPlayerPos(playerid, posX, posY, posZ);
    for (new p = 0; p<MAX_PLAYERS; p++)
    {
        if (IsPlayerConnected(p))
        {
            if(IsPlayerInRangeOfPoint(p, 2.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x3C3C3CFF, text);
                continue;
            }
            else if(IsPlayerInRangeOfPoint(p, 4.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0x6F6F6FFF, text);
                continue;
            }
            else if(IsPlayerInRangeOfPoint(p, 6.0, posX, posY, posZ))
            {
                SendClientMessage(p, 0xFFFFFF, text);
                continue;
            }
        }
    }
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)