SA-MP Forums Archive
How to know if a player is near another 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: How to know if a player is near another player (/showthread.php?tid=403151)



How to know if a player is near another player - T_Boy - 29.12.2012

Hello. I want to make a good /pay command, so I want the receiver to be near the giver, but I don't know how to script this! Any help?


Re : How to know if a player is near another player - DaRk_RaiN - 29.12.2012

Lets start off with the player position.
Put this right under the command
pawn Код:
new Float:x, Float:y, Float:z;
Now we will get his position
pawn Код:
GetPlayerPos(playerid,x, y, z);
I assume you used sscanf so we'll check if any one is near the player
pawn Код:
if(!IsPlayerInRangeOfPoint(targetid,5,x,y,z)return SendClientMessage(playerid,-1,"There isn't a near by player");
And that's it.


Re: How to know if a player is near another player - Faisal_khan - 29.12.2012

Get the player's position and the use it in IsPlayerInRangeOfPoint function and check if he is near the other player.


Re: How to know if a player is near another player - Mado - 29.12.2012

How I do it:

pawn Код:
if (ProxDetectorS(8.0, playerid, giveplayerid))
            {
                                //Your action
                         }



Re: How to know if a player is near another player - Faisal_khan - 29.12.2012

Its exactly the same what we showed him.:
pawn Код:
stock ProxDetector(Float:radi, playerid, string[],color)
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    for(new player;player<MAX_PLAYERS;player++)
    {
        if(!IsPlayerConnected(playerid))continue;
        if(IsPlayerInRangeOfPoint(playerid,radi,x,y,z))SendClientMessage(player,color,string);
    }
}



Re: Re : How to know if a player is near another player - T_Boy - 29.12.2012

Thank you, man!