20.02.2011, 17:15
Hi, so I have a problem with my function below. It's supposed to calculate the 3 nearest positions but it only returns the closest one on all of them. I've been trying various methods but I just can't seem to get it working :/
Any help would be appericated.
Thanks,
[03]Garsino.
Any help would be appericated.
pawn Код:
stock ReturnClosestDestinations(playerid, &dest1, &dest2, &dest3)
{
new Float:Pos[3], tmp1, tmp2, tmp3, Float:pdistance;
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
foreach(Locations, i)
{
pdistance = DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]);
printf("distance 1: %f", DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]));
printf("distance to point 1: %f | distance to point 2: %f ", DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]), DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[tmp1][PointX], lInfo[tmp1][PointY], lInfo[tmp1][PointZ]));
if(pdistance <= DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[tmp1][PointX], lInfo[tmp1][PointY], lInfo[tmp1][PointZ]))
{
dest1 = tmp1 = i;
print("tmp 1");
}
if(pdistance <= DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[tmp2][PointX], lInfo[tmp2][PointY], lInfo[tmp2][PointZ]) && i != dest1)
{
dest2 = tmp2 = i;
print("tmp 2");
}
if(pdistance <= DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[tmp3][PointX], lInfo[tmp3][PointY], lInfo[tmp3][PointZ]) && i != dest1 && i != dest2)
{
dest3 = tmp3 = i;
print("tmp 3");
}
}
return 1;
}
[03]Garsino.