tModLoader tMod Custom Accessory, need help

eX_y

Terrarian
(Sorry for grammar errors)
So I've been working on my mod for a couple weeks and I'm currently making an accessory.
I have a normal stat (+20 HP) and I don't have any problem on stats, instead, I want to make it give a stat (Regeneration (Buff ID: 2)) when player gets hurt, anyone can help me with that?

(The code is on the attachments)
 

Attachments

  • FleshcrpAccessorySS.png
    FleshcrpAccessorySS.png
    37 KB · Views: 101
You have to implement a ModPlayer and override the PostHurt hook and update the the ModPlayer from your item.

Would look somthing like this:

ModPlayer:
C#:
namespace TestMod
{
  class TestModPlayer : ModPlayer
  {
    public bool hasTutorialSwordEquiped;

    public override void ResetEffects()
    {
      hasTutorialSwordEquiped = false;
    }

    public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit)
    {
      if (hasTutorialSwordEquiped)
      {
        this.player.AddBuff(BuffID.Regeneration, 350, true);
      }
      //Don´t know if needed or not
      base.PostHurt(pvp, quiet, damage, hitDirection, crit);
    }
  }
}

Add this to your item:
C#:
    public override void UpdateAccessory(Player player, bool hideVisual)
    {
            player.GetModPlayer<TestModPlayer>().hasTutorialSwordEquiped = true;
    }

You can find more information on this by lookin at tModLoader ExampleMod SimpleModPlayer.cs.
 
Back
Top Bottom