Get closest point. - 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)
+--- Thread: Get closest point. (
/showthread.php?tid=433503)
Get closest point. -
audriuxxx - 27.04.2013
Hi,
I have 4 coordinates, and i want to get, which coordinate is closest from my. How i can do it?
Re: Get closest point. -
Jimmy0wns - 27.04.2013
Explain it better please?
Re: Get closest point. -
Faisal_khan - 27.04.2013
EDIT: damn misunderstood.
Re: Get closest point. -
audriuxxx - 27.04.2013
I have these coordinates:
Код:
1500.000,2.0000,1.0000
3000.500,0.5000,5.0000
2000.0,500.5,300.5
And how get, which coordinate is closest from my.
Re: Get closest point. -
Lordzy - 27.04.2013
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint
Re: Get closest point. -
Goldilox - 27.04.2013
Use loop for that.
Код:
new Float:min = 9999.9;
new minindex;
new Float:distance;
new Float:px, Float:py, Float:pz;
GetPlayerPos(playerid, px, py, pz);
// pointx/y/z[] is an array, that contains all the points you want to get the nearest from
for(new i = 0; i < sizeof(pointx); i ++)
{
distance = PointToPoint(px, py, pz, pointx[i], pointy[i], pointz[i]);
//Change this to your function to get the distance
if(distance < min)
{
minindex = i;
min = distance;
}
}