tModLoader How do you make a projectile apply a debuff onto a hit enemy?

AxerTheAxe

Skeletron Prime
I was wondering how to make a gun shoot a projectile that gives the hit target/enemy a debuff. Thanks for any potential help!
 
Like this:

public override void ModifyHitPlayer( Player target, ref int damage, ref bool crit )
{
target.AddBuff( mod.BuffType( "NameOfTheBuff" ), 240 );
}
public override void ModifyHitNPC( NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection )
{
target.AddBuff( mod.BuffType( "NameOfTheBuff" ), 240 );
}

mod.BuffType( "name" ) can be replaced with BuffID.<valid_buff_id> or just an integer id of the buff.
240 is the duration (60 = 1 second)
 
Like this:

public override void ModifyHitPlayer( Player target, ref int damage, ref bool crit )
{
target.AddBuff( mod.BuffType( "NameOfTheBuff" ), 240 );
}
public override void ModifyHitNPC( NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection )
{
target.AddBuff( mod.BuffType( "NameOfTheBuff" ), 240 );
}

mod.BuffType( "name" ) can be replaced with BuffID.<valid_buff_id> or just an integer id of the buff.
240 is the duration (60 = 1 second)

Hi, my bullet still does not afflict the debuff. Here is the code.

public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit)
{
target.AddBuff(BuffID.CursedInferno, 240);
}
public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
target.AddBuff(BuffID.CursedInferno, 240);
}

What do I do?
 
Just for anyone who reads this and is wondering how to do this the code that Katniss sent works. I was putting the code into my gun script and not the projectile script. So you will have to make a new projectile then put the script into there.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TutorialMod1.Projectiles
{
    public class ExampleProjectile1 : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.width = 8;
            projectile.height = 12;
            projectile.scale = 2.0f;

            projectile.aiStyle = 1;
            projectile.friendly = true;
            projectile.penetrate = 100;
            projectile.ranged = true;
            projectile.arrow = true;

            projectile.aiStyle = -1;

            projectile.light = 0.3f;
        }

        public override void AI()
        {
            Lighting.AddLight(projectile.position, 0.05f, 0.20f, 0.95f);
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)                //HERE
        {
            target.AddBuff(BuffID.OnFire, 30 * 60);
            target.AddBuff(BuffID.Ichor, 30 * 60);
        }
    }
}

First, create a projectile class.

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TutorialMod1.Items.Weapons
{
    public class ModdedArrow1 : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Modded Arrow1");
        }

        public override void SetDefaults()
        {
            item.damage = 225;
            item.ranged = true;
            item.width = 1;
            item.height = 1;
            item.scale = 2.0f;
            item.maxStack = 9999;
            item.consumable = true;
            item.knockBack = 1.75f;
            item.value = Item.buyPrice(copper: 1);
            item.rare = 5;
            item.shoot = mod.ProjectileType("ExampleProjectile1");    //HERE
            item.shootSpeed = 15.5f;
            item.ammo = AmmoID.Arrow;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 1);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this, 9999);
            recipe.AddRecipe();
        }
    }
}

Next, create a specific arrow class and choose which projectile class to use.
Code:
item.shoot = mod.ProjectileType("ExampleProjectile1");
 
Back
Top Bottom