Calculating the 3 closest locations
#1

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.
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;
}
Thanks,
[03]Garsino.
Reply


Messages In This Thread
Calculating the 3 closest locations - by [03]Garsino - 20.02.2011, 17:15
Re: Calculating the 3 closest locations - by MadeMan - 20.02.2011, 19:15
Re: Calculating the 3 closest locations - by [03]Garsino - 20.02.2011, 20:05
Re: Calculating the 3 closest locations - by [03]Garsino - 24.02.2011, 05:51
Re: Calculating the 3 closest locations - by [03]Garsino - 28.02.2011, 07:08
Re: Calculating the 3 closest locations - by legodude - 28.02.2011, 08:26
Re: Calculating the 3 closest locations - by Simon - 28.02.2011, 08:50

Forum Jump:


Users browsing this thread: 1 Guest(s)