Skip to content

Commit

Permalink
Carrying - Handle simultaneously carry action (#99)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Kexanone authored Sep 23, 2024
1 parent a94353b commit 7c0ca17
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -135,6 +137,7 @@ class ACE_Carrying_HelperCompartment : GenericEntity
if (!carrierController)
return;

carrierController.ACE_Carrying_SetIsCarrier(false);
carrierController.m_OnLifeStateChanged.Remove(OnCarrierLifeStateChanged);
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

//------------------------------------------------------------------------------------------------
Expand All @@ -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();
}

//------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
}

0 comments on commit 7c0ca17

Please sign in to comment.