tModLoader [Tutorial] Projectile Guide and Implementation: tModLoader Edition

Im getting this error
"Uses(42,78) : error CS0120: An object reference is required for the non-static field, method, or property 'Terraria.Entity.Center.get'"
with these two lines from the homing projectile code
(same error for both)

float shootToY = target.position.Y - NPC.Center.Y;
float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

Edit: I changed the NPC.Center to target.Center, but now the projectiles just fire straight up
 
Last edited:
Add this:
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) //put this AFTER SetDefaults
        {
            Projectile.NewProjectile(position.X, position.Y, speedX, speedY, 668, damage, knockBack, player.whoAmI); //shoot an additional projectile, in this case 668 or Flameburst Fireball
            return true; //shoot the bullet afterwards
        }
The name 'Player' could not be found
 
Cant make code for rocket using this guide...
Help ive been at it for so long and have no clue what to do now lol. Anyone got some code I can use and edit? (Projectile and rocket item)
 
I got it working, but now the weapon is flickering on and off quickly, is there a way to prevent it? Here's the codes I have:
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;

namespace JoshuasMod.Items.Weapons.Nirvana
{
    public class Nirvana : ModItem
    {
        public override void SetDefaults()
        {
            item.useStyle = 1;
            item.UseSound = SoundID.Item71;
            item.scale = 0.55f;
            item.damage = 1000;
            item.width = 64;
            item.height = 68;
            item.useTime = 10;
            item.useAnimation = 10;
            item.autoReuse = true;
            item.melee = false;
            item.expert = true;
            item.useTurn = true;
            }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.CursedInferno, 300);        //Add CursedInferno buff to the NPC for 5 seconds.

            int healingAmount = damage/50;
            player.statLife +=healingAmount;
            player.HealEffect(healingAmount, true);
        }
      
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)
            {
                item.CloneDefaults(ItemID.Arkhalis);
                item.useStyle = 5;
                item.UseSound = SoundID.Item1;
                item.damage = 1000;
                item.useTime = 24;
                item.useAnimation = 24;
                item.shootSpeed = 18f;
                item.shoot = mod.ProjectileType("NirvanaSlash");
                item.useTurn = false;
                item.noUseGraphic = true;
                item.channel = true;
            }
            else
            {
                item.useStyle = 1;
                item.UseSound = SoundID.Item71;
                item.scale = 0.55f;
                item.damage = 1000;
                item.width = 64;
                item.height = 68;
                item.useTime = 10;
                item.useAnimation = 10;
                item.autoReuse = true;
                item.melee = false;
                item.expert = true;
                item.useTurn = true;
            }
            return base.CanUseItem(player);
        }
      
        public override void AddRecipes() //Cannot add more than 14 items in the recipe, including modded items.
        {
        ModRecipe recipe = new ModRecipe(mod);
        //Vanilla items in the recipe.
        recipe.AddIngredient(ItemID.Arkhalis, 1);
        recipe.AddIngredient(ItemID.Muramasa, 1);
        recipe.AddIngredient(ItemID.LunarBar, 20);
        recipe.AddIngredient(ItemID.HallowedBar, 20);
        recipe.AddIngredient(ItemID.ChlorophyteBar, 20);
        recipe.AddIngredient(ItemID.BrokenHeroSword, 1);
        //Workbench the item is crafted at.
        recipe.AddTile(TileID.LunarCraftingStation);
        recipe.SetResult(this, 1);
        recipe.AddRecipe();
        }
    }
}
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;

