openmultiplayer / open.mp

Open Multiplayer, a multiplayer mod fully backwards compatible with SA-MP
https://open.mp
Mozilla Public License 2.0
423 stars 78 forks source link

PutPlayerInVehicle Desync #910

Open denisbranisteanu opened 3 months ago

denisbranisteanu commented 3 months ago

Describe the bug After applying PutPlayerInVehicle to a player who is currently driving any vehicle, the player will still appear to other players as the driver of the original vehicle after the function executes. Meanwhile, the original vehicle will begin moving as if it were being controlled by the player, alongside the new vehicle.

To Reproduce Steps to reproduce the behavior:

  1. Spawn a vehicle and get inside it as the driver.
  2. Spawn another vehicle and use the PutPlayerInVehicle function for the driver's seat.

Expected behavior To synchronize with all players that the player has been teleported to a new vehicle.

Screenshots and/or logs https://youtu.be/z_WwqUj2_0I

Release version open.mp 1.2.0.2670 (W)

Script for testing

// In order to get the front position of the vehicle, use this function
stock Vehicle_GetRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff = 0.0, Float:yoff = 0.0, Float:zoff = 0.0)
{
    if(!IsValidVehicle(vehicleid))
        return INVALID_VEHICLE_ID;

    new Float: angle;
    GetVehicleZAngle(vehicleid, angle);

    angle = 360 - angle;
    GetVehiclePos(vehicleid, x, y, z);

    x = floatsin(angle, degrees) * yoff + floatcos(angle, degrees) * xoff + x;
    y = floatcos(angle, degrees) * yoff - floatsin(angle, degrees) * xoff + y;
    z = zoff + z;
    return 1;
}

// Command to test the bug
@command() testcommand(playerid, params[], help)
{
    new Float:x,
        Float:y,
        Float:z,
        Float:rotation;

    if(IsPlayerInAnyVehicle(playerid))
    {
        Vehicle_GetRelativePos(GetPlayerVehicleID(playerid), x, y, z, 0.0, 10.00);
        GetVehicleZAngle(GetPlayerVehicleID(playerid), rotation);
    }
    else
    {
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, rotation);
    }

    // After getting new coordinates, we will create a vehicle
    // and if player is already in a vehicle, we will teleport it
    // from the old car to the new car

    // From DRIVER state to DRIVER state

    new carid = CreateVehicle(411, x, y, z, rotation, -1, -1, -1);
    PutPlayerInVehicle(playerid, carid, 0);

    // Turn on the engine
    SetVehicleParamsEx(carid, true, false, false, false, false, false, false);
    return 1;
}
LDami commented 2 months ago

It is probably a client issue, I can reproduce the issue on a SA-MP server. We can also experience it while spectating a player: https://www.youtube.com/watch?v=USeWnlcpbFg