Skip to content

Add seat parameter to setPedEnterVehicle#4573

Merged
qaisjp merged 7 commits intomultitheftauto:masterfrom
MohabCodeX:feature/setpedentervehicle-seat-parameter
Jan 10, 2026
Merged

Add seat parameter to setPedEnterVehicle#4573
qaisjp merged 7 commits intomultitheftauto:masterfrom
MohabCodeX:feature/setpedentervehicle-seat-parameter

Conversation

@MohabCodeX
Copy link
Contributor

This PR adds an optional seat parameter to setPedEnterVehicle.

The implementation reuses the existing seat validation logic from warpPedIntoVehicle.
When a seat is specified, it validates that:

  • The seat number doesn't exceed the vehicle's maximum passenger count
  • The vehicle model supports passengers (some models return 255 for invalid passenger counts)

Syntax:

bool setPedEnterVehicle ( ped thePed [, vehicle theVehicle = nil, bool passenger = false, int seat = nil ] )

Optional Arguments:

  • theVehicle: The vehicle to enter. If not specified, the ped will enter the nearest vehicle
  • passenger: If set to true and no seat is specified, the ped will enter as a passenger
  • seat: The seat number to enter (0-8). If specified, this overrides the passenger parameter

Note

The seat parameter takes priority over the passenger parameter.

Examples:

-- Enter driver seat
setPedEnterVehicle(ped, vehicle, false)

-- Enter as passenger (auto-determines seat)
setPedEnterVehicle(ped, vehicle, true)

-- Enter specific seats
setPedEnterVehicle(ped, vehicle, nil, 0)  -- Driver seat
setPedEnterVehicle(ped, vehicle, nil, 1)  -- Front passenger
setPedEnterVehicle(ped, vehicle, nil, 2)  
2025-11-23.15-13-33.2.mp4

Testing

hit.zip

@FileEX FileEX added the enhancement New feature or request label Nov 23, 2025
@qaisjp
Copy link
Member

qaisjp commented Jan 6, 2026

This is really cool. Great pull request description too.

What do you think about just letting an int be provided as the third argument? I think this would be cleaner and remove the need for a dummy/unused argument.

You should be able to use a std::variant to achieve this, as demonstrated here:

bool CLuaColShapeDefs::SetColPolygonHeight(CColShape* shape, std::variant<bool, float> floor, std::variant<bool, float> ceil)
{
if (shape->GetShapeType() != COLSHAPE_POLYGON)
{
throw std::invalid_argument("Shape must be a polygon");
}
auto* polygon = static_cast<CColPolygon*>(shape);
float lowest = std::holds_alternative<bool>(floor) ? std::numeric_limits<float>::lowest() : std::get<float>(floor);
float highest = std::holds_alternative<bool>(ceil) ? std::numeric_limits<float>::max() : std::get<float>(ceil);
if (lowest > highest)
{
std::swap(lowest, highest);
}
return CStaticFunctionDefinitions::SetColPolygonHeight(polygon, lowest, highest);
}

Comment on lines 6629 to 6637
// Explicit seat specified - validate it (reuse validation logic from warpPedIntoVehicle)
uiSeat = optSeat.value();
const unsigned char ucMaxPassengers = CClientVehicleManager::GetMaxPassengerCount(pVehicle->GetModel());

if (uiSeat > ucMaxPassengers)
return false;

if (uiSeat > 0 && ucMaxPassengers == 255)
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is copied from the warpPedIntoVehicle method, then I think it'd make sense to extract to a function that can be used by both. E.g. IsValidSeat

@MohabCodeX MohabCodeX requested a review from a team as a code owner January 8, 2026 20:53
@MegadreamsBE MegadreamsBE requested a review from qaisjp January 8, 2026 22:59
Copy link
Member

@qaisjp qaisjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, thanks for contributing this.

Comment on lines +491 to +493
// Camper only has 3 seats (0-2)
if (static_cast<VehicleType>(ulModel) == VehicleType::VT_CAMPER && ucSeat > 2)
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is a special case not accounted for by GetMaxPassengerCount but I won't argue with it since it was there before 😆

@qaisjp
Copy link
Member

qaisjp commented Jan 10, 2026

I'm moderately confident in this change, so I'm going to let this merge into 1.7 despite the feature freeze.

@qaisjp
Copy link
Member

qaisjp commented Jan 10, 2026

Thanks for sending this patch @MohabCodeX, you're churning out lots of great code!

@qaisjp qaisjp enabled auto-merge January 10, 2026 07:37
@qaisjp qaisjp added this pull request to the merge queue Jan 10, 2026
Merged via the queue into multitheftauto:master with commit 7be6d05 Jan 10, 2026
8 checks passed
MTABot pushed a commit that referenced this pull request Jan 10, 2026
7be6d05 Add seat parameter to `setPedEnterVehicle` (#4573)
d061e11 Visual Studio Update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants