SA-MP Forums Archive
Send message for near player - 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: Send message for near player (/showthread.php?tid=455869)



Send message for near player - Garwan50 - 03.08.2013

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


Re: Send message for near player - Virtual1ty - 03.08.2013

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


Re : Send message for near player - Garwan50 - 03.08.2013

Yeah, awesome, thanks


Re : Send message for near player - Garwan50 - 03.08.2013

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


Re : Send message for near player - Garwan50 - 03.08.2013

up plz :/


Re: Send message for near player - stokdam - 03.08.2013

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.


Re: Send message for near player - [KHK]Khalid - 03.08.2013

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.


Re : Send message for near player - Garwan50 - 03.08.2013

Lol, thanks mate


Re : Send message for near player - Garwan50 - 04.08.2013

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


Re: Send message for near player - stokdam - 04.08.2013

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;
}