namespace JoshuasMod.Projectiles.Nirvana
{
    public class NirvanaSlash : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Nirvana");
            Main.RegisterItemAnimation(projectile.type, new DrawAnimationVertical(10, 5));
            Main.projFrames[mod.ProjectileType("NirvanaSlash")] = 5;
        }
      
        public override void SetDefaults()
        {
            projectile.width = 80;
            projectile.height = 70;
            projectile.aiStyle = 75;
            projectile.penetrate = -1;
            projectile.friendly = true;
            projectile.melee = true;
            projectile.ownerHitCheck = true;
            projectile.ignoreWater = true;
            projectile.tileCollide = false;
        }

        public override void AI()
        {
            Player player = Main.player[projectile.owner];
            float num = 1.57079637f;
            Vector2 vector = player.RotatedRelativePoint(player.MountedCenter, true);
          
            num = 0f;
            if (projectile.spriteDirection == -1)
            {
                num = 3.14159265274f;
            }
          
            if (++projectile.frame >= Main.projFrames[projectile.type])
            {
                projectile.frame = 1;
            }

            projectile.soundDelay--;
            if (projectile.soundDelay <=0)
            {
                Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 1);
                projectile.soundDelay = 12;
            }
          
            if (Main.myPlayer == projectile.owner)
            {
                if (player.channel && !player.noItems && !player.CCed)
                {
                    float scaleFactor6 = 1f;
                    if (player.inventory[player.selectedItem].shoot == projectile.type)
                    {
                        scaleFactor6 = player.inventory[player.selectedItem].shootSpeed * projectile.scale;
                    }
                  
                    Vector2 vector13 = Main.MouseWorld - vector;
                    vector13.Normalize();
                    if (vector13.HasNaNs())
                    {
                        vector13 = Vector2.UnitX * (float)player.direction;
                    }
                  
                    vector13 *= scaleFactor6;
                    if (vector13.X != projectile.velocity.X || vector13.Y != projectile.velocity.Y)
                    {
                        projectile.netUpdate = true;
                    }
                    projectile.velocity = vector13;
                }
                else
                {
                    projectile.Kill();
              
                }
            }
            Vector2 vector14 = projectile.Center + projectile.velocity * 3f;
            Lighting.AddLight(vector14, 0.1f, 1f, 0.1f);
            projectile.position = player.RotatedRelativePoint(player.MountedCenter, true) - projectile.Size / 2f;
            projectile.rotation = projectile.velocity.ToRotation() + num;
            projectile.spriteDirection = projectile.direction;
            projectile.timeLeft = 2;
            player.ChangeDir(projectile.direction);
            player.heldProj = projectile.whoAmI;
            player.itemTime = 2;
            player.itemAnimation = 2;
            player.itemRotation = (float)Math.Atan2((double)(projectile.velocity.Y * (float)projectile.direction), (double)(projectile.velocity.X * (float)projectile.direction));
        }
      
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.CursedInferno, 5 * 60);
            target.immune[projectile.owner] = 2;
        }
    } 
}
Also, after I use the Alternate attack (Right Click), it doesn't go back to it's normal left click. Why's that?
Hey i'm having the same problem with the alt attack thing, did you ever learn how to fix that?
 
Advanced Concepts:

For those who want to make a homing projectile without the use of an aiStyle try this. This is a modified version of my PDT Bullet in COFP. This should go inside the AI hook.
Code:
//For all of the NPC slots in Main.npc
//Note, you can replace NPC with other entities such as Projectiles and Players
public override void AI()
{
    for(int i = 0; i < 200; i++)
    {
       NPC target = Main.npc[i];
       //If the npc is hostile
       if(target.hostile)
       {
           //Get the shoot trajectory from the projectile and target
           float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
           float shootToY = target.position.Y - projectile.Center.Y;
           float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

           //If the distance between the live targeted npc and the projectile is less than 480 pixels
           if(distance < 480f && !target.friendly && target.active)
           {
               //Divide the factor, 3f, which is the desired velocity
               distance = 3f / distance;
  
               //Multiply the distance by a multiplier if you wish the projectile to have go faster
               shootToX *= distance * 5;
               shootToY *= distance * 5;

               //Set the velocities to the shoot values
               projectile.velocity.X = shootToX;
               projectile.velocity.Y = shootToY;
           }
       }
    }
}

I see this a lot on the forums, asking how to make things shoot at a target so, here you guys go. This is a modified version of my PDT from COFP. This should be inside the AI hook.
Code:
//Note, you can use this with an NPC to shoot at a Player also
//For every npc slot in Main.npc
public override void AI()
{
    for(int i = 0; i < 200; i++)
    {
       //Enemy NPC variable being set
       NPC target = Main.npc[i];

       //Getting the shooting trajectory
       float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
       float shootToY = target.position.Y - projectile.Center.Y;
       float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

       //If the distance between the projectile and the live target is active
       if(distance < 480f && !target.friendly && target.active)
       {
           if(projectile.ai[0] > 4f) //Assuming you are already incrementing this in AI outside of for loop
           {
               //Dividing the factor of 3f which is the desired velocity by distance
               distance = 3f / distance;
  
               //Multiplying the shoot trajectory with distance times a multiplier if you so choose to
               shootToX *= distance * 5;
               shootToY *= distance * 5;
  
               //Shoot projectile and set ai back to 0
               Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, 1, 0, 0, Main.myPlayer, 0f, 0f); //Spawning a projectile
               Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 11); //Bullet noise
               projectile.ai[0] = 0f;
           }
       }
    }
    projectile.ai[0] += 1f;
}

