21.09.2011, 12:54
You could try:
Modify to suit your needs.
pawn Код:
stock GetClosestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}