SA-MP Forums Archive
closest vehicle - 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: closest vehicle (/showthread.php?tid=517650)



closest vehicle - n00el - 06.06.2014

hello.
how i can get a closest vehicle without the current vehicle id?
for e.g. i am in a vehicle (id 2) and near me there is a vehicle (id 3).

when i am using this, i always get id 2. how i can get id 3?
PHP код:
stock GetClosestVehicle(playeridFloat:radius)
{
    new 
Float:CarXFloat:CarZFloat:CarYFloat:DisFloat:Dis2,vehicleid;
    
Dis 99999.99;
    
vehicleid INVALID_VEHICLE_ID;
    for(new 
0MAX_VEHICLESi++)
    {
        
GetVehiclePos(iCarXCarYCarZ);
        
Dis2 GetPlayerDistanceFromPoint(playeridCarXCarYCarZ);
        if(
Dis2 Dis && Dis2 radius)
        {
                
Dis Dis2;
                
vehicleid i;
        }
    }
    return 
vehicleid;




Re: closest vehicle - BroZeus - 06.06.2014

if(Dis2 < Dis && Dis2 < radius)
change this to this --
if(Dis2 < Dis && Dis2 < radius && i != GetPlayerVehicleID(playerid))