tModLoader how to make an accessory that ignites an npc on hit?

TheSuve

Terrarian
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.GameContent.Creative;
using System;


namespace MyMod.Items
{

internal class Ac : ModItem
{


public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
}

public override void SetDefaults()
{
Item.width = 20;
Item.height = 20;
Item.accessory = true;
Item.lifeRegen = 3;

}



public override void UpdateAccessory(Player player, bool hideVisual)
{
player.statDefense += 20;
player.GetDamage(DamageClass.Throwing) += 1.1f;
player.GetCritChance(DamageClass.Throwing) += 1.4f;
player.GetAttackSpeed(DamageClass.Throwing) += 1.5f;
player.moveSpeed += 0.7f;
}

public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(24, 120);
}



}
}


this is my code for the accessory (I'm new to creating terraria mods), can you tell me how to make it set on fire when hitting an enemy?
 
Here's an example from the TML Discord bot. Basically you'd follow this, except instead of the example showing adding immunity to the player, you'd check the bool in OnHitNPC and then add the fire debuff.

============
Sometimes it isn't possible to create an effect for an accessory without supplementing it with other stuff. A common pattern to follow is using a bool field/property on a class that inherits ModPlayer. Here's a quick rundown of how to set this pattern up:
  • Your accessory item uses its UpdateAccessory hook to set our bool field, SomeAccessoryBool, on a class inheriting ModPlayer, SomeAccessoryPlayer: player.GetModPlayer<SomeAccessoryPlayer>().SomeAccessoryBool = true
  • Then, SomeAccessoryPlayer uses its ResetEffects hook to set SomeAccessoryBool back to false. This makes it so we don't need to add any extra logic for handling unequiping our accessory
  • Finally, we can implement any effect we want using any hooks on SomeAccessoryPlayer
Here's an example of this pattern in action:
Accessory: tModLoader/ExampleMod/Content/Items/Accessories/ExampleImmunityAccessory.cs at stable · tModLoader/tModLoader
Player: tModLoader/ExampleMod/Common/Players/ExampleImmunityPlayer.cs at stable · tModLoader/tModLoader
 
Back
Top Bottom