• PC NEWS: 1.4.2.3 update is out! More info here. Report bugs here
  • Journey's End on Xbox and PlayStation!: Get all the info by clicking here. A new patch is in QA - expect some Gamepad love, the return of Red's Pick and more. Click here for Known Issues and FAQ. For any other bugs, report them (with as much detail as possible) here.
  • MOBILE NEWS: Stay up to date with the latest mobile news here. Report mobile bugs here

(closed)

Sgga

Terrarian
I need help so when i swing a sword it shoots a projectile I already have the sword and projectile
 

Sgga

Terrarian
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;
}
}
}
 

Greybrynn

Retinazer
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)
 

Sgga

Terrarian
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: 10
Last edited:

Sgga

Terrarian
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
 

Greybrynn

Retinazer
Oh on the sword there needs to be a item.shootSpeed = speed of projectilef
Example:
Item.shootSpeed = 12f
 

Sgga

Terrarian
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:
Top Bottom