1. 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;
            }
     
    Last edited by a moderator: Dec 15, 2016
  2. Add a null check for hitInfo. I think @Wulf made this suggestion on a similar post not too long ago.
     
  3. Resolved now :) Thanks for the help guys. @PsychoTea to the rescue.
     
    Last edited by a moderator: Dec 15, 2016