tAPI [Tutorial] Projectile Guide and Implementation

okay so this is the code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class PulsingDarkness2 : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.CultistBossFireBallClone);
            projectile.name = "Death Sickle";
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.timeLeft = 900;
            aiType = ProjectileID.CultistBossFireBallClone;     

        }

    }
}

so when this dies or lands, it leaves a dark particle then i need to pass through it to make it explode
[doublepost=1494601283,1494601209][/doublepost]Also, this error poped up when I add the code you gave me
c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Items\Weapons\Magic\SkysBlessing.cs(33,17) : error CS1061: 'Terraria.Utilities.UnifiedRandom' does not contain a definition for 'next' and no extension method 'next' accepting a first argument of type 'Terraria.Utilities.UnifiedRandom' could be found (are you missing a using directive or an assembly reference?)
 

Attachments

  • DarkParticle.png
    DarkParticle.png
    496.5 KB · Views: 200
  • DarkExplosion.png
    DarkExplosion.png
    324.5 KB · Views: 174
okay so this is the code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class PulsingDarkness2 : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.CultistBossFireBallClone);
            projectile.name = "Death Sickle";
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.timeLeft = 900;
            aiType = ProjectileID.CultistBossFireBallClone;    

        }

    }
}

so when this dies or lands, it leaves a dark particle then i need to pass through it to make it explode
[doublepost=1494601283,1494601209][/doublepost]Also, this error poped up when I add the code you gave me
c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Items\Weapons\Magic\SkysBlessing.cs(33,17) : error CS1061: 'Terraria.Utilities.UnifiedRandom' does not contain a definition for 'next' and no extension method 'next' accepting a first argument of type 'Terraria.Utilities.UnifiedRandom' could be found (are you missing a using directive or an assembly reference?)
Sorry, it should be "Next", not "next".

The reason your projectile isn't working because it is built into the AI style, meaning that it will ONLY explode when it intercepts a player. You would have to code this projectile yourself.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace YourModName.Items.Weapons.Magic        //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class SkysBlessing : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Sky's Blessing"; //the name displayed when hovering over the Weapon ingame.      
            item.damage = 13;   //The damage stat for the Weapon.                    
            item.magic = true;   //This defines if it does magic damage and if its effected by magic increasing Armor/Accessories.
            item.width = 24;      //The size of the width of the hitbox in pixels.
            item.height = 28;      //The size of the height of the hitbox in pixels.
            item.toolTip = "Rains down a hail of feathers.";  //The description of the Weapon shown when hovering over the Weapon ingame.
            item.useTime = 20;     //How fast the Weapon is used.
            item.useAnimation = 40;
            item.useStyle = 5; //How long the Weapon is used for.
            Item.staff[item.type] = true; //this makes the useStyle animate as a staff instead of as a gu         //The way your Weapon will be used, 5 is the Holding Out Used for: Guns, Spellbooks, Drills, Chainsaws, Flails, Spears for example
            item.noMelee = true;     //Setting to True allows the weapon sprite to stop doing damage, so only the projectile does the damge
            item.knockBack = 8;  //The knockback stat of your Weapon.    
            item.value = Item.buyPrice(0, 10, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
            item.rare = 6;   //The color the title of your Weapon when hovering over it ingame
            item.mana = 17;//How many mana this weapon use
            item.UseSound = SoundID.Item13; //item.UseSound = SoundID.Item1;   //The sound played when using your Weapon
            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.
            item.shoot = mod.ProjectileType("SkysBlessing");//This defines what type of projectile this weapon will shoot
            item.shootSpeed = 15f;    //This defines the projectile speed when shoot

            if(Main.rand.Next(5) == 0)
            {
               type = mod.ProjectileType("SkysBlessing");
            }
               else
            {
               type = mod.ProjectileType("SkysBlessing2");
            }

        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Feather, 30);
            recipe.AddIngredient(ItemID.RainCloud, 15);//in this example you see how to add your custom item to the crafting recipe
            recipe.AddTile(TileID.SkyMill);     //in this example you see how to add your custom craftingbench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        //-----------------------------------------------StarWrath projectile style----------------------------------------------
        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 = 7 + Main.rand.Next(2);  //This defines how many projectiles to shot
            for (int index = 0; index < numberProjectiles; ++index)
            {
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(201) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //this defines the projectile width, direction and position
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-200, 201);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-40, 41) * 0.02f;  //this defines the projectile X position speed and randomnes
                float SpeedY = num17 + (float)Main.rand.Next(-40, 41) * 0.02f;  //this defines the projectile Y position speed and randomnes
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX, SpeedY, type, damage, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
            }
            return false;
        }
    }
}

this is my code.
 
