tModLoader [Tutorial] Projectile Guide and Implementation: tModLoader Edition

Sorry I don't really mod anymore but if you still need some help...



You would need to use the item.shoot to make it shoot a projectile. Also, you cannot have a useTime or useAnimation under 2, it has to be greater than or equal to two because the game cannot trigger an action with a useTime/useAnimation of 0 or 1.



You would need to make a projectile to have the vampire effect by using the AI function. Then set the damage function to heal the player manually with a set amount using the damage to the npc. Depending on what you mean by 6-12 knives, if a burst, you might want to check out the ConsumeAmmo function. If like a shotgun, you would need to override the Shoot function. The shoot method is easier to implement actually. Now for the whole spinning thing, you should not stick with a normal ai but instead create a unique ai, setting the ai value in your projectile to -1. Use projectile.rotation to help you spin it and projectile.alpha to make it fade. Most of these are in the example mod, so check out the code, they work, but not in the newest version (sadly because I don't update it anymore).


Thanks!


If you still exist, the projectile uses dust to as the projectile rather than an image. Other than that, you can use the homing projectile code in the second post.

See, I'm sort of a newb when it comes to coding, so I had absolutely no idea what you meant in any of that besides "projectile.rotation" and "example mod" so if you could MAYBE (if this isn't too much to ask for) give me the basic skeleton of the thing I just described so I can modify it a bit myself, that would be awesome :)
 

See, I'm sort of a newb when it comes to coding, so I had absolutely no idea what you meant in any of that besides "projectile.rotation" and "example mod" so if you could MAYBE (if this isn't too much to ask for) give me the basic skeleton of the thing I just described so I can modify it a bit myself, that would be awesome :)

You can just download the example mod on the first post of this thread. The file is called "MPT.zip". You need to open and extract it to any location and then you should be able to look through the code in any of the folders. The rotation thing that you are looking for would be in the folder called something like "projectiles" and go open "Example Bullet A" with your IDE or Notepad or NotePad++. From there it will describe with comments (the stuff after "//") on how to use such items. If you are still confused/cannot open the file, then here is the example cs codes for the most important stuff.

Projectiles
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Terraria;
using Terraria.ModLoader;

namespace MPT.Projectiles //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{   
    public class ExampleBulletA : ModProjectile 
    {
        public override void SetDefaults()
        {
            projectile.name = "Example Bullet A"; //Name of the projectile, only shows this if you get killed by it
            projectile.width = 36; //Set the hitbox width
            projectile.height = 36; //Set the hitbox height
            projectile.timeLeft = 60; //The amount of time the projectile is alive for
            projectile.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.friendly = true; //Tells the game whether it is friendly to players/friendly npcs or not
            projectile.hostile = false; //Tells the game whether it is hostile to players or not
            projectile.tileCollide = true; //Tells the game whether or not it can collide with a tile
            projectile.ignoreWater = true; //Tells the game whether or not projectile will be affected by water
            projectile.ranged = true; //Tells the game whether it is a ranged projectile or not
            projectile.aiStyle = 0; //How the projectile works, 0 makes the projectile just go straight towards your cursor
        }
       
        //How the projectile works
        public override void AI()
        {
            Player owner = Main.player[projectile.owner]; //Makes a player variable of owner set as the player using the projectile
            projectile.light = 0.9f; //Lights up the whole room
            projectile.alpha = 128; //Semi Transparent
            projectile.rotation += (float)projectile.direction * 0.8f; //Spins in a good speed
            int DustID = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 2f), projectile.width + 4, projectile.height + 4, 36, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 120, default(Color), 0.75f); //Spawns dust
            Main.dust[DustID].noGravity = true; //Makes dust not fall
            if(projectile.timeLeft % 15 == 0) //If the remainder of the timeLeft divided 15 is 0, then make the projectile; Every 15 seconds, projectile spawns another projectile
            {
                Projectile.NewProjectile(projectile.position.X, projectile.position.Y, MathHelper.Lerp(-1f, 1f, (float)Main.rand.NextDouble()), MathHelper.Lerp(-1f, 1f, (float)Main.rand.NextDouble()), mod.ProjectileType("ExampleBulletB"), 5 * (int)owner.rangedDamage, projectile.knockBack, Main.myPlayer); //owner.rangedDamage is basically the damage multiplier for ranged weapons
            }
        }
       
        //When you hit an NPC
        public override void OnHitNPC(NPC n, int damage, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            int rand = Main.rand.Next(2); //Generates an integer from 0 to 1
            if(rand == 0)
            {
                n.AddBuff(24, 180); //On Fire! debuff for 3 seconds
            }
            else if (rand == 1)
            {
                owner.statLife += 5; //Gives 5 Health
                owner.HealEffect(5, true); //Shows you have healed by 5 health
            }
        }
       
        //When the projectile hits a tile
        public override bool OnTileCollide(Vector2 velocityChange)  
        {
            if (projectile.velocity.X != velocityChange.X)
            {
                projectile.velocity.X = -velocityChange.X/2; //Goes in the opposite direction with half of its x velocity
            }
            if (projectile.velocity.Y != velocityChange.Y)
            {
                projectile.velocity.Y = -velocityChange.Y/2; //Goes in the opposite direction with half of its y velocity
            }
            return false;
        }
       
        //After the projectile is dead
        public override void Kill(int timeLeft)
        {
            int rand = Main.rand.Next(5); //Generates integers from 0 to 4
            Projectile.NewProjectile(projectile.position.X, projectile.position.Y, 0, 0, 296, (int) (projectile.damage * 1.5), projectile.knockBack, Main.myPlayer); // 296 is the explosion from the Inferno Fork
            if(rand == 0)
            {
                Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, mod.ItemType("ExampleBulletA"), 1, false, 0, false); //Spawns a bullet
            }
        }
    }
}

