tModLoader Looking for a way for a weapon ignore defense

TRYAGAIN211

Official Terrarian
Hello, I am currently making a weapon that summons projectiles that deal 5 damage, but ignores all defense of the hit enemy,
and I don't know how to make a specific weapon penetrate defense without any other weapons getting this benefit. Does anyone know how to do this?

Thanks in advance.
 
You can make your weapon cause a DeBuff that decreases defense.

Code:
using Terraria;
using Terraria.ModLoader;

namespace YOURMOD.Buffs
{
    public class DefenceBuff : ModBuff
    {
        public override void SetDefaults()
        {
            DisplayName.SetDefault("Defence DeBuff");
            Description.SetDefault("Destroys Defence.");
            Main.buffNoTimeDisplay[Type] = false;
            Main.debuff[Type] = false; //Add this so the nurse doesn't remove the buff when healing
        }

        public override void Update(Player player, ref int buffIndex)
        {
            player.statDefense -= 99999; // -99999 defense to whomever this buff is active on
        }
    }
}

If you don't want other weapons to abuse this you can just make the buff last 1 second or shorter
 
Oh! I didn't notice that someone replied to this, I actually figured it out myself by shuffling through terraria's code and found a way to bypass enemies defense by using this bit of code here:

Code:
public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
    if (target.defense < 999)
    {
        damage = damage + (target.defense / 2); // Terraria no longer cares about defense when the damage is beyond one less then the npc's defense
    }
}
 
Back
Top Bottom