From ca616fb758f68846b9737f4253822141114fa1f7 Mon Sep 17 00:00:00 2001 From: local9 Date: Sat, 7 Jan 2023 17:42:32 +0000 Subject: [PATCH 1/2] feat(character): delete attached entities on `/rc` command --- VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs b/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs index a65ce13..1f1f370 100644 --- a/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs +++ b/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs @@ -40,7 +40,7 @@ public LoadPlayer() }), false); #endif - API.RegisterCommand("rc", new Action, string>((source, args, raw) => + API.RegisterCommand("rc", new Action, string>(async (source, args, raw) => { bool isDead = API.IsPlayerDead(API.PlayerId()); @@ -54,6 +54,16 @@ public LoadPlayer() if (isCuffed || isHogtied) return; // need notification + int playerPed = API.PlayerPedId(); + + while (API.IsEntityAttached(playerPed)) + { + await BaseScript.Delay(0); + int entity = API.GetEntityAttachedTo(playerPed); + if (API.DoesEntityExist(entity)) + API.DeleteEntity(ref entity); + } + if (args.Count == 0) { ReloadCharacterSkin(string.Empty); From 42e117317b9ffda148d63ae7113fd101eb3ce0cd Mon Sep 17 00:00:00 2001 From: local9 Date: Sat, 7 Jan 2023 18:05:21 +0000 Subject: [PATCH 2/2] tweak(rc): tweak some logic around `/rc` command --- .../vorpcharacter_cl/Script/LoadPlayer.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs b/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs index 1f1f370..658b282 100644 --- a/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs +++ b/VORP-Character/vorpcharacter_cl/Script/LoadPlayer.cs @@ -43,41 +43,37 @@ public LoadPlayer() API.RegisterCommand("rc", new Action, string>(async (source, args, raw) => { bool isDead = API.IsPlayerDead(API.PlayerId()); + if (isDead) return; // TODO: Add notification - int pHealth = Utilities.GetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Health); - int pStamina = Utilities.GetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Stamina); + // We only need to grab this player ped ID once, we shouldn't wait CPU cycles + int playerPedId = Cache.PlayerPedId; - if (isDead) return; // need notification + int pHealth = Utilities.GetAttributeCoreValue(playerPedId, eAttributeCore.Health); + int pStamina = Utilities.GetAttributeCoreValue(playerPedId, eAttributeCore.Stamina); - bool isCuffed = Utilities.IsPedCuffed(Cache.PlayerPedId); - bool isHogtied = Utilities.IsPedHogtied(Cache.PlayerPedId); + bool isCuffed = Utilities.IsPedCuffed(playerPedId); + bool isHogtied = Utilities.IsPedHogtied(playerPedId); if (isCuffed || isHogtied) return; // need notification - int playerPed = API.PlayerPedId(); - - while (API.IsEntityAttached(playerPed)) + while (API.IsEntityAttached(playerPedId)) { await BaseScript.Delay(0); - int entity = API.GetEntityAttachedTo(playerPed); + int entity = API.GetEntityAttachedTo(playerPedId); if (API.DoesEntityExist(entity)) API.DeleteEntity(ref entity); } if (args.Count == 0) - { ReloadCharacterSkin(string.Empty); - - Utilities.SetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Health, pHealth); - Utilities.SetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Stamina, pStamina); - - return; - } + else + ReloadCharacterSkin($"{args[0]}"); - ReloadCharacterSkin($"{args[0]}"); - - Utilities.SetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Health, pHealth); - Utilities.SetAttributeCoreValue(API.PlayerPedId(), eAttributeCore.Stamina, pStamina); + // update Player Ped ID as it changes due to the model being reloaded + playerPedId = Cache.PlayerPedId; + + Utilities.SetAttributeCoreValue(playerPedId, eAttributeCore.Health, pHealth); + Utilities.SetAttributeCoreValue(playerPedId, eAttributeCore.Stamina, pStamina); }), false);