Checking who's near you.
#3

Use a Get Distance function:
pawn Код:
stock Float: GetDistanceToPoint(playerid,Float: X2,Float:Y2 ,Float: Z2)
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
  return floatsqroot ( floatpower ( floatabs ( floatsub ( X , X2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Y , Y2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Z , Z2 ) ) , 2 ) );
}
================================================== ==================================
There are better distance functions (you can try IsPlayerInRangeOfPoint but I personally had issues with it. There are other distance functions around if you search a little), this is the one I had at hand.

In the command, create a loop through all the players and get the distance. If the distance is less than 10, Get the player name and format a message.
================================================== ==================================

A quick example I made up:
pawn Код:
stock Float: GetDistanceToPoint(playerid,Float: X2,Float:Y2 ,Float: Z2)
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
  return floatsqroot ( floatpower ( floatabs ( floatsub ( X , X2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Y , Y2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Z , Z2 ) ) , 2 ) );
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/nearme", cmdtext, true, 10) == 0)
    {
        new Float:pos[3];
        GetPlayerPos(playerid,ppos[0],ppos[1],ppos[2]);
        for (new i = 0; i<MAX_PLAYERS; i++)
        {
            if(GetDistanceToPoint(i,pos[0],pos[1],pos[2])<10)
            {
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(i,pname,MAX_PLAYER_NAME);
                new string[64];
                format(string,sizeof(string),"%s(%i) is near you!",pname,i);
                SendClientMessage(playerid,0xFFFF00AA,string);
            }
        }
        return 1;
    }
    return 0;
}
Reply


Messages In This Thread
Checking who's near you. - by Shockey HD - 11.05.2012, 02:21
Re: Checking who's near you. - by JaKe Elite - 11.05.2012, 02:41
Re: Checking who's near you. - by Yuryfury - 11.05.2012, 02:46
Re: Checking who's near you. - by ReneG - 11.05.2012, 03:31
Re: Checking who's near you. - by Shockey HD - 11.05.2012, 03:35

Forum Jump:


Users browsing this thread: 1 Guest(s)