diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index 8676bfca..6e090b64 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -287,6 +287,19 @@ Int32 CVehicle::GetOccupantID(Int32 slot) const return _Func->GetVehicleOccupant(m_ID, slot); } +// ------------------------------------------------------------------------------------------------ +bool CVehicle::HasOccupant(Int32 slot) const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + const Int32 id = _Func->GetVehicleOccupant(m_ID, slot); + // Use the server errors to see if there was an occupant + const vcmpError err = _Func->GetLastError(); + // Return whether there was no error and the returned ID is valid + return (err == vcmpErrorNone) && INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL); +} + // ------------------------------------------------------------------------------------------------ void CVehicle::Respawn() const { @@ -1976,6 +1989,7 @@ void Register_CVehicle(HSQUIRRELVM vm) .Func(_SC("SetOptionEx"), &CVehicle::SetOptionEx) .Func(_SC("Occupant"), &CVehicle::GetOccupant) .Func(_SC("OccupantID"), &CVehicle::GetOccupantID) + .Func(_SC("HasOccupant"), &CVehicle::HasOccupant) .Func(_SC("Respawn"), &CVehicle::Respawn) .Func(_SC("Explode"), &CVehicle::Explode) .Func(_SC("SetRot"), &CVehicle::SetRotationEx) diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp index 1e34a47c..e9182872 100644 --- a/source/Entity/Vehicle.hpp +++ b/source/Entity/Vehicle.hpp @@ -242,6 +242,11 @@ public: */ Int32 GetOccupantID(Int32 slot) const; + /* -------------------------------------------------------------------------------------------- + * See whether the managed vehicle entity has an occupant in a certain slot. + */ + bool HasOccupant(Int32 slot) const; + /* -------------------------------------------------------------------------------------------- * Respawn the managed vehicle entity. */