Isplayernearavehicle ? +REP
#1

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.
Reply
#2

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;
}
Reply
#3

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;

Reply
#4

Apologies, I meant IsPlayerInRangeOfPoint in my above message.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)