How would I make my gun shoot an animated projectile?

Dankus Memeus

Terrarian
I only started modding a week ago, but I've looked at tutorials and the animated projectile on example mod but I can't make my gun shoot the projectile. I think it has something to do with using ammo because I can make it shoot from magic weapons. I'm pretty new to coding so this is probably to advanced for me but any help would be appreciated!

Code for gun:

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using Terraria.DataStructures;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Creative;
using DudsMod.Content.Projectiles;

namespace DudsMod.Content.Items.Weapons
{
public class Malorian : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Wake the :red: up samurari!\nRight click to release a flame attack\nConverts musket balls into high powered bullets");

}

public override void SetDefaults()
{


Item.width = 48;
Item.height = 48;
Item.scale = 0.8f;
Item.rare = ItemRarityID.Red;


Item.useTime = 30;
Item.useAnimation = 30;
Item.useStyle = ItemUseStyleID.Shoot;
Item.autoReuse = true;


Item.UseSound = new SoundStyle($"{nameof(DudsMod)}/Assets/Sounds/Items/Guns/MalorianBullet")
{
Volume = 2.3f,
PitchVariance = 0.2f,
MaxInstances = 7,
};


Item.DamageType = DamageClass.Ranged;
Item.damage = 250;
Item.knockBack = 6f;
Item.noMelee = true;
Item.crit = 25;


Item.shoot = ModContent.ProjectileType<MalorianBullet>();
Item.shootSpeed = 55f;
Item.useAmmo = AmmoID.Bullet;
}

}

}



Code for projectile:

using DudsMod.Content.Items;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.Creative;
using Terraria.ID;
using Terraria.ModLoader;

namespace DudsMod.Content.Projectiles
{
public class MalorianBullet : ModProjectile
{

public override void SetStaticDefaults() {
Main.projFrames[Projectile.type] = 7;
}

public override void SetDefaults() {
Projectile.width = 16;
Projectile.height = 16;

Projectile.friendly = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.ignoreWater = false;
Projectile.tileCollide = true;
Projectile.penetrate = 1;
Projectile.light = 0.25f;

Projectile.alpha = 60;
}
public override Color? GetAlpha(Color lightColor) {

return null;
}

public override void AI() {
Projectile.ai[0] += 2f;

FadeInAndOut();

Projectile.velocity *= 1f;


if (++Projectile.frameCounter >= 2) {
Projectile.frameCounter = 0;

if (++Projectile.frame >= 2)
Projectile.frame = 0;
}


if (Projectile.ai[0] >= 180f)
Projectile.Kill();


Projectile.direction = Projectile.spriteDirection = (Projectile.velocity.X > 0f) ? 1 : -1;

Projectile.rotation = Projectile.velocity.ToRotation();

if (Projectile.spriteDirection == -1) {
Projectile.rotation += MathHelper.Pi;

}
}


public void FadeInAndOut() {

if (Projectile.ai[0] <= 50f) {

Projectile.alpha -= 25;

if (Projectile.alpha < 100)
Projectile.alpha = 100;

return;
}


Projectile.alpha += 25;

if (Projectile.alpha > 255)
Projectile.alpha = 255;
}

public override bool PreDraw(ref Color lightColor) {

SpriteEffects spriteEffects = SpriteEffects.None;
if (Projectile.spriteDirection == -1)
spriteEffects = SpriteEffects.FlipHorizontally;

Texture2D texture = (Texture2D)ModContent.Request<Texture2D>(Texture);


int frameHeight = texture.Height / Main.projFrames[Projectile.type];
int startY = frameHeight * Projectile.frame;


Rectangle sourceRectangle = new Rectangle(0, startY, texture.Width, frameHeight);



Vector2 origin = sourceRectangle.Size() / 2f;


float offsetX = 20f;
origin.X = (float)(Projectile.spriteDirection == 1 ? sourceRectangle.Width - offsetX : offsetX);



Color drawColor = Projectile.GetAlpha(lightColor);
Main.EntitySpriteDraw(texture,
Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY),
sourceRectangle, drawColor, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0);

return false;
}
}
}
 
Back
Top Bottom