(closed)

Sgga

Terrarian
I need help so when i swing a sword it shoots a projectile I already have the sword and projectile
 
i also keep on getting this error also idk why
Screenshot 2021-07-06 101622.jpg


if your asking heres the code

using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;

namespace armorswords.Projectiles
{
public class MourningArc : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Mourning Arc"); //The weapon's name when shown in-game.
}

public override void SetDefaults()
{
projectile.width = 120;
projectile.height = 120;
projectile.timeLeft = 15;
projectile.penetrate = -1;
projectile.scale = 0.6f;
projectile.ignoreWater = true;
projectile.melee = true;
projectile.friendly = true;
projectile.tileCollide = false;
}

public override void AI()
{
//The sound code for the projectile.
projectile.soundDelay--;
if (projectile.soundDelay <= 0)
{
Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 15);
projectile.soundDelay = 45;
}

//How the projectile works.
Player player = Main.player[projectile.owner];
if (Main.myPlayer == projectile.owner)
{
if (!player.channel || player.noItems || player.CCed)
{
projectile.Kill();
}
}
Lighting.AddLight(projectile.Center, 0f, 1f, 0f); //This is the Projectile's light color (RGB)

projectile.Center = player.MountedCenter;
projectile.position.X += player.width / 2 * player.direction;
projectile.spriteDirection = player.direction;
projectile.rotation += 0.36f * player.direction; //This is the Projectile's Spinning/Rotation Speed
if (projectile.rotation > MathHelper.TwoPi)
{
projectile.rotation -= MathHelper.TwoPi;
}
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D texture = Main.projectileTexture[projectile.type];
spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, null, Color.White, projectile.rotation, new Vector2(texture.Width / 2, texture.Height / 2), 1f, projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f);
return false;
}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.CursedInferno, 5 * 60); //Add CursedInferno Buff to the NPC for 5 seconds.
target.immune[projectile.owner] = 2;
}
}
}
 
Code:
item.shoot = ModContent.ProjectileType<Projectiles.enterprojectilehere>();
Hope that this helps, add this to the weapon itself to shoot
Also the error is that you don’t have images for the mourning arc
(Got the code from example mod on GitHub, I didn’t have mine pulled up and I can’t get there so that was the closest I could get and I am new to coding but I do have weapons and armors)
 
Code:
item.shoot = ModContent.ProjectileType<Projectiles.enterprojectilehere>();
Hope that this helps, add this to the weapon itself to shoot
Also the error is that you don’t have images for the mourning arc
(Got the code from example mod on GitHub, I didn’t have mine pulled up and I can’t get there so that was the closest I could get and I am new to coding but I do have weapons and armors)
thx so much but this happened
error.jpg
code:


using Terraria.ID;
using Terraria.ModLoader;

namespace armorswords.Items
{
public class HeadOfTheGrunk : ModItem
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("HeadOfTheGrunk"); // 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("The mouth is full of acid... ew.");
}

public override void SetDefaults()
{
item.damage = 50;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 27;
item.useAnimation = 27;
item.useStyle = 2;
item.knockBack = 5;
item.value = 770;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = ModContent.ProjectileType<Projectiles.MourningArc>(MourningArc);
}
}
}


heres the mod if you need more info
 

Attachments

  • Mod.zip
    31.1 KB · Views: 47
Last edited:
also when i swing my weapon it shoots nothing idk why i think its the projectile
code for projectile

using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;

namespace armorswords.Projectiles
{
public class MourningArc : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Mourning Arc"); //The weapon's name when shown in-game.
}

public override void SetDefaults()
{
projectile.width = 120;
projectile.height = 120;
projectile.timeLeft = 15;
projectile.penetrate = -1;
projectile.scale = 0.6f;
projectile.ignoreWater = true;
projectile.melee = true;
projectile.friendly = true;
projectile.tileCollide = false;
}

public override void AI()
{
//The sound code for the projectile.
projectile.soundDelay--;
if (projectile.soundDelay <= 0)
{
Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 15);
projectile.soundDelay = 45;
}

//How the projectile works.
Player player = Main.player[projectile.owner];
if (Main.myPlayer == projectile.owner)
{
if (!player.channel || player.noItems || player.CCed)
{
projectile.Kill();
}
}
Lighting.AddLight(projectile.Center, 0f, 1f, 0f); //This is the Projectile's light color (RGB)

projectile.Center = player.MountedCenter;
projectile.position.X += player.width / 2 * player.direction;
projectile.spriteDirection = player.direction;
projectile.rotation += 0.36f * player.direction; //This is the Projectile's Spinning/Rotation Speed
if (projectile.rotation > MathHelper.TwoPi)
{
projectile.rotation -= MathHelper.TwoPi;
}
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D texture = Main.projectileTexture[projectile.type];
spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, null, Color.White, projectile.rotation, new Vector2(texture.Width / 2, texture.Height / 2), 1f, projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f);
return false;
}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.CursedInferno, 5 * 60); //Add CursedInferno Buff to the NPC for 5 seconds.
target.immune[projectile.owner] = 2;
}
}


texture

MourningArc.png
 
oh
like this?
using Terraria.ID;
using Terraria.ModLoader;

namespace armorswords.Items
{
public class HeadOfTheGrunk : ModItem
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("HeadOfTheGrunk"); // 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("The mouth is full of acid... ew.");
}

public override void SetDefaults()
{
item.damage = 50;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 27;
item.useAnimation = 27;
item.useStyle = 1;
item.knockBack = 5;
item.value = 770;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = ModContent.ProjectileType<Projectiles.MourningArc>();
item.shootSpeed = 10f;
}
}
}


also it still no work
 
Last edited:
Back
Top Bottom