Egaming
Skeletron Prime
I need help with a yoyo shooting projectiles when an enemy is close, the yoyo just stays there in midair when i let go of it. It also shoots way too many projectiles and i would like to know how to make it shoot slower.
The code:
The code:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace EgamingsCryptolicMod.Projectiles
{
public class CryptolicYoyoProjectile : ModProjectile
{
public override void SetStaticDefaults()
{
ProjectileID.Sets.YoyosLifeTimeMultiplier[projectile.type] = -1f;
ProjectileID.Sets.YoyosMaximumRange[projectile.type] = 500f;
ProjectileID.Sets.YoyosTopSpeed[projectile.type] = 20f;
}
public override void SetDefaults()
{
projectile.extraUpdates = 0;
projectile.width = 16;
projectile.height = 16;
projectile.aiStyle = 99;
projectile.friendly = true;
projectile.penetrate = -1;
projectile.melee = true;
}
public override void PostAI()
{
if (Main.rand.NextBool())
{
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 61);
dust.noGravity = true;
dust.scale = 1.6f;
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
Player p = Main.player[projectile.owner];
int healingAmount = damage / 1000;
p.statLife += healingAmount;
p.HealEffect(healingAmount, true);
}
public override void AI()
{
for (int i = 0; i < 200; i++)
{
NPC target = Main.npc[i];
float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
float shootToY = target.position.Y - projectile.Center.Y;
float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
if (distance < 100f && !target.friendly && target.active)
{
if (projectile.ai[0] > 10f)
{
distance = 3f / distance;
shootToX *= distance * 5;
shootToY *= distance * 5;
int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, mod.ProjectileType("CryptolicBlast"), projectile.damage, projectile.knockBack, Main.myPlayer, 0f, 0f); //mod.ProjectileType("Laser") is the projectile it shoots, change it to what you like
Main.projectile[proj].timeLeft = 300;
Main.projectile[proj].netUpdate = true;
projectile.netUpdate = true;
Main.PlaySound(1, (int)projectile.position.X, (int)projectile.position.Y, 12);
projectile.ai[0] = -1f;
}
}
projectile.ai[0] += 1f;
}
}
}
}