0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

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: SPT-AKI/Modules#82
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-02-15 08:56:02 +00:00 committed by chomp
parent c8507fb600
commit 44e9f44f70

View File

@ -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);