Items
Code:
using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MPT.Items
{
    public class ExampleBulletA : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Example Bullet A";
            item.damage = 10; //This is added with the weapon's damage
            item.ranged = true; 
            item.width = 14;
            item.height = 32;
            item.maxStack = 999;
            item.toolTip = "Example Bullet A";
            item.consumable = true; //Tells the game that this should be used up once fired
            item.knockBack = 1f; //Added with the weapon's knockback
            item.value = 500;
            item.rare = 2;
            item.shoot = mod.ProjectileType("ExampleBulletA");
            item.shootSpeed = 7f; //Added to the weapon's shoot speed
            item.ammo = mod.ItemType("ExampleBulletA"); //Tells the game that it should be considered the same type of ammo as this item
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(this, 111);
            recipe.AddRecipe();
        }
    }
}
Code:
using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ID; //We are borrowing properties from IDs to easily make a Recipe
using Terraria.ModLoader;

namespace MPT.Items
{
public class ExampleGun : ModItem
{
        public override void SetDefaults()
        {
            item.name = "Example Gun"; //Its display name
            item.damage = 20; //The damage
            item.ranged = true; //Whether or not it is a ranged weapon
            item.width = 60; //Item width
            item.height = 60; //Item height
            item.maxStack = 1; //How many of this item you can stack
            item.toolTip = "An example gun."; //The item’s tooltip
            item.useTime = 10; //How long it takes for the item to be used
            item.useAnimation = 39; //How long the animation of the item takes
            item.knockBack = 7f; //How much knockback the item produces
            item.useSound = 12; //The soundeffect played when used 
            item.noMelee = true; //Whether the weapon should do melee damage or not
            item.useStyle = 5; //How the weapon is held, 5 is the gun hold style
            item.value = 1; //How much the item is worth
            item.rare = 1; //The rarity of the item
            item.shoot = mod.ProjectileType("ExampleBulletA"); //What the item shoots, retains an int value | *
            item.shootSpeed = 1f; //How fast the projectile fires   
            item.useAmmo = mod.ItemType("ExampleBulletA"); //Tells the game what type of ammo to use       
            item.autoReuse = true; //Whether it automatically uses the item again after its done being used/animated
        }
        public override void AddRecipes() //Adding recipes
        {
            ModRecipe recipe = new ModRecipe(mod); //Creating a new recipe to be added to 
            recipe.AddIngredient(ItemID.DirtBlock); //Setting the ingredient to the item as a Dirt Block
            recipe.SetResult(this); //Set the result of the recipe to this item (this refers to the class itself)
            recipe.AddRecipe(); //Add this recipe
        }
        public override bool ConsumeAmmo(Player p) //Tells the game whether the item consumes ammo or not
        {
            int rand = Main.rand.Next(9); //A random chance... once again
            if(p.itemAnimation < p.inventory[p.selectedItem].useAnimation - 25) //Consumes ammo near the end of the item's animation
            {
                    return true; //Ammo is consumed
            }
            else
            {
                return false; //Ammo is not consumed before animation is finished
            }
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) //This lets you modify the firing of the item
        {
            /*Code is made by berberborscing*/
            int spread = 30; //The angle of random spread.
            float spreadMult = 0.1f; //Multiplier for bullet spread, set it higher and it will make for some outrageous spread.
            for (int i = 0; i < 3; i++)
            {
                float vX = speedX +(float)Main.rand.Next(-spread,spread+1) * spreadMult;
                float vY = speedY +(float)Main.rand.Next(-spread,spread+1) * spreadMult;
                Projectile.NewProjectile(position.X, position.Y, vX, vY, type, damage, knockBack, Main.myPlayer);
            }
            return false; //Makes sure to not spawn the original projectile
        }
    }
}
 
