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)
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);
}
}
}
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();
}
}
}
item.shoot = mod.ProjectileType("ExampleProjectile1");