SA-MP Forums Archive
Checking if a player is close - 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: Checking if a player is close (/showthread.php?tid=427681)



Checking if a player is close - liam1412 - 02.04.2013

In a pay command, I want to check if they payer and payee are close to each other.

Any ideas?

Thanks


Re: Checking if a player is close - brawrr - 02.04.2013

use this func

PHP код:
forward GetClosestPlayer(p1);// top
public GetClosestPlayer(p1)
{
    new 
x,Float:dis,Float:dis2,player;
    
player = -1;
    
dis 99999.99;
    for (
x=0;x<MAX_PLAYERS;x++)
    {
        if(
IsPlayerConnected(x))
        {
            if(
!= p1)
            {
                
dis2 GetDistanceBetweenPlayers(x,p1);
                if(
dis2 dis && dis2 != -1.00)
                {
                    
dis dis2;
                    
player x;
                }
            }
        }
    }
    return 
player;

and u can use this func like that

PHP код:
GivePlayerMoney(GetClosestPlayer(playerid), 100); // give $100 to closest player 



Re: Checking if a player is close - Finn - 02.04.2013

https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

pawn Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(PLAYER_ID_NUMBER_ONE, x, y, z);

if(IsPlayerInRangeOfPoint(PLAYER_ID_NUMBER_TWO, 2.0, x, y, z))
{
    // They are within 2.0 units
}
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint

pawn Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(PLAYER_ID_NUMBER_ONE, x, y, z);

if(GetPlayerDistanceFromPoint(PLAYER_ID_NUMBER_TWO, x, y, z) < 2.0)
{
    // They are within 2.0 units
}



Re: Checking if a player is close - MP2 - 02.04.2013

I'd personally use a bigger radius than 2; perhaps 5.


Re: Checking if a player is close - liam1412 - 03.04.2013

I settled on 3.0

Thanks for the help as always!