You can just download the example mod on the first post of this thread. The file is called "MPT.zip". You need to open and extract it to any location and then you should be able to look through the code in any of the folders. The rotation thing that you are looking for would be in the folder called something like "projectiles" and go open "Example Bullet A" with your IDE or Notepad or NotePad++. From there it will describe with comments (the stuff after "//") on how to use such items. If you are still confused/cannot open the file, then here is the example cs codes for the most important stuff.

Projectiles
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Terraria;
using Terraria.ModLoader;

namespace MPT.Projectiles //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{  
    public class ExampleBulletA : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Example Bullet A"; //Name of the projectile, only shows this if you get killed by it
            projectile.width = 36; //Set the hitbox width
            projectile.height = 36; //Set the hitbox height
            projectile.timeLeft = 60; //The amount of time the projectile is alive for
            projectile.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.friendly = true; //Tells the game whether it is friendly to players/friendly npcs or not
            projectile.hostile = false; //Tells the game whether it is hostile to players or not
            projectile.tileCollide = true; //Tells the game whether or not it can collide with a tile
            projectile.ignoreWater = true; //Tells the game whether or not projectile will be affected by water
            projectile.ranged = true; //Tells the game whether it is a ranged projectile or not
            projectile.aiStyle = 0; //How the projectile works, 0 makes the projectile just go straight towards your cursor
        }
      
        //How the projectile works
        public override void AI()
        {
            Player owner = Main.player[projectile.owner]; //Makes a player variable of owner set as the player using the projectile
            projectile.light = 0.9f; //Lights up the whole room
            projectile.alpha = 128; //Semi Transparent
            projectile.rotation += (float)projectile.direction * 0.8f; //Spins in a good speed
            int DustID = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 2f), projectile.width + 4, projectile.height + 4, 36, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 120, default(Color), 0.75f); //Spawns dust
            Main.dust[DustID].noGravity = true; //Makes dust not fall
            if(projectile.timeLeft % 15 == 0) //If the remainder of the timeLeft divided 15 is 0, then make the projectile; Every 15 seconds, projectile spawns another projectile
            {
                Projectile.NewProjectile(projectile.position.X, projectile.position.Y, MathHelper.Lerp(-1f, 1f, (float)Main.rand.NextDouble()), MathHelper.Lerp(-1f, 1f, (float)Main.rand.NextDouble()), mod.ProjectileType("ExampleBulletB"), 5 * (int)owner.rangedDamage, projectile.knockBack, Main.myPlayer); //owner.rangedDamage is basically the damage multiplier for ranged weapons
            }
        }
      
        //When you hit an NPC
        public override void OnHitNPC(NPC n, int damage, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            int rand = Main.rand.Next(2); //Generates an integer from 0 to 1
            if(rand == 0)
            {
                n.AddBuff(24, 180); //On Fire! debuff for 3 seconds
            }
            else if (rand == 1)
            {
                owner.statLife += 5; //Gives 5 Health
                owner.HealEffect(5, true); //Shows you have healed by 5 health
            }
        }
      
        //When the projectile hits a tile
        public override bool OnTileCollide(Vector2 velocityChange) 
        {
            if (projectile.velocity.X != velocityChange.X)
            {
                projectile.velocity.X = -velocityChange.X/2; //Goes in the opposite direction with half of its x velocity
            }
            if (projectile.velocity.Y != velocityChange.Y)
            {
                projectile.velocity.Y = -velocityChange.Y/2; //Goes in the opposite direction with half of its y velocity
            }
            return false;
        }
      
        //After the projectile is dead
        public override void Kill(int timeLeft)
        {
            int rand = Main.rand.Next(5); //Generates integers from 0 to 4
            Projectile.NewProjectile(projectile.position.X, projectile.position.Y, 0, 0, 296, (int) (projectile.damage * 1.5), projectile.knockBack, Main.myPlayer); // 296 is the explosion from the Inferno Fork
            if(rand == 0)
            {
                Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, mod.ItemType("ExampleBulletA"), 1, false, 0, false); //Spawns a bullet
            }
        }
    }
}

