You don't really need to understand the maths in the GetDistanceBetweenCoords method itself, you just need
to know how to use the function. It does as it says - gets the distance between two points.
It has four parameters:
x1 and y1 are the X and Y coordinates of one point (in your case the player)
x2 and y2 are the X and Y coordinates of another point (in your case the checkpoint)
Here's an example of how you might use the function:
pawn Код:
new leaderid, Float:shortestdistance=999999, Float:x, Float:y, Float:z;
for(new i=0; i<MAX_PLAYERS; i++) // loops through all players
{
if(IsPlayerConnected(i)) // checks the current player being checked is connected
{
GetPlayerPos(i, x, y, z); // gets the current players x, y and z coords and stores them in the variables x, y and z
if(GetDistanceBetweenCoords(x, y, CHECKPOINT_X, CHECKPOINT_Y) < shortestdistance) // if the player is closer to the checkpoint than the current shortest distance of another player, continue
{
shortestdistance = GetDistanceBetweenCoords(x, y, CHECKPOINT_X, CHECKPOINT_Y); // set the new shortest distance
leaderid= i; // set the playerid of the new closest player
}
}
}
leaderid would be the playerid of the player closest to the checkpoint.