Last edited:
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace YourModName.Items.Weapons.Magic        //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class SkysBlessing : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Sky's Blessing"; //the name displayed when hovering over the Weapon ingame.     
            item.damage = 13;   //The damage stat for the Weapon.                   
            item.magic = true;   //This defines if it does magic damage and if its effected by magic increasing Armor/Accessories.
            item.width = 24;      //The size of the width of the hitbox in pixels.
            item.height = 28;      //The size of the height of the hitbox in pixels.
            item.toolTip = "Rains down a hail of feathers.";  //The description of the Weapon shown when hovering over the Weapon ingame.
            item.useTime = 20;     //How fast the Weapon is used.
            item.useAnimation = 40;
            item.useStyle = 5; //How long the Weapon is used for.
            Item.staff[item.type] = true; //this makes the useStyle animate as a staff instead of as a gu         //The way your Weapon will be used, 5 is the Holding Out Used for: Guns, Spellbooks, Drills, Chainsaws, Flails, Spears for example
            item.noMelee = true;     //Setting to True allows the weapon sprite to stop doing damage, so only the projectile does the damge
            item.knockBack = 8;  //The knockback stat of your Weapon.   
            item.value = Item.buyPrice(0, 10, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
            item.rare = 6;   //The color the title of your Weapon when hovering over it ingame
            item.mana = 17;//How many mana this weapon use
            item.UseSound = SoundID.Item13; //item.UseSound = SoundID.Item1;   //The sound played when using your Weapon
            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.
            item.shoot = mod.ProjectileType("SkysBlessing");//This defines what type of projectile this weapon will shoot
            item.shootSpeed = 15f;    //This defines the projectile speed when shoot

            if(Main.rand.Next(5) == 0)
            {
               type = mod.ProjectileType("SkysBlessing");
            }
               else
            {
               type = mod.ProjectileType("SkysBlessing2");
            }

        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Feather, 30);
            recipe.AddIngredient(ItemID.RainCloud, 15);//in this example you see how to add your custom item to the crafting recipe
            recipe.AddTile(TileID.SkyMill);     //in this example you see how to add your custom craftingbench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        //-----------------------------------------------StarWrath projectile style----------------------------------------------
        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 = 7 + Main.rand.Next(2);  //This defines how many projectiles to shot
            for (int index = 0; index < numberProjectiles; ++index)
            {
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(201) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //this defines the projectile width, direction and position
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-200, 201);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-40, 41) * 0.02f;  //this defines the projectile X position speed and randomnes
                float SpeedY = num17 + (float)Main.rand.Next(-40, 41) * 0.02f;  //this defines the projectile Y position speed and randomnes
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX, SpeedY, type, damage, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
            }
            return false;
        }
    }
}

this is my code.
That's still just your item file, I need to see your projectile file.

How can I make my projectile use a custom sound that I added?
Are you using tAPI or tModLoader?

For tAPI, I don't think there is.

For tModLoader, you can use

Code:
mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Directory/To/Sound");
 
That's still just your item file, I need to see your projectile file.


Are you using tAPI or tModLoader?

For tAPI, I don't think there is.

For tModLoader, you can use

Code:
mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Directory/To/Sound");


Where do I put that code? If I paste it into my projectile code I just get errors. This is what my projectile code looks like:

Code:
using Terraria.ModLoader;
using Terraria.ID;


namespace hyperfrostw.Projectiles
{
    public class swordbeam : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.TerraBeam);
            projectile.name = "Sword Beam";
            aiType = ProjectileID.TerraBeam;
           
        }

      

        public override bool Autoload(ref string name, ref string texture)
        {
            texture = "Terraria/Projectile_" + ProjectileID.TerraBeam;
           
            return true;
        }
    }
}

I can add that line of code you gave me to my sword class as item.UseSound and it work just fine, but I don't want to change the sound of the sword swing. I want to change the sound of the projectile it shoots.

Thanks
 
Where do I put that code? If I paste it into my projectile code I just get errors. This is what my projectile code looks like:

Code:
using Terraria.ModLoader;
using Terraria.ID;


namespace hyperfrostw.Projectiles
{
    public class swordbeam : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.TerraBeam);
            projectile.name = "Sword Beam";
            aiType = ProjectileID.TerraBeam;
          
        }

     

        public override bool Autoload(ref string name, ref string texture)
        {
            texture = "Terraria/Projectile_" + ProjectileID.TerraBeam;
          
            return true;
        }
    }
}

I can add that line of code you gave me to my sword class as item.UseSound and it work just fine, but I don't want to change the sound of the sword swing. I want to change the sound of the projectile it shoots.

Thanks
Since you are using a default AI style, you unfortunately, can't change the sound since the sound is built into the style. So in order to do the thingy, you have to make your own AI as with most of the projectile related problems are when using vanilla AIs.
 
Since you are using a default AI style, you unfortunately, can't change the sound since the sound is built into the style. So in order to do the thingy, you have to make your own AI as with most of the projectile related problems are when using vanilla AIs.

Hmm. Projectiles that travel in a straight line such as the TerraBeam don't require an AI style, right?
 