I just figured this out, and I felt really dumb because it was really simple... with the power of Math: Trigonometry Edition, here's how you can make a projectile orbit around something. This example involves orbiting the player.
Code:
public override void AI()
{
    //Making player variable "p" set as the projectile's owner
    Player p = Main.player[projectile.owner];

    //Factors for calculations
    double deg = (double) projectile.ai[1]; //The degrees, you can multiply projectile.ai[1] to make it orbit faster, may be choppy depending on the value
    double rad = deg * (Math.PI / 180); //Convert degrees to radians
    double dist = 64; //Distance away from the player

    /*Position the player based on where the player is, the Sin/Cos of the angle times the /
    /distance for the desired distance away from the player minus the projectile's width   /
    /and height divided by two so the center of the projectile is at the right place.     */
    projectile.position.X = player.Center.X - (int)(Math.Cos(rad) * dist) - projectile.width/2;
    projectile.position.Y = player.Center.Y - (int)(Math.Sin(rad) * dist) - projectile.height/2;

    //Increase the counter/angle in degrees by 1 point, you can change the rate here too, but the orbit may look choppy depending on the value
    projectile.ai[1] += 1f;
}

for the homing projectile it says it couldn't find out what a hostile npc is please help me fix this issue
 
I know this is a dead thread but there is a ez pz way to make a homing projectile by just setting the projectile.aiStyle to 36

code:
projectile.aiStyle = 36;
 
is there a way I can make it shoot a vanilla projectile and it rains from the sky like how star wrath does in vanilla
 
i think for making a arching projectile just use the arrow ai and also to make something like the star wrath i know there is a guide for it if i find it i will post it in the thread but for now try to find it on your own
also dither your pfp made me die inside a little
 
I require assistance D:
Okay, so main idea:
A sword that shoots two different projectiles,
ProjectileA shoots from sword (ai = 0)
ProjectileB shoots like starwrath (ai = 503[I think])
Problem: EVERYTHING PROJECTILES ARE BROKEN
Sword.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Items.Weapons
{
public class YinBlade : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Yin Blade");
Tooltip.SetDefault("Yin or Yang or a path of nonexistence.. or Fluffiness.");
}

public override void SetDefaults()
{
item.damage = 109999;
item.melee = true;
item.width = 64;
item.height = 64;
item.useTime = 2;
item.useAnimation = 5;
item.useStyle = 1;
item.knockBack = 10;
item.value = 999999;
item.rare = 13;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.scale = 2.5f;
item.shoot = mod.ProjectileType("Lightning");
item.shootSpeed = 20f;
item.shoot = mod.ProjectileType("Meteor");
item.shootSpeed = 5f;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(2, 999);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}

public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{
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.Electrified, 21600);
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 target = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY);
float ceilingLimit = target.Y;
if (ceilingLimit > player.Center.Y - 200f)
{
ceilingLimit = player.Center.Y - 200f;
}
for (int i = 0; i < 3; i++)
{
position = player.Center + new Vector2((-(float)Main.rand.Next(0,401) * player.direction), -600f);
position.Y -= (100 * i);
Vector2 heading = target - position;
if (heading.Y < 0f)
{
heading.Y *= -1f;
}
if (heading.Y < 20f)
{
heading.Y = 20f;
}
heading.Normalize();
heading *= new Vector2(speedX, speedY).Length();
speedX = heading.X;
speedY = heading.Y + Main.rand.Next(-40,41) * 0.02f;
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage * 2, knockBack, player.whoAmI, 0f, ceilingLimit);
}
return false;
}
}
}

ProjectileA.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Projectiles
{

public class Lightning : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Lightning");
}
public override void SetDefaults()
{
projectile.width = 100;
projectile.height = 100;
projectile.friendly = true;
projectile.hostile = false;
projectile.melee = true;
projectile.magic = false;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.timeLeft = 200;
projectile.light = 2f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
projectile.aiStyle = 0;
projectile.scale = 1.75f;
}
public override void AI()
{
if (Main.rand.Next(1) == 0)
{
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height,235);
dust.noGravity = false;
dust.scale = 1.0f;
}
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2f;
}
}
}
}

