Hello,
I understand why the null reference is happening because I am doing a check for a weapon in my hand OnEntityTakeDamage but I am throwing the weapon so when it goes to check the weapon, is not in my hand anymore causing the error
I have done some null checks but it doesn't seem to be doing the trick.
Code:private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { var weapon = hitInfo.Weapon?.GetItem().info.shortname; if (entity == null) return; if (weapon == null) return; if (entity is BuildingBlock) { var block = entity as BuildingBlock; if (block == null) return; else if (block.grade == BuildingGrade.Enum.Wood && weapon != null && weapon == "salvaged.sword") hitInfo.damageTypes.Scale(Rust.DamageType.Slash, 15); else if (block.grade == BuildingGrade.Enum.Stone && weapon != null && weapon == "salvaged.sword") hitInfo.damageTypes.Scale(Rust.DamageType.Slash, 40); } if (entity is Door && weapon == "salvaged.sword") hitInfo.damageTypes.Scale(Rust.DamageType.Slash, 5); else return; }
NullReferenceException when checking for weapon
Discussion in 'Rust Development' started by Nathan 3, Dec 14, 2016.