11.12.2010, 16:37
e,g i have 4 points, i want to get the one closest to the player
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;
}
}
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
x1 -= x2;
y1 -= y2;
z1 -= z2;
return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
distance = PointToPoint(px, py, pz, ClosestBurgerShots[i], ClosestBurgerShots[i], ClosestBurgerShots[z]);
if(distance < min)
{
minindex = i;
min = distance;
new Loc[MAX_ZONE_NAME];
Get2DZone(Loc,ClosestBurgerShots[i], ClosestBurgerShots[i], ClosestBurgerShots[z]);
SetPlayerRouting(playerid, 1559.5081, -1290.5549,"Burger Shot In %s",Loc);
}
new Float:ClosestBurgerShots[][3] = {
{2366.3240,2071.0330,10.8203},
{2472.1331,2034.2130,11.0625},
{1873.4980,2071.7546,11.0625}
};
//the whole code above here
new Loc[MAX_ZONE_NAME];
Get2DZone(Loc,ClosestBurgerShots[minindex][0], ClosestBurgerShots[minindex][1], ClosestBurgerShots[minindex][2]);
SetPlayerRouting(playerid, 1559.5081, -1290.5549,"Burger Shot In %s",Loc);