Skip to content

Commit d7c86a6

Browse files
committed
2 parents f1c2a22 + 679199e commit d7c86a6

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
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
{

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include "packets/CConsoleEchoPacket.h"
6767
#include "packets/CChatClearPacket.h"
6868
#include "packets/CElementRPCPacket.h"
69+
#include "packets/CVehicleInOutPacket.h"
6970
#include "version.h"
7071
#include <net/rpc_enums.h>
7172

@@ -4352,6 +4353,28 @@ bool CStaticFunctionDefinitions::RemovePedFromVehicle(CElement* pElement)
43524353
auto ucOccupiedSeat = static_cast<unsigned char>(pPed->GetOccupiedVehicleSeat());
43534354
if (pVehicle)
43544355
{
4356+
unsigned int uiVehicleAction = pPed->GetVehicleAction();
4357+
4358+
// Handle mid-enter/exit states
4359+
if (uiVehicleAction == CPed::VEHICLEACTION_ENTERING || uiVehicleAction == CPed::VEHICLEACTION_JACKING)
4360+
{
4361+
pVehicle->SetOccupant(nullptr, ucOccupiedSeat);
4362+
pPed->SetOccupiedVehicle(nullptr, 0);
4363+
pPed->SetVehicleAction(CPed::VEHICLEACTION_NONE);
4364+
4365+
if (uiVehicleAction == CPed::VEHICLEACTION_JACKING)
4366+
pPed->SetJackingVehicle(nullptr);
4367+
4368+
// Clean up client handshake
4369+
if (IS_PLAYER(pPed))
4370+
{
4371+
CVehicleInOutPacket Reply(pPed->GetID(), pVehicle->GetID(), ucOccupiedSeat, CGame::VEHICLE_NOTIFY_IN_ABORT_RETURN);
4372+
m_pPlayerManager->BroadcastOnlyJoined(Reply);
4373+
}
4374+
4375+
return true;
4376+
}
4377+
43554378
CLuaArguments Arguments;
43564379
Arguments.PushElement(pVehicle); // vehicle
43574380
Arguments.PushNumber(ucOccupiedSeat); // seat
@@ -4371,8 +4394,8 @@ bool CStaticFunctionDefinitions::RemovePedFromVehicle(CElement* pElement)
43714394
pVehicle->CallEvent("onVehicleExit", Arguments2);
43724395

43734396
// Remove him from the vehicle
4374-
pVehicle->SetOccupant(NULL, ucOccupiedSeat);
4375-
pPed->SetOccupiedVehicle(NULL, 0);
4397+
pVehicle->SetOccupant(nullptr, ucOccupiedSeat);
4398+
pPed->SetOccupiedVehicle(nullptr, 0);
43764399
pPed->SetVehicleAction(CPed::VEHICLEACTION_NONE);
43774400

43784401
// Tell the players

0 commit comments

Comments
 (0)