SA-MP Forums Archive
GetClosestHouse - 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: GetClosestHouse (/showthread.php?tid=179488)



GetClosestHouse - MisterTickle - 27.09.2010

I am attempting to make a way to loop through all the houses, Find the one that is the closest and return it. Any ideas?

Код:
fpublic GetClosestHouse(playerid)
{
	foreach(house, i)
	{
	    return i;
	}
	return -255;
}



Re: GetClosestHouse - Retardedwolf - 27.09.2010

Does your script have a enum or variable/float to store where the house doors X, Y, Z is? If not make one then you could use some a function to compare the distances between each of the houses and return the closest house.

http://forum.sa-mp.com/showthread.ph...light=Distance


pawn Код:
public GetClosestHouse(playerid, Float:Distance = 1000.0)
{
    Distance = floatabs(Distance);
    if(!Distance Distance = 1000.0;
    new
        Float:X[2],
        Float:Y[2],
        Float:Z[2],
        Float:NearestPos = Distance,
        NearestHouse;
    GetPlayerPos(playerid, X[0], Y[0], Z[0]);
    foreach(house, i)
    {
        X[1] = Houses[i][hExteriorX]
        Y[1] = Houses[i][hExteriorY]
        if(NearestPos > PointToPoint2D(X[0], Y[0], X[1], Y[1])) NearestPos = PointToPoint(X[0], Y[0], X[1], Y[1])), NearestHouse = i;
        }
       return i;
    }
    return -255;
}
Based on https://sampforum.blast.hk/showthread.php?tid=125880