Getting pos with least distance - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting pos with least distance (
/showthread.php?tid=142026)
Getting pos with least distance -
ziomal432 - 16.04.2010
I've got this code:
Code:
new Float:pos[3], Float:Distance, Float:MaxDistance = 99999.0, LowestID = -1;
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
...
for(new i; i < sizeof(Pos247); i++)
{
Distance = PointToPoint3D(pos[0], pos[1], pos[2], Pos247[i][0], Pos247[i][1], Pos247[i][2]);
printf("%f %f", Distance, MaxDistance);
if(Distance < MaxDistance)
{
Distance = MaxDistance;
LowestID = i;
}
}
But the console shows:
Code:
[21:29:06] 2848.760009 99999.000000
[21:29:06] 2056.619873 99999.000000
[21:29:06] 1066.780151 99999.000000
[21:29:06] 1646.422973 99999.000000
[21:29:06] 2312.666259 99999.000000
[21:29:06] 5244.834960 99999.000000
[21:29:06] 2857.414306 99999.000000
[21:29:06] 1411.058227 99999.000000
[21:29:06] 1122.167846 99999.000000
[21:29:06] 1003.160583 99999.000000
[21:29:06] 1235.255126 99999.000000
[21:29:06] 1331.628173 99999.000000
[21:29:06] 2219.748046 99999.000000
- the if condition is not performed...
Re: Getting pos with least distance -
M4S7ERMIND - 16.04.2010
This will fix it:
Code:
MaxDistance = Distance;