diff --git a/Exiled.API/Features/DamageHandlers/CustomDamageHandler.cs b/Exiled.API/Features/DamageHandlers/CustomDamageHandler.cs index c72d482293..cf7e5c5e2e 100644 --- a/Exiled.API/Features/DamageHandlers/CustomDamageHandler.cs +++ b/Exiled.API/Features/DamageHandlers/CustomDamageHandler.cs @@ -49,7 +49,7 @@ public sealed class CustomDamageHandler : AttackerDamageHandler public CustomDamageHandler(Player target, BaseHandler baseHandler) : base(target, baseHandler) { - if (Attacker) + if (Attacker is not null) { if (baseHandler is BaseScpDamageHandler) CustomBase = new ScpDamageHandler(target, baseHandler); @@ -95,12 +95,19 @@ public CustomDamageHandler(Player target, Player attacker, float damage, DamageT Damage = damage; Type = damageType; - Firearm firearm = new(ItemType.GunAK) + if (attacker is not null) { - Base = { Owner = attacker.ReferenceHub }, - }; + Firearm firearm = new(ItemType.GunAK) + { + Base = { Owner = attacker.ReferenceHub }, + }; - CustomBase = new FirearmDamageHandler(firearm, target, new BaseFirearmHandler(firearm.Base, damage)); + CustomBase = new FirearmDamageHandler(firearm, target, new BaseFirearmHandler(firearm.Base, damage)); + + return; + } + + CustomBase = new DamageHandler(target, attacker: null); } /// diff --git a/Exiled.API/Features/DamageHandlers/DamageHandlerBase.cs b/Exiled.API/Features/DamageHandlers/DamageHandlerBase.cs index 55db916ed0..f3b668cf46 100644 --- a/Exiled.API/Features/DamageHandlers/DamageHandlerBase.cs +++ b/Exiled.API/Features/DamageHandlers/DamageHandlerBase.cs @@ -101,8 +101,8 @@ public virtual DamageType Type { DeathTranslation translation = DeathTranslations.TranslationsById[handler.TranslationId]; - if (DamageTypeExtensions.TranslationIdConversion.ContainsKey(translation.Id)) - return damageType = DamageTypeExtensions.TranslationIdConversion[translation.Id]; + if (DamageTypeExtensions.TranslationIdConversion.TryGetValue(translation.Id, out DamageType value)) + return damageType = value; Log.Warn($"{nameof(DamageHandler)}.{nameof(Type)}:" + $"No matching {nameof(DamageType)} for {nameof(UniversalDamageHandler)} with ID {translation.Id}, type will be reported as {DamageType.Unknown}." +