diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index ab48ed872f..4c26e90da0 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -127,7 +127,7 @@ void CClientPed::Init(CClientManager* pManager, unsigned long ulModelID, bool bI m_pTaskManager = NULL; m_pOccupiedVehicle = NULL; m_pOccupyingVehicle = NULL; - // m_uiOccupyingSeat = 0; + m_uiOccupyingSeat = 0; m_uiOccupiedVehicleSeat = 0xFF; m_bHealthLocked = false; m_bDontChangeRadio = false; @@ -1464,7 +1464,7 @@ void CClientPed::WarpIntoVehicle(CClientVehicle* pVehicle, unsigned int uiSeat) CClientVehicle* pPrevVehicle = GetRealOccupiedVehicle(); // Eventually remove us from a previous vehicle RemoveFromVehicle(); - // m_uiOccupyingSeat = uiSeat; + m_uiOccupyingSeat = uiSeat; m_bForceGettingIn = false; m_bForceGettingOut = false; m_ucLeavingDoor = 0xFF; @@ -7275,3 +7275,15 @@ void CClientPed::RunSwimTask() const inWaterTask->SetAsPedTask(m_pPlayerPed, TASK_PRIORITY_EVENT_RESPONSE_NONTEMP, true); } + +bool CClientPed::IsEnteringToVehicle() +{ + int inOutState = GetVehicleInOutState(); + return inOutState == VEHICLE_INOUT_GETTING_IN || inOutState == VEHICLE_INOUT_JACKING; +} + +bool CClientPed::IsExitingFromVehicle() +{ + int inOutState = GetVehicleInOutState(); + return inOutState == VEHICLE_INOUT_GETTING_OUT || inOutState == VEHICLE_INOUT_GETTING_JACKED; +} diff --git a/Client/mods/deathmatch/logic/CClientPed.h b/Client/mods/deathmatch/logic/CClientPed.h index 8bab35d984..045f523860 100644 --- a/Client/mods/deathmatch/logic/CClientPed.h +++ b/Client/mods/deathmatch/logic/CClientPed.h @@ -254,6 +254,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule CClientVehicle* GetOccupyingVehicle() noexcept { return m_pOccupyingVehicle; }; const CClientVehicle* GetOccupyingVehicle() const noexcept { return m_pOccupyingVehicle; }; + unsigned int GetOccupyingVehicleSeat() const noexcept { return m_uiOccupyingSeat; }; + CClientVehicle* GetRealOccupiedVehicle(); CClientVehicle* GetClosestEnterableVehicle(bool bGetPositionFromClosestDoor, bool bCheckDriverDoor, bool bCheckPassengerDoors, bool bCheckStreamedOutVehicles, unsigned int* uiClosestDoor = NULL, CVector* pClosestDoorPosition = NULL, @@ -267,6 +269,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule void WarpIntoVehicle(CClientVehicle* pVehicle, unsigned int uiSeat = 0); CClientVehicle* RemoveFromVehicle(bool bIgnoreIfGettingOut = false); + bool IsEnteringToVehicle(); + bool IsExitingFromVehicle(); + bool IsVisible(); void SetVisible(bool bVisible); bool GetUsesCollision(); @@ -640,16 +645,16 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule unsigned long m_ulLastOnScreenTime; CClientVehiclePtr m_pOccupiedVehicle; CClientVehiclePtr m_pOccupyingVehicle; - // unsigned int m_uiOccupyingSeat; - unsigned int m_uiOccupiedVehicleSeat; - bool m_bForceGettingIn; - bool m_bForceGettingOut; - CShotSyncData* m_shotSyncData; - CStatsData* m_stats; - CControllerState* m_currentControllerState; - CControllerState* m_lastControllerState; - CControllerState m_rawControllerState; // copy of lastControllerState before CClientPed::ApplyControllerStateFixes is applied (modifies states to - // prevent stuff like rapid input glitch) + unsigned int m_uiOccupyingSeat; + unsigned int m_uiOccupiedVehicleSeat; + bool m_bForceGettingIn; + bool m_bForceGettingOut; + CShotSyncData* m_shotSyncData; + CStatsData* m_stats; + CControllerState* m_currentControllerState; + CControllerState* m_lastControllerState; + CControllerState m_rawControllerState; // copy of lastControllerState before CClientPed::ApplyControllerStateFixes is applied (modifies states to + // prevent stuff like rapid input glitch) CRemoteDataStorage* m_remoteDataStorage; unsigned long m_ulLastTimeFired; unsigned long m_ulLastTimeBeganAiming; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 7fae5985ac..33027a83fc 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -4143,8 +4143,7 @@ void CClientVehicle::SetPedOccupyingVehicle(CClientPed* pClientPed, CClientVehic // Ped vars pClientPed->m_pOccupyingVehicle = pVehicle; - // if ( uiSeat >= 0 && uiSeat < 8 ) - // pClientPed->m_uiOccupyingSeat = uiSeat; + pClientPed->m_uiOccupyingSeat = uiSeat; if (ucDoor != 0xFF) pVehicle->AllowDoorRatioSetting(ucDoor, false); @@ -4270,7 +4269,7 @@ void CClientVehicle::UnpairPedAndVehicle(CClientPed* pClientPed, CClientVehicle* { INFO(("UnpairPedAndVehicle: pClientPed:%s from m_pOccupyingVehicle:0x%08x", GetPlayerName(pClientPed).c_str(), pVehicle)); pClientPed->m_pOccupyingVehicle = NULL; - // pClientPed->m_uiOccupyingSeat = 0xFF; + pClientPed->m_uiOccupyingSeat = NULL; } } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 450214d624..e366d14fc4 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -104,6 +104,11 @@ void CLuaPedDefs::LoadFunctions() {"getPedTotalAmmo", GetPedTotalAmmo}, {"getPedOccupiedVehicle", GetPedOccupiedVehicle}, {"getPedOccupiedVehicleSeat", GetPedOccupiedVehicleSeat}, + {"isPedEnteringToVehicle", ArgumentParser}, + {"isPedExitingFromVehicle", ArgumentParser}, + {"getPedVehicleEnteringTo", ArgumentParser}, + {"getPedVehicleEnteringToSeat", ArgumentParser}, + {"getPedBonePosition", GetPedBonePosition}, {"getPedClothes", GetPedClothes}, {"getPedMoveState", GetPedMoveState}, @@ -155,6 +160,8 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getMoveState", "getPedMoveState"); lua_classfunction(luaVM, "getOccupiedVehicle", "getPedOccupiedVehicle"); lua_classfunction(luaVM, "getOccupiedVehicleSeat", "getPedOccupiedVehicleSeat"); + lua_classfunction(luaVM, "getVehicleEnteringTo", "getPedVehicleEnteringTo"); + lua_classfunction(luaVM, "getVehicleEnteringToSeat", "getPedVehicleEnteringToSeat"); lua_classfunction(luaVM, "getOxygenLevel", "getPedOxygenLevel"); lua_classfunction(luaVM, "getStat", "getPedStat"); lua_classfunction(luaVM, "getTarget", "getPedTarget"); @@ -213,6 +220,8 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setExitVehicle", "setPedExitVehicle"); lua_classfunction(luaVM, "setBleeding", "setPedBleeding"); lua_classfunction(luaVM, "playVoiceLine", "playPedVoiceLine"); + lua_classfunction(luaVM, "isEnteringToVehicle", "isPedEnteringToVehicle"); + lua_classfunction(luaVM, "isExitingFromVehicle", "isPedExitingFromVehicle"); lua_classvariable(luaVM, "vehicle", OOP_WarpPedIntoVehicle, GetPedOccupiedVehicle); lua_classvariable(luaVM, "vehicleSeat", NULL, "getPedOccupiedVehicleSeat"); @@ -232,6 +241,10 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "ducked", NULL, "isPedDucked"); lua_classvariable(luaVM, "headless", "setPedHeadless", "isPedHeadless"); lua_classvariable(luaVM, "inVehicle", NULL, "isPedInVehicle"); + lua_classvariable(luaVM, "enteringToVehicle", NULL, "isPedEnteringToVehicle"); + lua_classvariable(luaVM, "exitingFromVehicle", NULL, "isPedExitingFromVehicle"); + lua_classvariable(luaVM, "vehicleEnteringTo", NULL, "getPedVehicleEnteringTo"); + lua_classvariable(luaVM, "vehicleEnteringToSeat", NULL, "getPedVehicleEnteringToSeat"); lua_classvariable(luaVM, "onFire", "setPedOnFire", "isPedOnFire"); lua_classvariable(luaVM, "onGround", NULL, "isPedOnGround"); lua_classvariable(luaVM, "dead", NULL, "isPedDead"); @@ -2585,3 +2598,23 @@ void CLuaPedDefs::PlayPedVoiceLine(CClientPed* ped, int speechId, std::optional< ped->Say(speechContextId, probability.value_or(1.0f)); } + +bool CLuaPedDefs::IsPedEnteringToVehicle(CClientPed* const ped) noexcept +{ + return ped->IsEnteringToVehicle(); +} + +bool CLuaPedDefs::IsPedExitingFromVehicle(CClientPed* const ped) noexcept +{ + return ped->IsExitingFromVehicle(); +} + +CClientVehicle* CLuaPedDefs::GetPedVehicleEnteringTo(CClientPed* const ped) +{ + return ped->GetOccupyingVehicle(); +} + +int CLuaPedDefs::GetPedVehicleEnteringToSeat(CClientPed* const ped) +{ + return ped->GetOccupyingVehicleSeat(); +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 8f9e386bf8..e6a4e610d3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -119,5 +119,9 @@ class CLuaPedDefs : public CLuaDefs static bool killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully); - static void PlayPedVoiceLine(CClientPed* ped, int speechId, std::optional probability); + static void PlayPedVoiceLine(CClientPed* ped, int speechId, std::optional probability); + static bool IsPedEnteringToVehicle(CClientPed* const ped) noexcept; + static bool IsPedExitingFromVehicle(CClientPed* const ped) noexcept; + static CClientVehicle* GetPedVehicleEnteringTo(CClientPed* const ped); + static int GetPedVehicleEnteringToSeat(CClientPed* const ped); }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 135e5a4e9a..6b96b6db9b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -48,6 +48,8 @@ void CLuaPedDefs::LoadFunctions() {"getPedOccupiedVehicle", GetPedOccupiedVehicle}, {"getPedOccupiedVehicleSeat", GetPedOccupiedVehicleSeat}, {"isPedInVehicle", IsPedInVehicle}, + {"isPedEnteringToVehicle", ArgumentParser}, + {"isPedExitingFromVehicle", ArgumentParser}, {"isPedReloadingWeapon", ArgumentParser}, // Ped set functions @@ -120,6 +122,8 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "isHeadless", "isPedHeadless"); lua_classfunction(luaVM, "isWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13846 lua_classfunction(luaVM, "isReloadingWeapon", "isPedReloadingWeapon"); + lua_classfunction(luaVM, "isEnteringToVehicle", "isPedEnteringToVehicle"); + lua_classfunction(luaVM, "isExitingFromVehicle", "isPedExitingFromVehicle"); lua_classfunction(luaVM, "getArmor", "getPedArmor"); lua_classfunction(luaVM, "getFightingStyle", "getPedFightingStyle"); @@ -153,6 +157,8 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setWearingJetpack", "setPedWearingJetpack"); // introduced in 1.5.5-9.13846 lua_classvariable(luaVM, "inVehicle", NULL, "isPedInVehicle"); + lua_classvariable(luaVM, "enteringToVehicle", NULL, "isPedEnteringToVehicle"); + lua_classvariable(luaVM, "exitingFromVehicle", NULL, "isPedExitingFromVehicle"); lua_classvariable(luaVM, "ducked", NULL, "isPedDucked"); lua_classvariable(luaVM, "inWater", NULL, "isPedInWater"); lua_classvariable(luaVM, "onGround", NULL, "isPedOnGround"); @@ -1557,3 +1563,13 @@ int CLuaPedDefs::TakeAllWeapons(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + +bool CLuaPedDefs::IsPedEnteringToVehicle(CPed* const ped) noexcept +{ + return ped->GetVehicleAction() == CPed::VEHICLEACTION_ENTERING; +} + +bool CLuaPedDefs::IsPedExitingFromVehicle(CPed* const ped) noexcept +{ + return ped->GetVehicleAction() == CPed::VEHICLEACTION_EXITING; +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index ad935649a5..b36d3fa250 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -51,6 +51,8 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(GetPedOccupiedVehicle); LUA_DECLARE(GetPedOccupiedVehicleSeat); LUA_DECLARE(IsPedInVehicle); + static bool IsPedEnteringToVehicle(CPed* const ped) noexcept; + static bool IsPedExitingFromVehicle(CPed* const ped) noexcept; LUA_DECLARE(GetPedAmmoInClip); LUA_DECLARE(GetPedTotalAmmo); static bool IsPedReloadingWeapon(CPed* const ped) noexcept;