Skip to content

Fix Client-side getVehicleOccupant returns incorrectly when a player dies #4026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,13 @@ void CClientPed::InternalSetHealth(float fHealth)
WarpIntoVehicle(pVehicle, uiVehicleSeat);
}
}
else if (m_pPlayerPed->GetHealth() > 0.0f && fHealth <= 0.0f)
{
// Remove from vehicle in MTA scope
// Fix issue GH #4017
m_vehicleWithoutPairAllowed = true;
CClientVehicle::UnpairPedAndVehicle(this);
}

// Recheck we have a ped, ReCreateModel might destroy it
if (m_pPlayerPed)
Expand Down Expand Up @@ -1957,6 +1964,11 @@ void CClientPed::Kill(eWeaponType weaponType, unsigned char ucBodypart, bool bSt
if (IsWearingGoggles())
SetWearingGoggles(false, false);

// Remove from vehicle in MTA scope
// Fix issue GH #4017
m_vehicleWithoutPairAllowed = true;
CClientVehicle::UnpairPedAndVehicle(this);

m_bDead = true;
}

Expand Down Expand Up @@ -2714,6 +2726,9 @@ void CClientPed::StreamedInPulse(bool bDoStandardPulses)
// Grab some vars here, saves getting them twice
CClientVehicle* pVehicle = GetOccupiedVehicle();

if (m_vehicleWithoutPairAllowed && (IsDead() || !GetRealOccupiedVehicle()))
m_vehicleWithoutPairAllowed = false;

// Do we have a player? (streamed in)
if (m_pPlayerPed)
{
Expand Down Expand Up @@ -7081,7 +7096,7 @@ void CClientPed::UpdateVehicleInOut()

// Jax: this was commented, re-comment if it was there for a reason (..and give the reason!)
// Are we in a vehicle we aren't supposed to be in?
if (pVehicle && !pOccupiedVehicle)
if (pVehicle && !pOccupiedVehicle && !m_vehicleWithoutPairAllowed)
{
g_pCore->GetConsole()->Print("You shouldn't be in this vehicle");
RemoveFromVehicle();
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool m_bNoNewVehicleTask; // When set, we are not allowed to initiate a new enter/exit task because we are waiting for server reply
ElementID m_NoNewVehicleTaskReasonID; // ElementID of the vehicle that we are waiting on
CClientPed* m_pGettingJackedBy; // The ped that is jacking us
bool m_vehicleWithoutPairAllowed{false}; // Means that a ped can be in a vehicle (temporarily) without being paired with it. This is used in CClientPed::Kill and SetInternalHealth

std::shared_ptr<CClientModel> m_clientModel;

Expand Down
Loading