Checking if a player is close to car.
#1

Okay so, I know how to check if a player is in a certain radius to a certain location, but how can I make that a command is only availeble when the player is at a certain car?

With "certain car" it has to be at one car model, so any car model of the SFPD cruiser.

Thanks,
Reply
#2

Try using:
pawn Код:
stock GetClosestVehicle(playerid, Float:dis)
{
    new Float:X, Float:Y, Float:Z;
    if(GetPlayerPos(playerid, X, Y, Z))
    {
        new vehicleid = INVALID_VEHICLE_ID;
        for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
        {
            if(GetVehiclePos(v, VX, VY, VZ))
            {
                VX -= X, VY -= Y, VZ -= Z;
                temp = VX * VX + VY * VY + VZ * VZ;
                if(temp < dis) dis = temp, vehicleid = v;
            }
        }
        dis = floatpower(dis, 0.5);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}
Adjust to suit your needs.
Reply
#3

Thanks.

What do I add in the actually command?
Reply
#4

By that, GetClosestVehicle I got already in my script.

pawn Код:
stock GetClosestVehicle(playerid)
{
    if(IsPlayerConnected(playerid) && IsVehicleConnected(0))
    {
        new closestvehicle=0;
        new Float:closestdist=GetDistanceToVehicle(playerid,0);
        for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++)
        {
            new Float:dist = GetDistanceToVehicle(playerid,vehicleid);
            if ((dist < closestdist))
            {
                closestdist = dist;
                closestvehicle = vehicleid;
            }
        }
        return closestvehicle;
    }
    return -1;
}
Reply
#5

Third page bump
Reply
#6

https://sampwiki.blast.hk/wiki/GetVehicleModel
Reply
#7

I need to check if the player is CLOSE TO a vehicle, not if he's inside of it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)