Trams?
#2

Well, your function does not check for the closest one, but only if a tram is within the given range. So it will always return the id of the tram with the lowest vehicleid.
But you can do this with some extra lines:

pawn Код:
stock ReturnClosestTramID(playerid)
{
    new Float:nearest_dist = -1.0, nearest_id = -1;
    for(new c=0; c<MAX_VEHICLES; c++)
    {
        if(GetVehicleModel(c) == 449)
        {
            new Float:X,Float:Y,Float:Z;
            GetVehiclePos(c, X, Y, Z);
            if(GetPlayerToPoint(playerid, X, Y, Z) < nearest_dist || nearest_dist == -1.0)
            // You have to get any implementation of a GetPlayerToPoint function that returns the distance
            {
                nearest_dist = GetPlayerToPoint(playerid, X, Y, Z);
                nearest_id = c;
            }
        }
    }
    return c;
}
As you can see, you basically countercheck the distance with the currently shortest distance to see if the tram is nearer than your current nearest tram.
Reply


Messages In This Thread
Trams? - by Danny - 21.03.2011, 16:56
Re: Trams? - by Mauzen - 21.03.2011, 21:42

Forum Jump:


Users browsing this thread: 1 Guest(s)