Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ( Check if a_samp it's included in the main script )
- #if !defined a_samp
- #include a_samp
- #endif
- #if !defined foreach
- #include foreach
- #endif
- #define FLOAT_INFINITY (Float:0x7F800000)
- // ( This is the function you can simply use on your script )
- stock GetClosestPlayer( playerid, checkvw = false, Float:range = FLOAT_INFINITY )
- {
- new Float:playerPos[ 3 ], Float:thisDist;
- GetPlayerPos( playerid, playerPos[ 0 ], playerPos[ 1 ], playerPos[ 2 ]);
- new Float:closestDist = FLOAT_INFINITY;
- new closestPlayer = INVALID_PLAYER_ID;
- foreach(new i : Player)
- {
- if( i == playerid ) continue;
- if( checkvw && GetPlayerVirtualWorld( playerid ) != GetPlayerVirtualWorld( i ) ) continue;
- if( GetPlayerInterior( playerid ) != GetPlayerInterior( i ) ) continue;
- thisDist = GetPlayerDistanceFromPoint( i, playerPos[ 0 ], playerPos[ 1 ], playerPos[ 2 ] );
- if( thisDist < closestDist && thisDist < range )
- {
- closestPlayer = i;
- closestDist = thisDist;
- }
- }
- return closestPlayer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement