Skip to content

Commit da682f2

Browse files
Synchronize changes from 1.6 master branch [ci skip]
7be6d05 Add seat parameter to `setPedEnterVehicle` (#4573) d061e11 Visual Studio Update
2 parents 3bb13a4 + 7be6d05 commit da682f2

7 files changed

Lines changed: 67 additions & 46 deletions

File tree

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6530,25 +6530,19 @@ void CClientPed::UpdateStreamPosition(const CVector& vecInPosition)
65306530
// Asks server for permission to start entering vehicle
65316531
//
65326532
//////////////////////////////////////////////////////////////////
6533-
bool CClientPed::EnterVehicle(CClientVehicle* pVehicle, bool bPassenger)
6533+
bool CClientPed::EnterVehicle(CClientVehicle* pVehicle, bool bPassenger, std::optional<unsigned int> optSeat)
65346534
{
65356535
// Are we local player or ped we are syncing
65366536
if (!IsSyncing() && !IsLocalPlayer() && !IsLocalEntity())
6537-
{
65386537
return false;
6539-
}
65406538

65416539
// Are we already inside a vehicle
65426540
if (GetOccupiedVehicle())
6543-
{
65446541
return false;
6545-
}
65466542

65476543
// We dead or in water?
65486544
if (IsDead())
6549-
{
65506545
return false;
6551-
}
65526546

65536547
// Are we already sending an in/out request or not allowed to create a new in/out?
65546548
if (m_bNoNewVehicleTask // Are we permitted to even enter a vehicle?
@@ -6567,9 +6561,7 @@ bool CClientPed::EnterVehicle(CClientVehicle* pVehicle, bool bPassenger)
65676561

65686562
// Streamed?
65696563
if (!m_pPlayerPed)
6570-
{
65716564
return false;
6572-
}
65736565

65746566
unsigned int uiDoor = 0;
65756567
// Do we want to enter a specific vehicle?
@@ -6594,43 +6586,31 @@ bool CClientPed::EnterVehicle(CClientVehicle* pVehicle, bool bPassenger)
65946586

65956587
// Dead vehicle?
65966588
if (pVehicle->GetHealth() <= 0.0f)
6597-
{
65986589
return false;
6599-
}
66006590

6591+
// Stop if the vehicle is not enterable
66016592
if (!pVehicle->IsEnterable(IsLocalEntity()))
6602-
{
6603-
// Stop if the vehicle is not enterable
66046593
return false;
6605-
}
66066594

66076595
// Stop if the ped is swimming and the vehicle model cannot be entered from water (fixes #1990)
66086596
auto vehicleModel = static_cast<VehicleType>(pVehicle->GetModel());
66096597

66106598
if (IsInWater() && !(vehicleModel == VehicleType::VT_SKIMMER || vehicleModel == VehicleType::VT_SEASPAR || vehicleModel == VehicleType::VT_LEVIATHN || vehicleModel == VehicleType::VT_VORTEX))
6611-
{
66126599
return false;
6613-
}
66146600

66156601
// If the Jump task is playing and we are in water - I know right
66166602
// Kill the task.
66176603
CTask* pTask = GetCurrentPrimaryTask();
66186604
if (pTask && pTask->GetTaskType() == TASK_COMPLEX_JUMP) // Kill jump task - breaks warp in entry and doesn't really matter
66196605
{
6620-
if (pVehicle->IsInWater() ||
6621-
IsInWater()) // Make sure we are about to warp in (this bug only happens when someone jumps into water with a vehicle)
6622-
{
6606+
if (pVehicle->IsInWater() || IsInWater()) // Make sure we are about to warp in (this bug only happens when someone jumps into water with a vehicle)
66236607
KillTask(3, true); // Kill jump task if we are about to warp in
6624-
}
66256608
}
66266609

66276610
// Make sure we don't have any other primary tasks running, otherwise our 'enter-vehicle'
66286611
// task will replace it and fuck it up!
66296612
if (GetCurrentPrimaryTask())
6630-
{
6631-
// We already have a primary task, so stop.
66326613
return false;
6633-
}
66346614

66356615
if (IsClimbing() // Make sure we're not currently climbing
66366616
|| HasJetPack() // Make sure we don't have a jetpack
@@ -6641,17 +6621,31 @@ bool CClientPed::EnterVehicle(CClientVehicle* pVehicle, bool bPassenger)
66416621
return false;
66426622
}
66436623

6644-
unsigned int uiSeat = uiDoor;
6645-
if (bPassenger && uiDoor == 0)
6624+
// Determine seat - either explicitly specified or auto-determined from door/passenger flag
6625+
unsigned int uiSeat;
6626+
6627+
if (optSeat.has_value())
66466628
{
6647-
// We're trying to enter as a passenger, yet our closest door
6648-
// is the driver's door. Force an enter for the passenger seat.
6649-
uiSeat = 1;
6629+
// Explicit seat specified
6630+
uiSeat = optSeat.value();
6631+
if (!CClientVehicleManager::IsValidSeat(pVehicle->GetModel(), static_cast<unsigned char>(uiSeat)))
6632+
return false;
66506633
}
6651-
else if (!bPassenger)
6634+
else
66526635
{
6653-
// We want to drive. Force our seat to the driver's seat.
6654-
uiSeat = 0;
6636+
// Legacy behavior - auto-determine seat from door/passenger flag
6637+
uiSeat = uiDoor;
6638+
if (bPassenger && uiDoor == 0)
6639+
{
6640+
// We're trying to enter as a passenger, yet our closest door
6641+
// is the driver's door. Force an enter for the passenger seat.
6642+
uiSeat = 1;
6643+
}
6644+
else if (!bPassenger)
6645+
{
6646+
// We want to drive. Force our seat to the driver's seat.
6647+
uiSeat = 0;
6648+
}
66556649
}
66566650

66576651
// If the vehicle's a boat, make sure we're standing on it (we need a dif task to enter boats properly)

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
609609
public:
610610
void _GetIntoVehicle(CClientVehicle* pVehicle, unsigned int uiSeat, unsigned char ucDoor);
611611
// Used to control and sync entering/exiting
612-
bool EnterVehicle(CClientVehicle* pVehicle, bool bPassenger);
612+
bool EnterVehicle(CClientVehicle* pVehicle, bool bPassenger, std::optional<unsigned int> optSeat = std::nullopt);
613613
bool ExitVehicle();
614614
void ResetVehicleInOut();
615615
void UpdateVehicleInOut();

Client/mods/deathmatch/logic/CClientVehicleManager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,24 @@ unsigned char CClientVehicleManager::GetMaxPassengerCount(unsigned long ulModel)
486486
return 0xFF;
487487
}
488488

489+
bool CClientVehicleManager::IsValidSeat(unsigned long ulModel, unsigned char ucSeat)
490+
{
491+
// Camper only has 3 seats (0-2)
492+
if (static_cast<VehicleType>(ulModel) == VehicleType::VT_CAMPER && ucSeat > 2)
493+
return false;
494+
495+
// Get the maximum passenger count for the vehicle
496+
unsigned char ucMaxPassengers = GetMaxPassengerCount(ulModel);
497+
if (ucSeat > ucMaxPassengers)
498+
return false;
499+
500+
// Vehicles with unknown passenger count (255) can only have driver in seat 0
501+
if (ucSeat > 0 && ucMaxPassengers == 255)
502+
return false;
503+
504+
return true;
505+
}
506+
489507
void CClientVehicleManager::GetRandomVariation(unsigned short usModel, unsigned char& ucVariant, unsigned char& ucVariant2)
490508
{
491509
RandomizeRandomSeed();

Client/mods/deathmatch/logic/CClientVehicleManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CClientVehicleManager
5050
static bool HasDamageModel(unsigned long ulModel);
5151
static bool HasDamageModel(enum eClientVehicleType Type);
5252
static bool HasDoors(unsigned long ulModel);
53+
static bool IsValidSeat(unsigned long ulModel, unsigned char ucSeat);
5354

5455
bool Exists(CClientVehicle* pVehicle);
5556

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9963,8 +9963,7 @@ bool CStaticFunctionDefinitions::WarpPedIntoVehicle(CClientPed* pPed, CClientVeh
99639963
if (pPed->IsLocalEntity() != pVehicle->IsLocalEntity())
99649964
return false;
99659965

9966-
// Camper only has 3 seats (0-2)
9967-
if (static_cast<VehicleType>(pVehicle->GetModel()) == VehicleType::VT_CAMPER && uiSeat > 2)
9966+
if (!CClientVehicleManager::IsValidSeat(pVehicle->GetModel(), static_cast<unsigned char>(uiSeat)))
99689967
return false;
99699968

99709969
if (pPed->IsLocalEntity())
@@ -9977,14 +9976,6 @@ bool CStaticFunctionDefinitions::WarpPedIntoVehicle(CClientPed* pPed, CClientVeh
99779976
if (pPed->IsDead() || pVehicle->GetHealth() <= 0.0f)
99789977
return false;
99799978

9980-
// Valid seat id for that vehicle?
9981-
uchar ucMaxPassengers = CClientVehicleManager::GetMaxPassengerCount(pVehicle->GetModel());
9982-
if (uiSeat > ucMaxPassengers)
9983-
return false;
9984-
9985-
if (uiSeat > 0 && ucMaxPassengers == 255)
9986-
return false;
9987-
99889979
// Toss the previous player out of it if neccessary
99899980
if (CClientPed* pPreviousOccupant = pVehicle->GetOccupant(uiSeat))
99909981
RemovePedFromVehicle(pPreviousOccupant);

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,11 +2518,28 @@ int CLuaPedDefs::DetonateSatchels(lua_State* luaVM)
25182518
return 1;
25192519
}
25202520

2521-
bool CLuaPedDefs::SetPedEnterVehicle(CClientPed* pPed, std::optional<CClientVehicle*> pOptVehicle, std::optional<bool> bOptPassenger)
2521+
bool CLuaPedDefs::SetPedEnterVehicle(CClientPed* pPed, std::optional<CClientVehicle*> pOptVehicle, std::optional<std::variant<bool, unsigned int>> seatOrPassenger)
25222522
{
25232523
CClientVehicle* pVehicle = pOptVehicle.value_or(nullptr);
2524-
bool bPassenger = bOptPassenger.value_or(false);
2525-
return pPed->EnterVehicle(pVehicle, bPassenger);
2524+
bool bPassenger = false;
2525+
std::optional<unsigned int> optSeat;
2526+
2527+
// Parse third argument: either a bool (passenger flag) or int (seat number)
2528+
if (seatOrPassenger.has_value())
2529+
{
2530+
if (std::holds_alternative<bool>(seatOrPassenger.value()))
2531+
{
2532+
// Third argument is bool - treat as passenger flag
2533+
bPassenger = std::get<bool>(seatOrPassenger.value());
2534+
}
2535+
else if (std::holds_alternative<unsigned int>(seatOrPassenger.value()))
2536+
{
2537+
// Third argument is int - treat as seat number
2538+
optSeat = std::get<unsigned int>(seatOrPassenger.value());
2539+
}
2540+
}
2541+
2542+
return pPed->EnterVehicle(pVehicle, bPassenger, optSeat);
25262543
}
25272544

25282545
bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed)

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CLuaPedDefs : public CLuaDefs
112112
LUA_DECLARE(RemovePedFromVehicle);
113113
LUA_DECLARE(SetPedOxygenLevel);
114114
LUA_DECLARE(SetPedStat);
115-
static bool SetPedEnterVehicle(CClientPed* pPed, std::optional<CClientVehicle*> pOptVehicle, std::optional<bool> bOptPassenger);
115+
static bool SetPedEnterVehicle(CClientPed* pPed, std::optional<CClientVehicle*> pOptVehicle, std::optional<std::variant<bool, unsigned int>> seatOrPassenger);
116116
static bool SetPedExitVehicle(CClientPed* pPed);
117117
static bool IsPedBleeding(CClientPed* ped);
118118
static bool SetPedBleeding(CClientPed* ped, bool bleeding);

0 commit comments

Comments
 (0)