From 44e9f44f70c580f6b5bf49b28845190f09c5f387 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Thu, 15 Feb 2024 08:56:02 +0000 Subject: [PATCH] Fix error when BTR kills enemy (!82) Fixes an NRE when the BTR kills an enemy while using cover fire service Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/82 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/Aki.Custom/BTR/BTRManager.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/project/Aki.Custom/BTR/BTRManager.cs b/project/Aki.Custom/BTR/BTRManager.cs index e4408dd..8930d5b 100644 --- a/project/Aki.Custom/BTR/BTRManager.cs +++ b/project/Aki.Custom/BTR/BTRManager.cs @@ -450,7 +450,7 @@ namespace Aki.Custom.BTR isShooting = true; yield return new WaitForSecondsRealtime(machineGunAimDelay); - if (!currentTarget.IsVisible || !btrBotShooter.BotBtrData.CanShoot()) + if (currentTarget?.Person == null || currentTarget?.IsVisible == false || !btrBotShooter.BotBtrData.CanShoot()) { isShooting = false; yield break; @@ -462,9 +462,14 @@ namespace Aki.Custom.BTR int burstMin = Mathf.FloorToInt(machineGunBurstCount.x); int burstMax = Mathf.FloorToInt(machineGunBurstCount.y); int burstCount = Random.Range(burstMin, burstMax + 1); + Vector3 targetHeadPos = currentTarget.Person.PlayerBones.Head.position; while (burstCount > 0) { - Vector3 targetHeadPos = currentTarget.Person.PlayerBones.Head.position; + // Only update shooting position if the target isn't null + if (currentTarget?.Person != null) + { + targetHeadPos = currentTarget.Person.PlayerBones.Head.position; + } Vector3 aimDirection = Vector3.Normalize(targetHeadPos - machineGunMuzzle.position); ballisticCalculator.Shoot(btrMachineGunAmmo, machineGunMuzzle.position, aimDirection, btrBotShooter.ProfileId, btrMachineGunWeapon, 1f, 0); firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, machineGunMuzzle.position, aimDirection, false);