You need to loop through the players and check if those players are in the same race as the "playerid". If they are and the value of the variable you store the checkpoints is greater than the one of "playerid", increase it by 1. If they're in the same, get the distance to the next cp (won't work perfect if the race's track is about turning 180 degrees and go to the next cp) and if it's less than "playerid"'s one, increase it again. The returning value will be increased by 1 as well. I had written this one long time ago, but you can get the idea.
PHP код:
// JUST AN EXAMPLE:
GetPlayerRacePosition(playerid, raceid)
{
new
position,
cp;
foreach(new i : Player)
{
if (Player_RaceID[i] == raceid && i != playerid)
{
if (Player_RaceCP[i] > Player_RaceCP[playerid]) ++position;
else if (Player_RaceCP[i] == Player_RaceCP[playerid])
{
cp = Player_RaceCP[playerid] + 1;
if (GetPlayerDistanceFromPoint(i, Race_CP[0][raceid][cp], Race_CP[1][raceid][cp], Race_CP[2][raceid][cp]) < GetPlayerDistanceFromPoint(playerid, Race_CP[0][raceid][cp], Race_CP[1][raceid][cp], Race_CP[2][raceid][cp]))
{
++position;
}
}
}
}
return position + 1;
}