ProjectileB.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Projectiles
{

public class Meteor : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Meteor");
}
public override void SetDefaults()
{
projectile.width = 100;
projectile.height = 100;
projectile.friendly = true;
projectile.hostile = false;
projectile.melee = true;
projectile.magic = false;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.timeLeft = 200;
projectile.light = 2f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
projectile.aiStyle = 503;
projectile.scale = 6f;
}
public override void AI()
{
if (Main.rand.Next(1) == 0)
{
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height,235);
dust.noGravity = false;
dust.scale = 1.0f;
}
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2f;
}
}
}
}

I require assistance!! ;-;
 
I keep having a error with the override for the mod file
 

Attachments

  • Screenshot (2).png
    Screenshot (2).png
    59.5 KB · Views: 124
Advanced Concepts:

For those who want to make a homing projectile without the use of an aiStyle try this. This is a modified version of my PDT Bullet in COFP. This should go inside the AI hook.
Code:
//For all of the NPC slots in Main.npc
//Note, you can replace NPC with other entities such as Projectiles and Players
public override void AI()
{
    for(int i = 0; i < 200; i++)
    {
       NPC target = Main.npc[i];
       //If the npc is hostile
       if(target.hostile)
       {
           //Get the shoot trajectory from the projectile and target
           float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
           float shootToY = target.position.Y - projectile.Center.Y;
           float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

           //If the distance between the live targeted npc and the projectile is less than 480 pixels
           if(distance < 480f && !target.friendly && target.active)
           {
               //Divide the factor, 3f, which is the desired velocity
               distance = 3f / distance;
  
               //Multiply the distance by a multiplier if you wish the projectile to have go faster
               shootToX *= distance * 5;
               shootToY *= distance * 5;

               //Set the velocities to the shoot values
               projectile.velocity.X = shootToX;
               projectile.velocity.Y = shootToY;
           }
       }
    }
}

I see this a lot on the forums, asking how to make things shoot at a target so, here you guys go. This is a modified version of my PDT from COFP. This should be inside the AI hook.
Code:
//Note, you can use this with an NPC to shoot at a Player also
//For every npc slot in Main.npc
public override void AI()
{
    for(int i = 0; i < 200; i++)
    {
       //Enemy NPC variable being set
       NPC target = Main.npc[i];

       //Getting the shooting trajectory
       float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
       float shootToY = target.position.Y - projectile.Center.Y;
       float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

       //If the distance between the projectile and the live target is active
       if(distance < 480f && !target.friendly && target.active)
       {
           if(projectile.ai[0] > 4f) //Assuming you are already incrementing this in AI outside of for loop
           {
               //Dividing the factor of 3f which is the desired velocity by distance
               distance = 3f / distance;
  
               //Multiplying the shoot trajectory with distance times a multiplier if you so choose to
               shootToX *= distance * 5;
               shootToY *= distance * 5;
  
               //Shoot projectile and set ai back to 0
               Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, 1, 0, 0, Main.myPlayer, 0f, 0f); //Spawning a projectile
               Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 11); //Bullet noise
               projectile.ai[0] = 0f;
           }
       }
    }
    projectile.ai[0] += 1f;
}

I just figured this out, and I felt really dumb because it was really simple... with the power of Math: Trigonometry Edition, here's how you can make a projectile orbit around something. This example involves orbiting the player.
Code:
public override void AI()
{
    //Making player variable "p" set as the projectile's owner
    Player p = Main.player[projectile.owner];

    //Factors for calculations
    double deg = (double) projectile.ai[1]; //The degrees, you can multiply projectile.ai[1] to make it orbit faster, may be choppy depending on the value
    double rad = deg * (Math.PI / 180); //Convert degrees to radians
    double dist = 64; //Distance away from the player

    /*Position the player based on where the player is, the Sin/Cos of the angle times the /
    /distance for the desired distance away from the player minus the projectile's width   /
    /and height divided by two so the center of the projectile is at the right place.     */
    projectile.position.X = player.Center.X - (int)(Math.Cos(rad) * dist) - projectile.width/2;
    projectile.position.Y = player.Center.Y - (int)(Math.Sin(rad) * dist) - projectile.height/2;

    //Increase the counter/angle in degrees by 1 point, you can change the rate here too, but the orbit may look choppy depending on the value
    projectile.ai[1] += 1f;
}
For 'Having projectiles to shoot at something', If I want to shoot two or more targets at once?
 
