openmultiplayer / openmultiplayer/open.mp

PutPlayerInVehicle Desync

Open
#910 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
641
Forks
208
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied reproduction script with PutPlayerInVehicle, then trace that entry point and the player/vehicle synchronization path. Confirm the behavior with two players: after moving the driver, all clients should see the player in the new vehicle, and the original vehicle should no longer move as if controlled by that player.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.