SA-MP Forums Archive
How to check Is player near vehicle bonnet/boot? - 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: How to check Is player near vehicle bonnet/boot? (/showthread.php?tid=308608)



How to check Is player near vehicle bonnet/boot? - zgintasz - 04.01.2012

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!


Re: How to check Is player near vehicle bonnet/boot? - Joe_ - 04.01.2012

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



Re: How to check Is player near vehicle bonnet/boot? - Jochemd - 04.01.2012

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


Re: How to check Is player near vehicle bonnet/boot? - Joe_ - 04.01.2012

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


Re: How to check Is player near vehicle bonnet/boot? - zgintasz - 04.01.2012

Okay, thanks


Re: How to check Is player near vehicle bonnet/boot? - bvdb1995 - 01.07.2012

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.


Re: How to check Is player near vehicle bonnet/boot? - MP2 - 01.07.2012

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.


Re: How to check Is player near vehicle bonnet/boot? - PaulDinam - 01.07.2012

Код:
  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++;
			        }
			    }



Re: How to check Is player near vehicle bonnet/boot? - Xenforox - 27.04.2014

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?