Find more than one nearby vehicle?
#1

I'm using this to find one nearest vehicle, but how can I convert it to find all vehicles in a given range?

pawn Код:
stock GetNearestVehicle(playerid, Float:range)
{
    new Float:x, Float:y, Float:z, Float:Distance;
    new nearbyveh = -1;
   
    for(new i=1; i < MAX_VEHICLES+1; i++)
    {
        if(i == GetPlayerVehicleID(playerid)) continue;
        GetVehiclePos(i, x, y, z);
        Distance = GetPlayerDistanceFromPoint(playerid, x, y, z);
       
        if(Distance <= range)
        {
            nearbyveh = i;
            range = Distance;
        }
    }
   
    return nearbyveh;
}
Reply
#2

Do you need to find all the vehicleid's or just the number of vehicles in a given range?
Reply
#3

All of the vehicleids in a given range.
Reply
#4

How do you want to use them afterwards, since there are various ways of doing this?

You could add each vehicle ID to a string, but I'm not sure why you would want to get each ID...?
Reply
#5

Quote:
Originally Posted by jakejohnsonusa
Посмотреть сообщение
How do you want to use them afterwards, since there are various ways of doing this?

You could add each vehicle ID to a string, but I'm not sure why you would want to get each ID...?
I'm making a radar command that catches the speed of all the vehicles in a given radius.
Reply
#6

Just use a loop with IsPlayerInRangeOfPoint
pawn Код:
new
    v,
    Float: X,
    Float: Y,
    Float: Z
;
while(++v < MAX_VEHICLES) {
    if(GetVehiclePos(v, X, Y, Z) && IsPlayerInRangeOfPoint(playerid, 30.0, X, Y, Z)) {
        // your code
    }
}
That would return all vehicles in 30.0 radius of the player
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)