SouzouOokami
Terrarian
I'm trying to make a weapon that charges up infinitely but resets if you get hit, but it keeps firing projectiles, constantly setting the charge back to 1. How do I make it so that way it will only fire a projectile after you let go of the mouse, if my charge code isn't also structured in a way where it won't go up?
Here's my code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Microsoft.Xna.Framework;
using System;
using Resurgance;
using Resurgance.Projectiles.Player;
using Microsoft.Xna.Framework.Input;
namespace Resurgance.Items
{
public class ChargeBlaster : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Charge Blaster"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("Gains more damage infinitely.\nResets after taking damage");
}
public override void SetDefaults()
{
Item.damage = 10 * charge;
Item.DamageType = DamageClass.Ranged;
Item.width = 40;
Item.height = 40;
Item.useTime = 20;
Item.useAnimation = 20;
Item.noMelee = true;
Item.useStyle = ItemUseStyleID.Shoot;
Item.channel = true;
Item.knockBack = 3;
Item.value = 75;
Item.rare = ItemRarityID.Blue;
Item.UseSound = SoundID.Item1;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<ChargeShot>();
Item.shootSpeed = 10f;
}
public float timer = 0f;
public float tickRate = 1f / 60;
public int charge = 1;
public void Update()
{
timer += tickRate;
if (timer >= 1f)
{
timer -= 1f;
charge ++;
}
}
public void Hurt()
{
charge = 1;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) {
const int NumProjectiles = 1;
for (int i = 0; i < NumProjectiles; i++) {
Vector2 newVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(1));
newVelocity *= 1f + Main.rand.NextFloat(0.1f);
// Create a projectile.
Projectile.NewProjectileDirect(source, position, newVelocity, type, damage * charge, knockback, player.whoAmI);
}
charge = 1;
return false;
}
}
}
Here's my code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Microsoft.Xna.Framework;
using System;
using Resurgance;
using Resurgance.Projectiles.Player;
using Microsoft.Xna.Framework.Input;
namespace Resurgance.Items
{
public class ChargeBlaster : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Charge Blaster"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("Gains more damage infinitely.\nResets after taking damage");
}
public override void SetDefaults()
{
Item.damage = 10 * charge;
Item.DamageType = DamageClass.Ranged;
Item.width = 40;
Item.height = 40;
Item.useTime = 20;
Item.useAnimation = 20;
Item.noMelee = true;
Item.useStyle = ItemUseStyleID.Shoot;
Item.channel = true;
Item.knockBack = 3;
Item.value = 75;
Item.rare = ItemRarityID.Blue;
Item.UseSound = SoundID.Item1;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<ChargeShot>();
Item.shootSpeed = 10f;
}
public float timer = 0f;
public float tickRate = 1f / 60;
public int charge = 1;
public void Update()
{
timer += tickRate;
if (timer >= 1f)
{
timer -= 1f;
charge ++;
}
}
public void Hurt()
{
charge = 1;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) {
const int NumProjectiles = 1;
for (int i = 0; i < NumProjectiles; i++) {
Vector2 newVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(1));
newVelocity *= 1f + Main.rand.NextFloat(0.1f);
// Create a projectile.
Projectile.NewProjectileDirect(source, position, newVelocity, type, damage * charge, knockback, player.whoAmI);
}
charge = 1;
return false;
}
}
}