How to check Is player near vehicle bonnet/boot?
#1

Hi,

How to check if player is near closest vehicle bonnet/boot(trunk)? Like in this video:
[ame="http://www.youtube.com/watch?v=FTEbk9D6x6Q"]http://www.youtube.com/watch?v=FTEbk9D6x6Q[/ame]

Thanks!
Reply
#2

itterate through all vehicles and use IsPlayerInRangeOfPoint to check if the player is near the vehicle. I don't think there is a way to check if he is near part of the vehicle specifically without making an array of offsets for each vehicle which would take forever.

Something like this:

pawn Код:
new Float:X, Float:Y, Float:Z;
for(new a = 0; a < MAX_VEHICLES; a++)
{
GetVehiclePos(a, X, Y, Z);
if(IsPlayerInRangeOfPoint(a, 4.0, X, Y, Z))
{
//he is near vehicleid a.
}
}
Reply
#3

Like Joe_ said, you can't check if a player is near a certain part of the vehicle.
Reply
#4

Yeah, but the value subracted from the Y coordinate would have to be different for every vehicle, a premier and a yosemite will have two different offsets, probably substantially more than the premier because it's longer..
Reply
#5

Okay, thanks
Reply
#6

Quote:
Originally Posted by Joe_
Посмотреть сообщение
itterate through all vehicles and use IsPlayerInRangeOfPoint to check if the player is near the vehicle. I don't think there is a way to check if he is near part of the vehicle specifically without making an array of offsets for each vehicle which would take forever.

Something like this:

pawn Код:
new Float:X, Float:Y, Float:Z;
for(new a = 0; a < MAX_VEHICLES; a++)
{
GetVehiclePos(a, X, Y, Z);
if(IsPlayerInRangeOfPoint(a, 4.0, X, Y, Z))
{
//he is near vehicleid a.
}
}
There is a way to make it but u will have to do it with bigger and smaller vehicles.
For example

pawn Код:
new Float:X, Float:Y, Float:Z;
for(new a = 0; a < MAX_VEHICLES; a++)
{
GetVehiclePos(a, X, Y, Z);
if(IsPlayerInRangeOfPoint(a, 1.0, X+5, Y, Z))
{
//he is near vehicleid a.
}
}
Now you need to be a bit away from the vehicle, place it at the trunk and it's done, the problem is not all vehicles are the same that means you have to make it for bigger and smaller vehicles.
Reply
#7

You could make use of the new GetVehicleModelInfo and the custom GetXYBehindVehicle function. This is a function I use:

pawn Код:
stock GetPosBehindVehicle(vehicleid, &Float:x, &Float:y, &Float:z, Float:offset=0.5)
{
    new Float:vehicleSize[3], Float:vehiclePos[3];
    GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, vehicleSize[0], vehicleSize[1], vehicleSize[2]);
    GetXYBehindVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1]/2)+offset);
    x = vehiclePos[0];
    y = vehiclePos[1];
    z = vehiclePos[2];
    return 1;
}

GetXYBehindVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
{
    new Float:a;
    GetVehiclePos(vehicleid, q, w, a);
    GetVehicleZAngle(vehicleid, a);
    q += (distance * -floatsin(-a, degrees));
    w += (distance * -floatcos(-a, degrees));
}
Then just check if they are in range of 1.0 unit, and it will check if they are at the back of the vehicle, not at the sides like just using IsPlayerInRangeOfPoint would do.
Reply
#8

Код:
  new counter = 0;
			    new result;
			    new plyName[MAX_PLAYER_NAME];

			    GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
			    for(new i; i != MAX_VEHICLES; i++)
			    {
			        new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
			        if(dist)
			        {
			            result = i;
			            counter++;
			        }
			    }
Reply
#9

Quote:
Originally Posted by MP2
Посмотреть сообщение
You could make use of the new GetVehicleModelInfo and the custom GetXYBehindVehicle function. This is a function I use:

pawn Код:
stock GetPosBehindVehicle(vehicleid, &Float:x, &Float:y, &Float:z, Float:offset=0.5)
{
    new Float:vehicleSize[3], Float:vehiclePos[3];
    GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, vehicleSize[0], vehicleSize[1], vehicleSize[2]);
    GetXYBehindVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1]/2)+offset);
    x = vehiclePos[0];
    y = vehiclePos[1];
    z = vehiclePos[2];
    return 1;
}

GetXYBehindVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
{
    new Float:a;
    GetVehiclePos(vehicleid, q, w, a);
    GetVehicleZAngle(vehicleid, a);
    q += (distance * -floatsin(-a, degrees));
    w += (distance * -floatcos(-a, degrees));
}
Then just check if they are in range of 1.0 unit, and it will check if they are at the back of the vehicle, not at the sides like just using IsPlayerInRangeOfPoint would do.
So to set a checkpoint behind a vehicle what should i do exactly?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)