Okay so this is the blue feather file:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class SkysBlessing : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.Blizzard);
            projectile.name = "Death Sickle";
            projectile.friendly = true;
            projectile.hostile = false;
            aiType = ProjectileID.Blizzard;     

        }
        //After the projectile is dead
        public override void Kill(int timeLeft)
        {
            Projectile.NewProjectile(projectile.position.X, projectile.position.Y, 0, 0, ProjectileID.MonkStaffT3_AltShot, (int)(projectile.damage * 1.5), projectile.knockBack, Main.myPlayer); // This spawns a projectile after this projectile is dead
        }
    }
}

and then this is the golden feather file:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class SkysBlessing2 : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.FrostWave);
            projectile.name = "Death Sickle";
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.damage = 20;
            aiType = ProjectileID.FrostWave;     

        }

    }
}
 
Also another question, i saw your tutorial for how to make an explosion but it gave me this error:

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Projectiles\PulsingDarkness2.cs(10,30) : error CS0115: 'YourModName.Projectiles.PulsingDarkness2.PostKill()': no suitable method found to override

here is the code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class PulsingDarkness2 : ModProjectile
    {
        public override void PostKill()
        {
            Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14);
            for (int num369 = 0; num369 < 20; num369++)
            {
                int num370 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[num370].velocity *= 1.4f;
            }
            for (int num371 = 0; num371 < 10; num371++)
            {
                int num372 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f);
                Main.dust[num372].noGravity = true;
                Main.dust[num372].velocity *= 5f;
                num372 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[num372].velocity *= 3f;
            }
            int num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore85 = Main.gore[num373];
            gore85.velocity.X = gore85.velocity.X + 1f;
            Gore gore86 = Main.gore[num373];
            gore86.velocity.Y = gore86.velocity.Y + 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore87 = Main.gore[num373];
            gore87.velocity.X = gore87.velocity.X - 1f;
            Gore gore88 = Main.gore[num373];
            gore88.velocity.Y = gore88.velocity.Y + 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore89 = Main.gore[num373];
            gore89.velocity.X = gore89.velocity.X + 1f;
            Gore gore90 = Main.gore[num373];
            gore90.velocity.Y = gore90.velocity.Y - 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore91 = Main.gore[num373];
            gore91.velocity.X = gore91.velocity.X - 1f;
            Gore gore92 = Main.gore[num373];
            gore92.velocity.Y = gore92.velocity.Y - 1f;
        }
    }
}
 
Also another question, i saw your tutorial for how to make an explosion but it gave me this error:

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Projectiles\PulsingDarkness2.cs(10,30) : error CS0115: 'YourModName.Projectiles.PulsingDarkness2.PostKill()': no suitable method found to override

here is the code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Projectiles
{
    public class PulsingDarkness2 : ModProjectile
    {
        public override void PostKill()
        {
            Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14);
            for (int num369 = 0; num369 < 20; num369++)
            {
                int num370 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[num370].velocity *= 1.4f;
            }
            for (int num371 = 0; num371 < 10; num371++)
            {
                int num372 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f);
                Main.dust[num372].noGravity = true;
                Main.dust[num372].velocity *= 5f;
                num372 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[num372].velocity *= 3f;
            }
            int num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore85 = Main.gore[num373];
            gore85.velocity.X = gore85.velocity.X + 1f;
            Gore gore86 = Main.gore[num373];
            gore86.velocity.Y = gore86.velocity.Y + 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore87 = Main.gore[num373];
            gore87.velocity.X = gore87.velocity.X - 1f;
            Gore gore88 = Main.gore[num373];
            gore88.velocity.Y = gore88.velocity.Y + 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore89 = Main.gore[num373];
            gore89.velocity.X = gore89.velocity.X + 1f;
            Gore gore90 = Main.gore[num373];
            gore90.velocity.Y = gore90.velocity.Y - 1f;
            num373 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num373].velocity *= 0.4f;
            Gore gore91 = Main.gore[num373];
            gore91.velocity.X = gore91.velocity.X - 1f;
            Gore gore92 = Main.gore[num373];
            gore92.velocity.Y = gore92.velocity.Y - 1f;
        }
    }
}
I don't see a PostKill in the documentation: http://bluemagic123.github.io/tModLoader/html/class_terraria_1_1_mod_loader_1_1_mod_projectile.html
 
Oh, so what should be the right one when I want to make an explosion?
[doublepost=1494662952,1494662664][/doublepost]wait nevermind I did it!
[doublepost=1494663131][/doublepost]Okay so it worked! but what should be the right sprite image? Because mine just turns to a box when it lands (Because that is my sprite).
 
Okay so how can i make my weapon fire projectiles from left to right? or from bottom to top?
[doublepost=1496062492,1496062316][/doublepost]Also, how could i make my weapon fire different projectiles at the same time when used?
 
Okay so how can i make my weapon fire projectiles from left to right? or from bottom to top?
[doublepost=1496062492,1496062316][/doublepost]Also, how could i make my weapon fire different projectiles at the same time when used?
Is this for tModLoader or tAPI?
 
How do I make a modded projectile pass through tiles, but becomes solid when it reaches the cursor? I'm using tModLoader, btw. :)
 
Back
Top Bottom