From 7c0ca175cdfb59e5c39b67e4d2f6673e6f62e250 Mon Sep 17 00:00:00 2001 From: Kex Date: Mon, 23 Sep 2024 22:04:54 +0200 Subject: [PATCH] Carrying - Handle simultaneously carry action (#99) * Make sure on the server side that the owner is in fact not already carried * Use replicated variables for determining if someone is carrier/carried * Correct comment * Check on server if target in fact not carried --- .../SCR_CharacterControllerComponent.c | 34 +++++++++++++++++++ .../Entities/ACE_Carrying_HelperCompartment.c | 6 +++- .../ACE_Carrying/Tools/ACE_Carrying_Tools.c | 12 +++++-- .../ACE_Carrying_CarryUserAction.c | 6 +++- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 addons/carrying/Scripts/Game/ACE_Carrying/Character/SCR_CharacterControllerComponent.c diff --git a/addons/carrying/Scripts/Game/ACE_Carrying/Character/SCR_CharacterControllerComponent.c b/addons/carrying/Scripts/Game/ACE_Carrying/Character/SCR_CharacterControllerComponent.c new file mode 100644 index 00000000..3d7beb35 --- /dev/null +++ b/addons/carrying/Scripts/Game/ACE_Carrying/Character/SCR_CharacterControllerComponent.c @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------------------------ +modded class SCR_CharacterControllerComponent : CharacterControllerComponent +{ + [RplProp()] + protected bool m_bACE_Carrying_IsCarrier = false; + [RplProp()] + protected bool m_bACE_Carrying_IsCarried = false; + + //------------------------------------------------------------------------------------------------ + void ACE_Carrying_SetIsCarrier(bool isCarrier) + { + m_bACE_Carrying_IsCarrier = isCarrier; + Replication.BumpMe(); + } + + //------------------------------------------------------------------------------------------------ + bool ACE_Carrying_IsCarrier() + { + return m_bACE_Carrying_IsCarrier; + } + + //------------------------------------------------------------------------------------------------ + void ACE_Carrying_SetIsCarried(bool isCarried) + { + m_bACE_Carrying_IsCarried = isCarried; + Replication.BumpMe(); + } + + //------------------------------------------------------------------------------------------------ + bool ACE_Carrying_IsCarried() + { + return m_bACE_Carrying_IsCarried; + } +} diff --git a/addons/carrying/Scripts/Game/ACE_Carrying/Entities/ACE_Carrying_HelperCompartment.c b/addons/carrying/Scripts/Game/ACE_Carrying/Entities/ACE_Carrying_HelperCompartment.c index ccaad502..a7939a48 100644 --- a/addons/carrying/Scripts/Game/ACE_Carrying/Entities/ACE_Carrying_HelperCompartment.c +++ b/addons/carrying/Scripts/Game/ACE_Carrying/Entities/ACE_Carrying_HelperCompartment.c @@ -37,12 +37,14 @@ class ACE_Carrying_HelperCompartment : GenericEntity if (!carrierController) return; + carrierController.ACE_Carrying_SetIsCarrier(true); carrierController.m_OnLifeStateChanged.Insert(OnCarrierLifeStateChanged); SCR_CharacterControllerComponent carriedController = SCR_CharacterControllerComponent.Cast(carried.FindComponent(SCR_CharacterControllerComponent)); if (!carriedController) return; + carriedController.ACE_Carrying_SetIsCarried(true); carriedController.m_OnLifeStateChanged.Insert(OnCarriedLifeStateChanged); RplComponent carriedRpl = RplComponent.Cast(carried.FindComponent(RplComponent)); @@ -135,6 +137,7 @@ class ACE_Carrying_HelperCompartment : GenericEntity if (!carrierController) return; + carrierController.ACE_Carrying_SetIsCarrier(false); carrierController.m_OnLifeStateChanged.Remove(OnCarrierLifeStateChanged); } @@ -145,7 +148,8 @@ class ACE_Carrying_HelperCompartment : GenericEntity SCR_CharacterControllerComponent carriedController = SCR_CharacterControllerComponent.Cast(m_pCarried.FindComponent(SCR_CharacterControllerComponent)); if (!carriedController) return; - + + carriedController.ACE_Carrying_SetIsCarried(false); carriedController.m_OnLifeStateChanged.Remove(OnCarriedLifeStateChanged); } } diff --git a/addons/carrying/Scripts/Game/ACE_Carrying/Tools/ACE_Carrying_Tools.c b/addons/carrying/Scripts/Game/ACE_Carrying/Tools/ACE_Carrying_Tools.c index ff9e30f4..77f2aa20 100644 --- a/addons/carrying/Scripts/Game/ACE_Carrying/Tools/ACE_Carrying_Tools.c +++ b/addons/carrying/Scripts/Game/ACE_Carrying/Tools/ACE_Carrying_Tools.c @@ -45,7 +45,11 @@ class ACE_Carrying_Tools if (!carrier) return false; - return GetHelperCompartmentFromCarrier(carrier); + SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(carrier.FindComponent(SCR_CharacterControllerComponent)); + if (!controller) + return false; + + return controller.ACE_Carrying_IsCarrier(); } //------------------------------------------------------------------------------------------------ @@ -55,7 +59,11 @@ class ACE_Carrying_Tools if (!carried) return false; - return GetHelperCompartmentFromCarried(carried); + SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(carried.FindComponent(SCR_CharacterControllerComponent)); + if (!controller) + return false; + + return controller.ACE_Carrying_IsCarried(); } //------------------------------------------------------------------------------------------------ diff --git a/addons/carrying/Scripts/Game/ACE_Carrying/UserActions/ACE_Carrying_CarryUserAction.c b/addons/carrying/Scripts/Game/ACE_Carrying/UserActions/ACE_Carrying_CarryUserAction.c index 0b65ea57..ec4d7af7 100755 --- a/addons/carrying/Scripts/Game/ACE_Carrying/UserActions/ACE_Carrying_CarryUserAction.c +++ b/addons/carrying/Scripts/Game/ACE_Carrying/UserActions/ACE_Carrying_CarryUserAction.c @@ -54,10 +54,14 @@ class ACE_Carrying_CarryUserAction : ScriptedUserAction //------------------------------------------------------------------------------------------------ override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity) { + // Check on server if they are in faction not yet carried + if (ACE_Carrying_Tools.IsCarried(pOwnerEntity)) + return; + ACE_Carrying_Tools.Carry(pUserEntity, pOwnerEntity); } //------------------------------------------------------------------------------------------------ - //! Methods are executed on the local player + //! Only run PerformAction on server override bool CanBroadcastScript() { return false; }; }