From 52a06cc83be1cd46237d329f15801c3eaf39052c Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 28 Jan 2018 22:53:27 +0200 Subject: [PATCH] Add a method to the vehicle entity class to check if a certain slot has an occupant. --- source/Entity/Vehicle.cpp | 14 ++++++++++++++ source/Entity/Vehicle.hpp | 5 +++++ 2 files changed, 19 insertions(+) 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. */