I require assistance D:
Okay, so main idea:
A sword that shoots two different projectiles,
ProjectileA shoots from sword (ai = 0)
ProjectileB shoots like starwrath (ai = 503[I think])
Problem: EVERYTHING PROJECTILES ARE BROKEN
Sword.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Items.Weapons
{
public class YinBlade : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Yin Blade");
Tooltip.SetDefault("Yin or Yang or a path of nonexistence.. or Fluffiness.");
}

public override void SetDefaults()
{
item.damage = 109999;
item.melee = true;
item.width = 64;
item.height = 64;
item.useTime = 2;
item.useAnimation = 5;
item.useStyle = 1;
item.knockBack = 10;
item.value = 999999;
item.rare = 13;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.scale = 2.5f;
item.shoot = mod.ProjectileType("Lightning");
item.shootSpeed = 20f;
item.shoot = mod.ProjectileType("Meteor");
item.shootSpeed = 5f;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(2, 999);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}

public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{
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.Electrified, 21600);
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 target = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY);
float ceilingLimit = target.Y;
if (ceilingLimit > player.Center.Y - 200f)
{
ceilingLimit = player.Center.Y - 200f;
}
for (int i = 0; i < 3; i++)
{
position = player.Center + new Vector2((-(float)Main.rand.Next(0,401) * player.direction), -600f);
position.Y -= (100 * i);
Vector2 heading = target - position;
if (heading.Y < 0f)
{
heading.Y *= -1f;
}
if (heading.Y < 20f)
{
heading.Y = 20f;
}
heading.Normalize();
heading *= new Vector2(speedX, speedY).Length();
speedX = heading.X;
speedY = heading.Y + Main.rand.Next(-40,41) * 0.02f;
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage * 2, knockBack, player.whoAmI, 0f, ceilingLimit);
}
return false;
}
}
}

ProjectileA.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Projectiles
{

public class Lightning : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Lightning");
}
public override void SetDefaults()
{
projectile.width = 100;
projectile.height = 100;
projectile.friendly = true;
projectile.hostile = false;
projectile.melee = true;
projectile.magic = false;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.timeLeft = 200;
projectile.light = 2f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
projectile.aiStyle = 0;
projectile.scale = 1.75f;
}
public override void AI()
{
if (Main.rand.Next(1) == 0)
{
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height,235);
dust.noGravity = false;
dust.scale = 1.0f;
}
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2f;
}
}
}
}

ProjectileB.cs:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace YinBlade.Projectiles
{

public class Meteor : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Meteor");
}
public override void SetDefaults()
{
projectile.width = 100;
projectile.height = 100;
projectile.friendly = true;
projectile.hostile = false;
projectile.melee = true;
projectile.magic = false;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.timeLeft = 200;
projectile.light = 2f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
projectile.aiStyle = 503;
projectile.scale = 6f;
}
public override void AI()
{
if (Main.rand.Next(1) == 0)
{
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height,235);
dust.noGravity = false;
dust.scale = 1.0f;
}
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2f;
}
}
}
}

I require assistance!! ;-;
The projectiles are fine. The sword, on the other hand...

Firstly, you can never ever ever set shoot to 2 different projectiles. You set shoot twice. This means that the game will read your first shoot, and override it with the second (same with shootSpeed). You need to override the shoot method. I see you have done this, but it's incorrect for what you want. To fix this, follow these 2 steps.
Delete the following:
Code:
item.shoot = mod.ProjectileType("Meteor");
item.shootSpeed = 5f;
Replace the shoot method with this:
Code:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
                Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI); //create Projectile A
                for (int i = 0; i < 3; i++) //replace 3 with however many projectiles you like

            {
                Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(12)); //12 is the spread in degrees, although like with Set Spread it's technically a 24 degree spread due to the fact that it's randomly between 12 degrees above and 12 degrees below your cursor.
                Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, mod.ProjectileType("Meteor"), damage, knockBack, player.whoAmI); //create Projectile B
            }
            return false; //prevents it from shooting the projectile specified in Shoot again
        }
 
Back
Top Bottom