From 17f6aaeedada660c455d1760efb45b5b901e5ca1 Mon Sep 17 00:00:00 2001 From: in0finite Date: Tue, 5 Jan 2021 05:18:47 +0100 Subject: [PATCH] peds are killed with a separate function ; ragdoll is detached only when peds are killed, not destroyed --- Assets/Scripts/Behaviours/Ped/Ped.cs | 5 ----- Assets/Scripts/Behaviours/Ped/Ped_Damage.cs | 22 +++++++++++++++++++ .../Behaviours/Ped/States/BaseScriptState.cs | 2 +- Assets/Scripts/UI/PedsWindow.cs | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index 8bfb52a6..53e26fac 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -207,11 +207,6 @@ namespace SanAndreasUnity.Behaviours void OnDisable () { s_allPeds.Remove (this); - - if (this.PlayerModel != null) - { - this.PlayerModel.DetachRagdoll(this.KillingDamageInfo); - } } diff --git a/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs b/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs index b5821699..cc2a139d 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs @@ -21,6 +21,8 @@ namespace SanAndreasUnity.Behaviours /// public DamageInfo KillingDamageInfo { get; set; } + private bool m_alreadyKilled = false; + void AwakeForDamage () @@ -130,6 +132,26 @@ namespace SanAndreasUnity.Behaviours msg.Text = damageAmount.ToString(); } + public void Kill() + { + F.RunExceptionSafe(this.KillInternal); + } + + void KillInternal() + { + if (m_alreadyKilled) + return; + + m_alreadyKilled = true; + + if (this.PlayerModel != null) + { + this.PlayerModel.DetachRagdoll(this.KillingDamageInfo); + } + + Object.Destroy(this.gameObject); + } + } } diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs index 80ad046e..e904a19e 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs @@ -319,7 +319,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States if (m_ped.Health <= 0) { m_ped.KillingDamageInfo = damageInfo; - Object.Destroy(m_ped.gameObject); + m_ped.Kill(); } // notify clients diff --git a/Assets/Scripts/UI/PedsWindow.cs b/Assets/Scripts/UI/PedsWindow.cs index 2344f817..e2ebf661 100644 --- a/Assets/Scripts/UI/PedsWindow.cs +++ b/Assets/Scripts/UI/PedsWindow.cs @@ -164,7 +164,7 @@ namespace SanAndreasUnity.UI { { foreach (var p in Ped.AllPeds) { - Destroy (p.gameObject); + p.Kill(); } }