Skip to content

Commit 679199e

Browse files
authored
Fix vehicle state desync when warpPedIntoVehicle is called during onVehicleStartExit (#4458)
Fix vehicle exit process to handle occupant changes correctly
1 parent 3ec9b5c commit 679199e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,9 @@ void CGame::Packet_Vehicle_InOut(CVehicleInOutPacket& Packet)
34173417
unsigned int occupiedSeat = pPed->GetOccupiedVehicleSeat();
34183418
if (pPed == pVehicle->GetOccupant(occupiedSeat))
34193419
{
3420+
// Reset the occupant changed flag before calling the event
3421+
pVehicle->m_bOccupantChanged = false;
3422+
34203423
// Call the exiting vehicle event
34213424
CLuaArguments Arguments;
34223425
Arguments.PushElement(pPed); // player / ped
@@ -3425,12 +3428,23 @@ void CGame::Packet_Vehicle_InOut(CVehicleInOutPacket& Packet)
34253428
Arguments.PushNumber(Packet.GetDoor()); // door being used
34263429
if (pVehicle->CallEvent("onVehicleStartExit", Arguments) && pPed->GetOccupiedVehicle() == pVehicle)
34273430
{
3428-
// Mark him as exiting the vehicle
3429-
pPed->SetVehicleAction(CPed::VEHICLEACTION_EXITING);
3431+
// Check if the occupant was changed during the event (e.g., by warpPedIntoVehicle)
3432+
if (!pVehicle->m_bOccupantChanged)
3433+
{
3434+
// Mark him as exiting the vehicle
3435+
pPed->SetVehicleAction(CPed::VEHICLEACTION_EXITING);
34303436

3431-
// Tell everyone he can start exiting the vehicle
3432-
CVehicleInOutPacket Reply(PedID, VehicleID, static_cast<unsigned char>(occupiedSeat), VEHICLE_REQUEST_OUT_CONFIRMED, Packet.GetDoor());
3433-
m_pPlayerManager->BroadcastOnlyJoined(Reply);
3437+
// Tell everyone he can start exiting the vehicle
3438+
CVehicleInOutPacket Reply(PedID, VehicleID, static_cast<unsigned char>(occupiedSeat), VEHICLE_REQUEST_OUT_CONFIRMED, Packet.GetDoor());
3439+
m_pPlayerManager->BroadcastOnlyJoined(Reply);
3440+
}
3441+
else
3442+
{
3443+
// Script interfered with the exit process
3444+
// Don't proceed with the exit, send failure response
3445+
CVehicleInOutPacket Reply(PedID, VehicleID, 0, VEHICLE_ATTEMPT_FAILED);
3446+
pPlayer->Send(Reply);
3447+
}
34343448
}
34353449
else
34363450
{

0 commit comments

Comments
 (0)