Items
Code:
using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MPT.Items
{
    public class ExampleBulletA : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Example Bullet A";
            item.damage = 10; //This is added with the weapon's damage
            item.ranged = true;
            item.width = 14;
            item.height = 32;
            item.maxStack = 999;
            item.toolTip = "Example Bullet A";
            item.consumable = true; //Tells the game that this should be used up once fired
            item.knockBack = 1f; //Added with the weapon's knockback
            item.value = 500;
            item.rare = 2;
            item.shoot = mod.ProjectileType("ExampleBulletA");
            item.shootSpeed = 7f; //Added to the weapon's shoot speed
            item.ammo = mod.ItemType("ExampleBulletA"); //Tells the game that it should be considered the same type of ammo as this item
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(this, 111);
            recipe.AddRecipe();
        }
    }
}
Code:
using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ID; //We are borrowing properties from IDs to easily make a Recipe
using Terraria.ModLoader;

namespace MPT.Items
{
public class ExampleGun : ModItem
{
        public override void SetDefaults()
        {
            item.name = "Example Gun"; //Its display name
            item.damage = 20; //The damage
            item.ranged = true; //Whether or not it is a ranged weapon
            item.width = 60; //Item width
            item.height = 60; //Item height
            item.maxStack = 1; //How many of this item you can stack
            item.toolTip = "An example gun."; //The item’s tooltip
            item.useTime = 10; //How long it takes for the item to be used
            item.useAnimation = 39; //How long the animation of the item takes
            item.knockBack = 7f; //How much knockback the item produces
            item.useSound = 12; //The soundeffect played when used
            item.noMelee = true; //Whether the weapon should do melee damage or not
            item.useStyle = 5; //How the weapon is held, 5 is the gun hold style
            item.value = 1; //How much the item is worth
            item.rare = 1; //The rarity of the item
            item.shoot = mod.ProjectileType("ExampleBulletA"); //What the item shoots, retains an int value | *
            item.shootSpeed = 1f; //How fast the projectile fires  
            item.useAmmo = mod.ItemType("ExampleBulletA"); //Tells the game what type of ammo to use      
            item.autoReuse = true; //Whether it automatically uses the item again after its done being used/animated
        }
        public override void AddRecipes() //Adding recipes
        {
            ModRecipe recipe = new ModRecipe(mod); //Creating a new recipe to be added to
            recipe.AddIngredient(ItemID.DirtBlock); //Setting the ingredient to the item as a Dirt Block
            recipe.SetResult(this); //Set the result of the recipe to this item (this refers to the class itself)
            recipe.AddRecipe(); //Add this recipe
        }
        public override bool ConsumeAmmo(Player p) //Tells the game whether the item consumes ammo or not
        {
            int rand = Main.rand.Next(9); //A random chance... once again
            if(p.itemAnimation < p.inventory[p.selectedItem].useAnimation - 25) //Consumes ammo near the end of the item's animation
            {
                    return true; //Ammo is consumed
            }
            else
            {
                return false; //Ammo is not consumed before animation is finished
            }
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) //This lets you modify the firing of the item
        {
            /*Code is made by berberborscing*/
            int spread = 30; //The angle of random spread.
            float spreadMult = 0.1f; //Multiplier for bullet spread, set it higher and it will make for some outrageous spread.
            for (int i = 0; i < 3; i++)
            {
                float vX = speedX +(float)Main.rand.Next(-spread,spread+1) * spreadMult;
                float vY = speedY +(float)Main.rand.Next(-spread,spread+1) * spreadMult;
                Projectile.NewProjectile(position.X, position.Y, vX, vY, type, damage, knockBack, Main.myPlayer);
            }
            return false; //Makes sure to not spawn the original projectile
        }
    }
}
Thanks a lot! :)
 
