tModLoader Projectile heal on hit

Saobie

Terrarian
While perusing the buish magic guide for making a life fruit item i remember seeing something related to having a projectile heal you for 5 hp whenever it hit an enemy and for the life if me i cant seem to find it again. I thought the code added was player.statlife += (number) but im unsure

Any help?
 
Just tried this, no luck

Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            Main.player[projectile.owner].statLife += 2;   
        }
 
There is no projectile being called in the hit npc event so your "projectile" in your code doesn't exist

instead use this

C#:
public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit)
{
    Main.player[proj.owner].statlife += 2;
}

you see between the brackets after the event there is a "Projectile" being called, which you can use in your code.

which you should then surround with for example this

C#:
public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit)
{
    if (proj.Equals(ProjectileID.WoodenArrowFriendly)) {
        Main.player[proj.owner].statlife += 2;
    }
}

in which case the healing effect only works for that particular type of arrow,I'm assuming you want to add it to your own projectile so that would be

C#:
public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit)
{
    if (proj.Equals(mod.ProjectileType("MyCustomProjectile")))
    {
        Main.player[proj.owner].statlife += 2;
    }
}

Hope that answers your question ^^
(yes it's old but it adds useful info I figured :) )
 
Back
Top Bottom