SA-MP Forums Archive
Isplayernearavehicle ? +REP - 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: Isplayernearavehicle ? +REP (/showthread.php?tid=602067)



Isplayernearavehicle ? +REP - xEF - 01.03.2016

I am searching for a stock or just functions; when a player is near a vehicle, and that vehicle near him is owned by this near player, nearanownvehicle[playerid]=1;
and when the player obviously go away it back to [playerid]=0;

Thanks to all that will think on that.
Regards,
Rodri.


Re: Isplayernearavehicle ? +REP - [NWA]Hannes - 01.03.2016

First of all, add the following code at the top of your script with your other declarations:
pawn Code:
native IsValidVehicle(vehicleid);
Here is my extremely inefficient function that loops through all vehicles and checks if playerid is close to any, you'll have to change one row and insert your own function, where playerid is the player that owns the vehicle and v is the owned vehicle.

Unfortunately, it is impossible to check a vehicles interior, so you'll have to create it in the right one from the beginning with LinkVehicleToInterior.

pawn Code:
IsPlayerNearVehicle(playerid)
{
    for(new v = 0; v < MAX_VEHICLES; v++)
    {
        if(IsValidVehicle(v))
        {
            new Float:vX, Float:vY, Float:vZ;
            GetVehiclePos(v, vX, vY, vZ);

            if(IsPlayerInRange(playerid, 5.0, vX, vY, vZ) && InsertYourFunctionHere[playerid][v] == 1) return 1;
        }
    }
    return 0;
}



Re: Isplayernearavehicle ? +REP - CodeStyle175 - 01.03.2016

It all depends, what type of vehicle system you have there, good or bad.
PHP Code:
#define max_cars 50
IsPlyNearOwnVeh(pid){
    new 
Float:p[3];
    
GetPlayerPos(pid,p[0],p[1],p[2]);
    for(new 
imax_carsi++){
        if( !
Veh[i][slot] || Veh[i][Owner]!=User[pid][sid] || GetVehicleDistanceFromPoint(Veh[i][slot],p[0],p[1],p[2]) > )continue;
        return 
1
    
}
    return 
0;




Re: Isplayernearavehicle ? +REP - [NWA]Hannes - 01.03.2016

Apologies, I meant IsPlayerInRangeOfPoint in my above message.


Re: Isplayernearavehicle ? +REP - Vince - 01.03.2016

First use GetVehiclePoolSize() to determine the highest vehicle id to cut down on iterations. Then also use IsVehicleStreamedIn() to weed out any non-streamed vehicles.