Thanks for the tip! Do you have any boss ai tutorials too? If you do, let me know :)
I do not have a boss tutorial, however there is a boss tutorial already, though it is for a different mod loader, it should be still relevant since it is still using vanilla code. If you have any problems, you can refer to my fully custom boss that I have done here. This is a conglomerate boss that has a main boss and sub bosses. It is fully custom made based on my coding of projectiles. So yeah, I guess you can say that doing projectiles prepares you for npcs and vice versa.
 
So I am trying to get a "Throwing style melee weapon" to work...

What I want the weapon to do is throw a random amount of projectiles in a similar way to vampire knives.

Here's the projectile CS

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TerraCompilation.Projectiles
{
   public class CopperSS : ModProjectile
  {
  public override void SetDefaults()
  {
  projectile.name = "Thrown Copper Shortsword";
  projectile.width = 10;
  projectile.height = 44;
  projectile.timeLeft = 120;
  projectile.penetrate = 0;
  projectile.friendly = true;
  projectile.hostile = false;
  projectile.tileCollide = true;
  projectile.ignoreWater = true;
  projectile.ranged = true;
  projectile.aiStyle = 0;
  }
  }
}

And this is the item CS itself
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using TerraCompilation.Items;

namespace TerraCompilation.Items.Weapons
{
   public class Copperhand : ModItem
   {
     public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
   {
     texture = "TerraCompilation/Items/Weapons/Copperhand";
     return true;
   }
     public override void SetDefaults()
     {
       item.name = "Copperhand";
       item.damage = 85;
       item.melee = true;
       item.noUseGraphic = true;
       item.width = 2;
       item.height = 2;
       item.toolTip = "Throw copper shortswords at your foes!";
       item.toolTip = "It's about time the copper shortsword got its revenge!";
       item.useTime = 10;
       item.useAnimation = 10;
       item.useStyle = 1;
       item.noMelee = true;
       item.knockBack = 2;
       item.value = 263000;
       item.rare = 4;
       item.UseSound = SoundID.Item1;
       item.autoReuse = true;
       item.shoot = mod.ProjectileType("CopperSS");
       item.shootSpeed = 10f;
       item.expert = true;
     }
     
     public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
     {
       int numberProjectiles = 2 + Main.rand.Next(8);
       for (int i = 0; i < numberProjectiles; i++)
       {
         Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(10));
         Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
       }
       return false;
     }
     
     public override void AddRecipes()
     {
       ModRecipe recipe = new ModRecipe(mod);
       recipe.AddIngredient(ItemID.LunarBar, 30);
       recipe.AddIngredient(null, "Unknownparts", 1);
       recipe.AddTile(TileID.LunarCraftingStation);
       recipe.SetResult(this);
       recipe.AddRecipe();
     }
   }
}

Yet whatever I do, I can't get it to fire the projectiles, it does its animations but never shoots.
I'm sure theres an error in there that my newbie brain can't see, so if an expert can tell me where I screwed up I'd be mighty thankful. :)
 
maybe i can help
Replace
Code:
item.shoot = mod.ProjectileType("CopperSS");  with  item.shoot = 10;
And on
Code:
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI); Replace type with mod.ProjectileType("CopperSS");
 
