whats wrong with this function? - 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: whats wrong with this function? (
/showthread.php?tid=288546)
whats wrong with this function? -
BaubaS - 08.10.2011
thread says all. it always returning 0, instead of vehicleid or invalid_vehicle_id value
pawn Код:
stock GetClosestVehicle(playerid, Float: fRadius) // by RyDeR`
{
new
iClosestID = INVALID_VEHICLE_ID,
Float: fFinalDistance,
Float: fDistance,
Float: fX,
Float: fY,
Float: fZ;
GetPlayerPos(playerid, fX, fY, fZ);
fFinalDistance = fRadius;
for(new i; i != Cars; ++i)
{
if((fDistance = GetVehicleDistanceFromPoint(i, fX, fY, fZ)) < fFinalDistance)
{
fFinalDistance = fDistance;
iClosestID = i;
}
}
return iClosestID;
}
Re: whats wrong with this function? -
TheLazySloth - 08.10.2011
If its from RyDeR, nothing because he is king at distances, unless you tweeked it... all I see that is weird is in the loop.
for(new i; i != Cars; ++i)
... try for(new i = 0; i < MAX_VEHICLES; i++)
Re: whats wrong with this function? -
BaubaS - 08.10.2011
Cars is value of created vehicles, its the same. Instead of loop 2000 vehicles, when ~200 is created Im looping created vehicles only (200)
Re: whats wrong with this function? -
TheLazySloth - 08.10.2011
Then try,
for(new i = 0; i < (Cars + 1); i++)
because the != will make it loop to infinity -.-