SA-MP Forums Archive
Player next to 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: Player next to vehicle (/showthread.php?tid=389120)



Player next to vehicle - Amine_Mejrhirrou - 31.10.2012

Hi all
If any one has the code of
a function that Detect the vehicleid next to the playerid pleas share it


Re: Player next to vehicle - tyler12 - 31.10.2012

PHP код:
stock GetNearestVehicle(playeridFloat:dis)
{
    new 
Float:LFloat:OFloat:II;
    if(
GetPlayerPos(playeridLOII))
    {
        new 
vehicleid INVALID_VEHICLE_ID;
        for(new 
vFloat:tempFloat:VLFloat:VOFloat:VII!= MAX_VEHICLESv++)
        {
            if(
GetVehiclePos(vVLVOVII) && != GetPlayerVehicleID(playerid))
            {
                
VL -= LVO -= OVII -= II;
                
temp VL VL VO VO VII VII;
                if(
temp disdis tempvehicleid v;
            }
        }
        
dis floatpower(dis0.5);
        return 
vehicleid;
    }
    return 
INVALID_VEHICLE_ID;




Re : Player next to vehicle - Amine_Mejrhirrou - 31.10.2012

gonna test and ++ REP if it works thnsk


Re: Player next to vehicle - Stu1 - 31.10.2012

If that doesn't work then heres one.
PHP код:
stock GetClosestVehicle(playerid)
{
    new 
Float:xFloat:yFloat:z;
    new 
Float:distFloat:closedist=50closevehfound 0;
    for(new 
i=1MAX_VEHICLESi++)
    {
        if(
GetVehiclePos(ixyz) && != GetPlayerVehicleID(playerid))
        {
            
dist GetPlayerDistanceFromPoint(playeridxyz);
            if(
dist closedist)
            {
                
found 1;
                
closedist dist;
                
closeveh i;
            }
        }
    }
    if(
found == 1) return closeveh;
    return 
0;