GetClosestVehicle
#4

Quote:
Originally Posted by Stinged
Посмотреть сообщение
You should start using GetVehiclePoolSize (Unless you're not using SA-MP 0.3.7)
It retrieves the highest vehicle ID, so instead of 2000 (MAX_VEHICLES), you'd be using something much lower if there isn't a lot of vehicles.

I just wrote this, so I'm not sure if it has any bugs or not.
Код:
native IsValidVehicle(vehicleid); // According to the wiki, it doesn't exist in the default sa-mp includes, so you have to add it.

GetClosestVehicle(playerid, Float: range)
{
    new
        vehicleid = -1,
        Float: last = range,
        Float: current,
        
        Float: x, Float: y, Float: z;
    GetPlayerPos(playerid, x, y, z);
    for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++) // for (new i = 1; i < MAX_VEHICLES; i++)
    {
        if (!IsValidVehicle(i)) continue;
        current = GetVehicleDistanceFromPoint(i, x, y, z);
        if (current < last)
        {
            vehicleid = i;
            last = current;
        }
    }
    return vehicleid;
}

Thank you, great help. Didn't know about GetVehiclePoolSize, thanks!

Thanks everyone else.
Reply


Messages In This Thread
GetClosestVehicle - by Jonesy96 - 14.07.2016, 15:40
Re: GetClosestVehicle - by Stinged - 14.07.2016, 16:20
Re: GetClosestVehicle - by Luicy. - 14.07.2016, 16:25
Re: GetClosestVehicle - by Jonesy96 - 14.07.2016, 16:28
Re: GetClosestVehicle - by Konstantinos - 14.07.2016, 16:30
Re: GetClosestVehicle - by Jonesy96 - 14.07.2016, 16:53

Forum Jump:


Users browsing this thread: 2 Guest(s)