Solo-Ion
Dungeon Spirit
Help, how would I add 10% lifesteal to an accessory?
edit: figured it out, but now there is an error
c:\Users\keega\Documents\My Games\Terraria\ModLoader\Mod Sources\NecroticIncantations\Items\NecroClass\Accessories\NecroticBone.cs(40,23) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
code:
using Terraria.ModLoader;
using NecroticIncantations.Items.NecroClass;
namespace NecroticIncantations.Items.NecroClass.Accessories
{
public class NecroticBone : ModItem
{
public float health;
public override void SetStaticDefaults()
{
Tooltip.SetDefault("10% increased necrotic damage" +
"\n1% lifesteal from enemies");
}
public override void SetDefaults()
{
item.Size = new Vector2(34);
item.rare = 2;
item.accessory = true;
}
public override void UpdateAccessory(Player player, bool hideVisual)
{
NecroticDamagePlayer modPlayer = NecroticDamagePlayer.ModPlayer(player);
modPlayer.NecroticDamage += 0.1f;
//add lifesteal effect
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
health = damage * .1f;
player.statLife += health + 1.0f;
}
}
}
I can't say for certain, but I think your problem is the line "player.statLife += health + 1.0f;". player.statLife is an integer (int for short) and you can't just add a float to an int. Both 'health' and '1.0f' are floats (putting a f on the end of a number makes it a float) so they must be explicitly converted to ints. Here's what that line should look like.
player.statLife += (int)(health + 1);
I removed .0f because there's no point defining an int as a float and then immediately converting to an int anyway.