From d544f3103b99b2424ddcb4d3459a0b0fb77e7dca Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Mon, 7 Sep 2020 13:33:12 +0100 Subject: [PATCH 1/7] Declaring the Event --- Server/mods/deathmatch/logic/CGame.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index dd40af53e0c..0c091df27a3 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1549,6 +1549,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onVehicleEnter", "player, seat, jacked", NULL, false); m_Events.AddEvent("onVehicleExit", "player, seat, jacker", NULL, false); m_Events.AddEvent("onVehicleExplode", "", NULL, false); + m_Events.AddEvent("onVehicleDrown", "", NULL, false); // Console events m_Events.AddEvent("onConsole", "text", NULL, false); From 8b2dfed736c7e97f79f1b927585723bc29688afc Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Mon, 7 Sep 2020 13:34:27 +0100 Subject: [PATCH 2/7] Calling the event once in water --- Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp | 8 ++++++++ Server/mods/deathmatch/logic/CVehicle.cpp | 1 + Server/mods/deathmatch/logic/CVehicle.h | 4 ++++ .../deathmatch/logic/packets/CVehiclePuresyncPacket.cpp | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp b/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp index 7da1c780c8c..f304170d98a 100644 --- a/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp +++ b/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp @@ -417,6 +417,14 @@ void CUnoccupiedVehicleSync::Packet_UnoccupiedVehicleSync(CUnoccupiedVehicleSync bool bDerailed = pVehicle->IsDerailed(); bool bInWater = pVehicle->IsInWater(); + if (bInWater && bInWater != pVehicle->GetLastSyncedIsInWater()) + { + // Call the event once in water + CLuaArguments Arguments; + pVehicle->CallEvent("onVehicleDrown", Arguments); + } + pVehicle->setLastSyncedIsInWater(bInWater); + // Turn the engine on if it's on pVehicle->SetEngineOn(vehicle.data.bEngineOn); diff --git a/Server/mods/deathmatch/logic/CVehicle.cpp b/Server/mods/deathmatch/logic/CVehicle.cpp index c2f4baf54b0..9661b672998 100644 --- a/Server/mods/deathmatch/logic/CVehicle.cpp +++ b/Server/mods/deathmatch/logic/CVehicle.cpp @@ -28,6 +28,7 @@ CVehicle::CVehicle(CVehicleManager* pVehicleManager, CElement* pParent, unsigned m_eVehicleType = CVehicleManager::GetVehicleType(m_usModel); m_fHealth = DEFAULT_VEHICLE_HEALTH; m_fLastSyncedHealthHealth = DEFAULT_VEHICLE_HEALTH; + m_bLastSyncedIsInWater = DEFAULT_IS_IN_WATER; m_llIdleTime = CTickCount::Now(); m_fTurretPositionX = 0; m_fTurretPositionY = 0; diff --git a/Server/mods/deathmatch/logic/CVehicle.h b/Server/mods/deathmatch/logic/CVehicle.h index 4d894578922..5834ab2bd27 100644 --- a/Server/mods/deathmatch/logic/CVehicle.h +++ b/Server/mods/deathmatch/logic/CVehicle.h @@ -23,6 +23,7 @@ class CVehicle; #define MAX_VEHICLE_SEATS 9 #define DEFAULT_VEHICLE_HEALTH 1000 #define MAX_VEHICLE_HEALTH 10000 +#define DEFAULT_IS_IN_WATER false enum eWheelStatus { @@ -188,6 +189,8 @@ class CVehicle : public CElement void SetHealth(float fHealth) { m_fHealth = fHealth; }; float GetLastSyncedHealth() { return m_fLastSyncedHealthHealth; }; void SetLastSyncedHealth(float fHealth) { m_fLastSyncedHealthHealth = fHealth; }; + float GetLastSyncedIsInWater() { return m_bLastSyncedIsInWater; }; + void setLastSyncedIsInWater(bool bIsInWater) { m_bLastSyncedIsInWater = bIsInWater; }; CVehicleColor& RandomizeColor(); @@ -364,6 +367,7 @@ class CVehicle : public CElement CVector m_vecTurnSpeed; float m_fHealth; float m_fLastSyncedHealthHealth; + bool m_bLastSyncedIsInWater; CTickCount m_llBlowTime; CTickCount m_llIdleTime; diff --git a/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp index caf12098440..f856b1cdb0a 100644 --- a/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp @@ -154,6 +154,15 @@ bool CVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream) // - Caz pVehicle->SetLastSyncedHealth(fHealth); + bool bInWater = pVehicle->IsInWater(); + if (bInWater && bInWater != pVehicle->GetLastSyncedIsInWater()) + { + // Call the event once in water + CLuaArguments Arguments; + pVehicle->CallEvent("onVehicleDrown", Arguments); + } + pVehicle->setLastSyncedIsInWater(bInWater); + // Trailer chain CVehicle* pTowedByVehicle = pVehicle; ElementID TrailerID; From 099fec91ae0258f06510cf264e1656e3c7561e58 Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Mon, 19 Oct 2020 07:38:25 +0100 Subject: [PATCH 3/7] Update Server/mods/deathmatch/logic/CGame.cpp Co-authored-by: Nikita Obrekht --- Server/mods/deathmatch/logic/CGame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 0c091df27a3..b4b9e0e25c2 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1549,7 +1549,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onVehicleEnter", "player, seat, jacked", NULL, false); m_Events.AddEvent("onVehicleExit", "player, seat, jacker", NULL, false); m_Events.AddEvent("onVehicleExplode", "", NULL, false); - m_Events.AddEvent("onVehicleDrown", "", NULL, false); + m_Events.AddEvent("onVehicleDrown", "", nullptr, false); // Console events m_Events.AddEvent("onConsole", "text", NULL, false); From 4426e5186cdce4489b8c1e53c2b888aa22aafbf0 Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Tue, 20 Oct 2020 21:34:22 +0100 Subject: [PATCH 4/7] Update Server/mods/deathmatch/logic/CVehicle.h Co-authored-by: saml1er <10183157+saml1er@users.noreply.github.com> --- Server/mods/deathmatch/logic/CVehicle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CVehicle.h b/Server/mods/deathmatch/logic/CVehicle.h index 5834ab2bd27..7fdc3027812 100644 --- a/Server/mods/deathmatch/logic/CVehicle.h +++ b/Server/mods/deathmatch/logic/CVehicle.h @@ -367,7 +367,7 @@ class CVehicle : public CElement CVector m_vecTurnSpeed; float m_fHealth; float m_fLastSyncedHealthHealth; - bool m_bLastSyncedIsInWater; + bool m_bLastSyncedIsInWater = false; CTickCount m_llBlowTime; CTickCount m_llIdleTime; From dae5ef3f71f9574ba419d7183369ee08d7506917 Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Tue, 20 Oct 2020 21:34:52 +0100 Subject: [PATCH 5/7] Update Server/mods/deathmatch/logic/CVehicle.cpp Co-authored-by: saml1er <10183157+saml1er@users.noreply.github.com> --- Server/mods/deathmatch/logic/CVehicle.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CVehicle.cpp b/Server/mods/deathmatch/logic/CVehicle.cpp index 9661b672998..c2f4baf54b0 100644 --- a/Server/mods/deathmatch/logic/CVehicle.cpp +++ b/Server/mods/deathmatch/logic/CVehicle.cpp @@ -28,7 +28,6 @@ CVehicle::CVehicle(CVehicleManager* pVehicleManager, CElement* pParent, unsigned m_eVehicleType = CVehicleManager::GetVehicleType(m_usModel); m_fHealth = DEFAULT_VEHICLE_HEALTH; m_fLastSyncedHealthHealth = DEFAULT_VEHICLE_HEALTH; - m_bLastSyncedIsInWater = DEFAULT_IS_IN_WATER; m_llIdleTime = CTickCount::Now(); m_fTurretPositionX = 0; m_fTurretPositionY = 0; From 71d145a1adfd802a1a0910de2a1c8201554a1b3d Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Tue, 20 Oct 2020 21:35:02 +0100 Subject: [PATCH 6/7] Update Server/mods/deathmatch/logic/CVehicle.h Co-authored-by: saml1er <10183157+saml1er@users.noreply.github.com> --- Server/mods/deathmatch/logic/CVehicle.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/CVehicle.h b/Server/mods/deathmatch/logic/CVehicle.h index 7fdc3027812..b36cb0e4269 100644 --- a/Server/mods/deathmatch/logic/CVehicle.h +++ b/Server/mods/deathmatch/logic/CVehicle.h @@ -23,8 +23,6 @@ class CVehicle; #define MAX_VEHICLE_SEATS 9 #define DEFAULT_VEHICLE_HEALTH 1000 #define MAX_VEHICLE_HEALTH 10000 -#define DEFAULT_IS_IN_WATER false - enum eWheelStatus { DT_WHEEL_INTACT = 0, From 6a3790ece057d26131b3d5fe7ae944119279db4f Mon Sep 17 00:00:00 2001 From: Unde-R <67543158+Unde-R@users.noreply.github.com> Date: Fri, 30 Oct 2020 13:49:07 +0100 Subject: [PATCH 7/7] Rename to onElementWaterInteract and support for objects/peds --- Server/mods/deathmatch/logic/CGame.cpp | 2 +- Server/mods/deathmatch/logic/CObject.h | 4 ++++ Server/mods/deathmatch/logic/CObjectSync.cpp | 9 +++++++++ Server/mods/deathmatch/logic/CPed.h | 3 +++ Server/mods/deathmatch/logic/CPedSync.cpp | 9 +++++++++ .../mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp | 5 +++-- .../deathmatch/logic/packets/CPlayerPuresyncPacket.cpp | 10 ++++++++++ .../logic/packets/CVehiclePuresyncPacket.cpp | 5 +++-- 8 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index b4b9e0e25c2..1076cad353f 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1549,7 +1549,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onVehicleEnter", "player, seat, jacked", NULL, false); m_Events.AddEvent("onVehicleExit", "player, seat, jacker", NULL, false); m_Events.AddEvent("onVehicleExplode", "", NULL, false); - m_Events.AddEvent("onVehicleDrown", "", nullptr, false); + m_Events.AddEvent("onElementWaterInteract", "bWaterInOrOut", nullptr, false); // Console events m_Events.AddEvent("onConsole", "text", NULL, false); diff --git a/Server/mods/deathmatch/logic/CObject.h b/Server/mods/deathmatch/logic/CObject.h index ea170408c40..175ac02d839 100644 --- a/Server/mods/deathmatch/logic/CObject.h +++ b/Server/mods/deathmatch/logic/CObject.h @@ -71,6 +71,9 @@ class CObject : public CElement CPlayer* GetSyncer() { return m_pSyncer; } void SetSyncer(CPlayer* pPlayer); + float GetLastSyncedIsInWater() { return m_bLastSyncedIsInWater; }; + void setLastSyncedIsInWater(bool bIsInWater) { m_bLastSyncedIsInWater = bIsInWater; }; + bool IsLowLod(); bool SetLowLodObject(CObject* pLowLodObject); CObject* GetLowLodObject(); @@ -103,4 +106,5 @@ class CObject : public CElement public: CPositionRotationAnimation* m_pMoveAnimation; + bool m_bLastSyncedIsInWater = false; }; diff --git a/Server/mods/deathmatch/logic/CObjectSync.cpp b/Server/mods/deathmatch/logic/CObjectSync.cpp index 75604d85e7d..72a0ce2765c 100644 --- a/Server/mods/deathmatch/logic/CObjectSync.cpp +++ b/Server/mods/deathmatch/logic/CObjectSync.cpp @@ -211,6 +211,15 @@ void CObjectSync::Packet_ObjectSync(CObjectSyncPacket& Packet) if (pData->ucFlags & 0x4) pObject->SetHealth(pData->fHealth); + bool bInWater = pObject->IsInWater(); + if (bInWater != pObject->GetLastSyncedIsInWater()) + { + CLuaArguments Arguments; + Arguments.PushBoolean(bInWater); + pPed->CallEvent("onElementWaterInteract", Arguments); + } + pPed->setLastSyncedIsInWater(bInWater); + // Send this sync pData->bSend = true; } diff --git a/Server/mods/deathmatch/logic/CPed.h b/Server/mods/deathmatch/logic/CPed.h index 0a1e0bbe359..3eb368d0e7b 100644 --- a/Server/mods/deathmatch/logic/CPed.h +++ b/Server/mods/deathmatch/logic/CPed.h @@ -257,6 +257,8 @@ class CPed : public CElement bool IsSyncable() { return m_bSyncable; }; void SetSyncable(bool bSynced) { m_bSyncable = bSynced; }; + float GetLastSyncedIsInWater() { return m_bLastSyncedIsInWater; }; + void setLastSyncedIsInWater(bool bIsInWater) { m_bLastSyncedIsInWater = bIsInWater; }; CPlayer* m_pSyncer; bool IsStealthAiming() { return m_bStealthAiming; } @@ -312,4 +314,5 @@ class CPed : public CElement private: CPedManager* m_pPedManager; + bool m_bLastSyncedIsInWater = false; }; diff --git a/Server/mods/deathmatch/logic/CPedSync.cpp b/Server/mods/deathmatch/logic/CPedSync.cpp index 490a137de44..88e5b495856 100644 --- a/Server/mods/deathmatch/logic/CPedSync.cpp +++ b/Server/mods/deathmatch/logic/CPedSync.cpp @@ -251,6 +251,15 @@ void CPedSync::Packet_PedSync(CPedSyncPacket& Packet) if (pData->ucFlags & 0x40 && pPlayer->GetBitStreamVersion() >= 0x55) pPed->SetInWater(pData->bIsInWater); + bool bInWater = pPed->IsInWater(); + if (bInWater != pPed->GetLastSyncedIsInWater()) + { + CLuaArguments Arguments; + Arguments.PushBoolean(bInWater); + pPed->CallEvent("onElementWaterInteract", Arguments); + } + pPed->setLastSyncedIsInWater(bInWater); + // Send this sync pData->bSend = true; } diff --git a/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp b/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp index f304170d98a..5c9558190dd 100644 --- a/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp +++ b/Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp @@ -417,11 +417,12 @@ void CUnoccupiedVehicleSync::Packet_UnoccupiedVehicleSync(CUnoccupiedVehicleSync bool bDerailed = pVehicle->IsDerailed(); bool bInWater = pVehicle->IsInWater(); - if (bInWater && bInWater != pVehicle->GetLastSyncedIsInWater()) + if (bInWater != pVehicle->GetLastSyncedIsInWater()) { // Call the event once in water CLuaArguments Arguments; - pVehicle->CallEvent("onVehicleDrown", Arguments); + Arguments.PushBoolean(bInWater); + pVehicle->CallEvent("onElementWaterInteract", Arguments); } pVehicle->setLastSyncedIsInWater(bInWater); diff --git a/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp index 04f0912d661..287d5380ded 100644 --- a/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp @@ -263,6 +263,16 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream) pSourcePlayer->CallEvent("onPlayerDamage", Arguments); } + bool bInWater = pSourcePlayer->IsInWater(); + if (bInWater != pSourcePlayer->GetLastSyncedIsInWater()) + { + // Call the event once in water + CLuaArguments Arguments; + Arguments.PushBoolean(bInWater); + pSourcePlayer->CallEvent("onElementWaterInteract", Arguments); + } + pSourcePlayer->setLastSyncedIsInWater(bInWater); + // Success return true; } diff --git a/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp index f856b1cdb0a..6d97efdb3e7 100644 --- a/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp @@ -155,11 +155,12 @@ bool CVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream) pVehicle->SetLastSyncedHealth(fHealth); bool bInWater = pVehicle->IsInWater(); - if (bInWater && bInWater != pVehicle->GetLastSyncedIsInWater()) + if (bInWater != pVehicle->GetLastSyncedIsInWater()) { // Call the event once in water CLuaArguments Arguments; - pVehicle->CallEvent("onVehicleDrown", Arguments); + Arguments.PushBoolean(bInWater); + pVehicle->CallEvent("onElementWaterInteract", Arguments); } pVehicle->setLastSyncedIsInWater(bInWater);