Weapons

(For Community-Made Hooks, see Weapon Hooks)

**Weapons** are essential items used for combat against enemies, bosses, and even other players during PvP games. They typically deal more damage than their tool counterparts. Some weapons can be crafted at a Work Bench or an Iron/Lead Anvil or Mythril/Orichalcum Anvil, while others can only be found in Chests, as enemy drops, or purchased from NPCs. *Terraria* has a wide variety of weapons and weapons classes, each suited to particular play styles or specific tasks.

## Types Of Weapons

### Melee Weapon

ExampleSword from bluemagic123's ExampleMod

*(Unedited, can be compiled in TModLoader)*

```
using System;

using Microsoft.Xna.Framework;

using Terraria;

using Terraria.ID;

using Terraria.ModLoader;

namespace ExampleMod.Items.Weapons

{

    public class ExampleSword : ModItem

    {

        public override void SetDefaults()

        {

            item.name = "Example Sword";

            item.damage = 50;

            item.melee = true;

            item.width = 40;

            item.height = 40;

            item.toolTip = "This is a modded sword.";

            item.useTime = 20;

            item.useAnimation = 20;

            item.useStyle = 1;

            item.knockBack = 6;

            item.value = 10000;

            item.rare = 2;

            item.useSound = 1;

            item.autoReuse = true;

        }

        public override void AddRecipes()

        {

            ModRecipe recipe = new ModRecipe(mod);

            recipe.AddIngredient(null, "ExampleItem", 10);

            recipe.AddTile(null, "ExampleWorkbench");

            recipe.SetResult(this);

            recipe.AddRecipe();

        }

        public override void MeleeEffects(Player player, Rectangle hitbox)

        {

            if (Main.rand.Next(3) == 0)

            {

                int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));

            }

        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)

        {

            target.AddBuff(BuffID.OnFire, 60);

        }

    }

}

```

*(Broken down, instructing how things in the .cs work)*

```
using System;

using Microsoft.Xna.Framework;

using Terraria;

using Terraria.ID;

using Terraria.ModLoader;

```

Information the .cs takes from, put this in all Weapon files.

```
namespace ExampleMod.Items.Weapons

```

The directory for your .cs and .png; Example Mod Sources/ExampleMod/Items/Weapons

```
public override void SetDefaults()

```

Sets the default values for the Weapon.

```
item.name = "Example Sword";

```

The name displayed when hovering over the Weapon ingame.

```
item.damage = 50;

```

The damage stat for the Weapon.

```
item.melee = true;

```

This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.

```
item.width = 40;

```

The size of the width of the hitbox in pixels.

```
item.height = 40;

```

The size of the height of the hitbox in pixels.

```
item.toolTip = "This is a modded sword.";

```

The description of the Weapon shown when hovering over the Weapon ingame.

```
item.useTime = 20;

```

How fast the Weapon is used.

```
item.useAnimation = 20;

```

How long the Weapon is used for.

```
item.useStyle = 1;

```

The way your Weapon will be used, 1 is the regular sword swing for example, can be found on the Vanilla Item Field Values Spreadsheet

```
item.knockBack = 6;

```

The knockback stat of your Weapon.

```
item.value = 10000;

```

The amount of money your Weapon is worth when selling to a NPC, 1 = 1 Copper | 100 = 1 Silver 10000 = 1 Gold

```
item.rare = 2;

```

The color the title of your Weapon when hovering over it ingame, you can find the tiers Here

```
item.useSound = 1;

```

The sound played when using your Weapon, different sounds can be found on the Vanilla Item Field Values Spreadsheet

```
item.autoReuse = true;

```

Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.

### Ranged Weapon

ExampleGun from bluemagic123's ExampleMod

```
using System;

using Microsoft.Xna.Framework;

using Terraria;

using Terraria.ID;

using Terraria.ModLoader;

namespace ExampleMod.Items.Weapons

{

    public class ExampleGun : ModItem

    {

        public override void SetDefaults()

        {

            item.name = "Example Gun";

            item.damage = 20;

            item.ranged = true;

            item.width = 40;

            item.height = 20;

            item.toolTip = "This is a modded gun.";

            item.useTime = 20;

            item.useAnimation = 20;

            item.useStyle = 5;

            item.noMelee = true;

            item.knockBack = 4;

            item.value = 10000;

            item.rare = 2;

            item.useSound = 11;

            item.autoReuse = true;

            item.shoot = 10;

            item.shootSpeed = 16f;

            item.useAmmo = ProjectileID.Bullet;

        }

    }

}

```

*(Broken down, instructing how things in the .cs work)*

```
using System;

using Microsoft.Xna.Framework;

using Terraria;

using Terraria.ID;

using Terraria.ModLoader;

```

Information the .cs takes from, put this in all Weapon files.

```
namespace ExampleMod.Items.Weapons

```

The directory for your .cs and .png; Example Mod Sources/ExampleMod/Items/Weapons

```
public override void SetDefaults()

```

Sets the default values for the Weapon.

```
item.name = "Example Gun";

```

The name displayed when hovering over the Weapon ingame.

```
item.damage = 50;

```

The damage stat for the Weapon.

```
item.range = true;

```

This defines if it does Range damage and if its effected by Range increasing Armor/Accessories.

```
item.width = 40;

```

The size of the width of the hitbox in pixels.

```
item.height = 20;

```

The size of the height of the hitbox in pixels.

```
item.toolTip = "This is a modded gun.";

```

The description of the Weapon shown when hovering over the Weapon ingame.

```
item.useTime = 20;

```

How fast the Weapon is used.

```
item.useAnimation = 20;

```

How long the Weapon is used for.

```
item.useStyle = 5;

```

The way your Weapon will be used, 1 is the regular sword swing for example, can be found on the Vanilla Item Field Values Spreadsheet

```
item.noMelee = true;

```

Setting to True allows the weapon sprite to stop doing damage, so only the projectile does the damge

```
item.value = 10000;

```

The amount of money your Weapon is worth when selling to a NPC, 1 = 1 Copper | 100 = 1 Silver 10000 = 1 Gold

```
item.rare = 2;

```

The color the title of your Weapon when hovering over it ingame, you can find the tiers Here

```
item.useSound = 1;

```

The sound played when using your Weapon, different sounds can be found on the Vanilla Item Field Values Spreadsheet

```
item.shoot = 10;

```

What Projectile the Weapon will shoot, you can find the types of Projectiles Here

You change the number out for mod.ProjectileType("ExampleBullet") and enter the name of your modded Projectile between the brackets.