See if a player is near to the driver's door or the passenger door
#1

How can i see if a player is near to the driver's door or the passenger door?
Reply
#2

https://sampwiki.blast.hk/wiki/GetVehicleModelInfo
Reply
#3

Quote:
Originally Posted by Mionee
Посмотреть сообщение
This function doesn't detect the position of the driver's door or the passenger.
Reply
#4

https://sampwiki.blast.hk/wiki/Vehicle_information_types

Код:
VEHICLE_MODEL_INFO_FRONTSEAT       // Position of the front seat*
VEHICLE_MODEL_INFO_REARSEAT        // Position of the rear seat*
Reply
#5

Quote:
Originally Posted by Mionee
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Vehicle_information_types

Код:
VEHICLE_MODEL_INFO_FRONTSEAT       // Position of the front seat*
VEHICLE_MODEL_INFO_REARSEAT        // Position of the rear seat*
For detect the position of the driver i need use VEHICLE_MODEL_INFO_FRONTSEAT and change the position of the axis y?
Reply
#6

Yes, just experiment with it.

There may be better ways though, you should wait another day or two for a more constructive reply before actually going with what I suggested.
Reply
#7

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Yes, just experiment with it.

There may be better ways though, you should wait another day or two for a more constructive reply before actually going with what I suggested.
I tried but don't work, how can i do?
Reply
#8

https://sampforum.blast.hk/showthread.php?tid=529324

This is a thread that I posted in where a guy needed a function that got the position in front of each tire.

You should use this function made by Mauzen to start:
pawn Код:
stock GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff= 0.0, Float:yoff= 0.0, Float:zoff= 0.0)
{
    new Float:rot;
    GetVehicleZAngle(vehicleid, rot);
    rot = 360 - rot;
    GetVehiclePos(vehicleid, x, y, z);
    x = floatsin(rot, degrees) * yoff + floatcos(rot, degrees) * xoff + x;
    y = floatcos(rot, degrees) * yoff - floatsin(rot, degrees) * xoff + y;
    z = zoff + z;
}
You could then modify the code to find the position at the doors, rather than at the tires.

pawn Код:
new Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2;
   
//For the front left tyre:
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSFRONT, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, -x - 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the front right tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSFRONT, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, x + 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the Back left tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSREAR, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, -x - 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the Back right tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSREAR, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, x + 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);
I don't have the time right now, but I want to be able to test the correct code before I give it to you. So please don't expect me to give you a complete code within the next few hours, it will be at least another 8-10 hours before I return home.
Reply
#9

Alright - what he suggested was:

If you already know the vehicleid - you can calculate the position of both front passenger seat and driver seat from the center position of the vehicle. Let's imagine a car:
Код:
O------O
| D  FS|
|      |
|   C  |
|      |
|  BS  |
O-------O
C here is the center of a car
D is driver's seat
FS - Front Seat & BS - Back Seat

All of these are calculated from the center of the car, meaning that if you find the position of the vehicle - you can easily get the position of the seats if you just add [FS] and [D] to the position of the car.

Once you get the positions - you can use vector-distance formula.
D = sqr( (x2-x1)^2 + (y2-y1)^2)

which allows you to get the distance of the player to a seat.

After storing and comparing the distances - you can find which one is smaller which means that's the seat to which the player is closer...


P.S. This might be a little bit confusing - please feel free to ask whichever part you might not have understood
Reply
#10

Quote:
Originally Posted by Threshold
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=529324

This is a thread that I posted in where a guy needed a function that got the position in front of each tire.

You should use this function made by Mauzen to start:
pawn Код:
stock GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff= 0.0, Float:yoff= 0.0, Float:zoff= 0.0)
{
    new Float:rot;
    GetVehicleZAngle(vehicleid, rot);
    rot = 360 - rot;
    GetVehiclePos(vehicleid, x, y, z);
    x = floatsin(rot, degrees) * yoff + floatcos(rot, degrees) * xoff + x;
    y = floatcos(rot, degrees) * yoff - floatsin(rot, degrees) * xoff + y;
    z = zoff + z;
}
You could then modify the code to find the position at the doors, rather than at the tires.

pawn Код:
new Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2;
   
//For the front left tyre:
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSFRONT, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, -x - 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the front right tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSFRONT, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, x + 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the Back left tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSREAR, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, -x - 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);

//For the Back right tyre...
    GetVehicleModelInfo(GetVehicleModel(veh), VEHICLE_MODEL_INFO_WHEELSREAR, x, y, z);
    GetVehicleRelativePos(veh, x2, y2, z2, x + 0.5, y, z);
    SetPlayerCheckpoint(playerid, x2, y2, z2, 0.5);
I don't have the time right now, but I want to be able to test the correct code before I give it to you. So please don't expect me to give you a complete code within the next few hours, it will be at least another 8-10 hours before I return home.
Thank you, i have solved the problem with the function "GetVehicleRelativePos", REP+.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)