maybe i can help
Replace
Code:
item.shoot = mod.ProjectileType("CopperSS");  with  item.shoot = 10;
And on
Code:
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI); Replace type with mod.ProjectileType("CopperSS");

Nope, it just errors expecting a ; when there's one there...
Gotta love how blind C# is at times...
 
maybe i can help
Replace
Code:
item.shoot = mod.ProjectileType("CopperSS");  with  item.shoot = 10;
And on
Code:
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI); Replace type with mod.ProjectileType("CopperSS");
Sorry my mistake. just mod.ProjectileType("CopperSS") without ;
 
Just have the shoot value of the item as the ID number or use TerrariaID like this...

Code:
item.shoot = 405; //Literal integer ID of Flairon Bubble
item.shoot = ProjectileID.FlaironBubble; //Must have "using Terraria.ID;" at the top
I don't know if you're doing the modding thing anymore, but I have a question.
The gun won't shoot a projectile when I use it.
Here's my code
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace TerrariaUnlimited.Items
{
    public class OnyxRepeater : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Onyx Repeater";
            item.damage = 38;
            item.ranged = true;
            item.width = 68;
            item.height = 25;
            item.toolTip = "This is currently a test";
            item.useTime = 10;
            item.useAnimation = 20;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 4;
            item.value = 10000;
            item.rare = 5;
            item.UseSound = SoundID.Item38;
            item.autoReuse = true;
            item.shoot = 661; //The Onyx Blaster's projectile
            item.shootSpeed = 4f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.OnyxBlaster, 1);
            recipe.AddIngredient(ItemID.HallowedBar, 15);
            recipe.AddTile(TileID.MythrilAnvil);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
In place of item.shoot = 661; I have used item.shoot = projectileID.OnyxBlaster; and that doesn't work either.
 
I don't know if you're doing the modding thing anymore, but I have a question.
The gun won't shoot a projectile when I use it.
Here's my code
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace TerrariaUnlimited.Items
{
    public class OnyxRepeater : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Onyx Repeater";
            item.damage = 38;
            item.ranged = true;
            item.width = 68;
            item.height = 25;
            item.toolTip = "This is currently a test";
            item.useTime = 10;
            item.useAnimation = 20;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 4;
            item.value = 10000;
            item.rare = 5;
            item.UseSound = SoundID.Item38;
            item.autoReuse = true;
            item.shoot = 661; //The Onyx Blaster's projectile
            item.shootSpeed = 4f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.OnyxBlaster, 1);
            recipe.AddIngredient(ItemID.HallowedBar, 15);
            recipe.AddTile(TileID.MythrilAnvil);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
In place of item.shoot = 661; I have used item.shoot = projectileID.OnyxBlaster; and that doesn't work either.
Are you getting an error when using ProjectileID instead of an integer number, or are you getting the same behaviour?

EDIT:
The ProjectileID is faulty. If you want to use it, ProjecileID.BlackBolt is the right ID.
 
Last edited:
Are you getting an error when using ProjectileID instead of an integer number, or are you getting the same behaviour?

EDIT:
The ProjectileID is faulty. If you want to use it, ProjecileID.BlackBolt is the right ID.

I am not getting any error at all. The gun just shoots bullets, and nothing else. I will try the projectile name. I was using the Terraria Wiki's page on Data ID's for this btw
Thanks!
 
I am not getting any error at all. The gun just shoots bullets, and nothing else. I will try the projectile name. I was using the Terraria Wiki's page on Data ID's for this btw
Thanks!
Ah of course that makes sense....
One thing you can try is the following:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    type = ProjectileID.BlackBolt;
    return true;
}
You'll want to place this method in your item class.

If you do not know what this does:
We basically intercept this weapon shooting his projectile right before it actually happens, which allows us to change around some variables (such as the position it's shot from, the velocity it's shot with, damage, knockback, etc.) including the type of the bullet that is shot. In this case it overrides every bullet type (with some if statements, you can check if a specific type of bullet is fired). returning true at the end of the method allows vanilla code to execute (if you return false, you can do your own projectile spawning).

Hope this helps!
 
Back
Top Bottom