SA-MP Forums Archive
Function for cars - 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: Function for cars (/showthread.php?tid=517997)



Function for cars - TheSy - 07.06.2014

Good morning.

I want to know if there is a function to determine if a vehicle is next to us?

And if no, do you would one for me?

thank you


Re: Function for cars - Faisal_khan - 07.06.2014

Well I found this"
pawn Code:
stock FindClosestVehicle(playerid)
{
    new
        Float:x, Float:y, Float:z,
        closest = -1;

    for(new a = 0; a < MAX_VEHICLES; a++)
    {
        GetVehiclePos(a, x, y, z);

        if(a != YOUR_VEHICLEID_OR_ARRAY/VARIBLE && IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z))
        {
            closest = a;
        }
    }
    if(closest != -1) return closest;
   
    return INVALID_VEHICLE_ID;
}
Ran a loop through all vehicles, checked for the vehicle near to you and then saved the result for further processing.