Advertisement
SoNNyPawno

Untitled

Apr 14th, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.09 KB | None | 0 0
  1. // ( Check if a_samp it's included in the main script )
  2. #if !defined a_samp
  3.  
  4. #include a_samp
  5.  
  6. #endif
  7. #if !defined foreach
  8.  
  9. #include foreach
  10.  
  11. #endif
  12.  
  13. #define FLOAT_INFINITY (Float:0x7F800000)
  14.  
  15. // ( This is the function you can simply use on your script )
  16. stock GetClosestPlayer( playerid, checkvw = false, Float:range = FLOAT_INFINITY )
  17. {
  18.     new Float:playerPos[ 3 ], Float:thisDist;
  19.     GetPlayerPos( playerid, playerPos[ 0 ], playerPos[ 1 ], playerPos[ 2 ]);
  20.  
  21.     new Float:closestDist = FLOAT_INFINITY;
  22.     new closestPlayer = INVALID_PLAYER_ID;
  23.  
  24.     foreach(new i : Player)
  25.     {
  26.         if( i == playerid ) continue;
  27.         if( checkvw && GetPlayerVirtualWorld( playerid ) != GetPlayerVirtualWorld( i ) ) continue;
  28.         if( GetPlayerInterior( playerid ) != GetPlayerInterior( i ) ) continue;
  29.  
  30.         thisDist = GetPlayerDistanceFromPoint( i, playerPos[ 0 ], playerPos[ 1 ], playerPos[ 2 ] );
  31.         if( thisDist < closestDist && thisDist < range )
  32.         {
  33.             closestPlayer = i;
  34.             closestDist = thisDist;
  35.         }
  36.     }
  37.     return closestPlayer;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement