How do i make my weapons shoot projectiles?

C#:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace DodgeMod.Items.Weapons
{
    public class ChewToy : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Chew Toy";
            item.damage = 9750;
            item.melee = true;
            item.width = 49;
            item.height = 50;
            item.toolTip = "Woof";
            item.useTime = 8;
            item.useAnimation = 8;
            item.useStyle = 1;
            item.knockBack = 17.5;
            item.value = item.buyPrice(50, 0, 0, 0);
            item.rare = 13;
            item.useSound = 1;
            item.autoReuse = true;
            item.useTurn = true;
            item.shoot = mod.ProjectileType("Doge");
            item.shootSpeed = 8f;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.TerraBlade, 1);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.Workbenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
            
        }
    }
}
Here is the code for my weapon, which I'm planning to make fire a pixelated Doge when I attack. Terraria states there are a few errors in this code and my projectile code. Any suggestions?

Here is my projectile code:
C#:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace DodgeMod.Items.Projectiles
{
    public class PixelatedDoge : ModProjectile
    {
        public override void SetDefaults()
        {
            
            projectile.name = "Pixelated Doge";
            projectile.width = 49;
            projectile.height = 50;
            projectile.friendly = true;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.penetrate = 30;
            projectile.timeLeft = 500;
            projectile.light = 2.75f;
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;
        }
        public override void AI()
        {
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
        }
    }
}
 
I forgot to mention, all the code and images are in their designated folder
 
im still reading this in 2020 yet its not working
 
Here is the existing code for my sword:
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace PebblesStupidContent.Items.Weapons.Melee.Swords.TypeNull
{
    public class TypeNull : ModItem
    {
        public override void SetStaticDefaults()
        {
            // DisplayName.SetDefault("Type: Null")
            Tooltip.SetDefault("Invalid ID, please terminate to continue");
        }

        public override void SetDefaults()
        {
            item.damage = 9999;
            item.melee = true;
            item.width = 94;
            item.height = 94;
            item.useTime = 10;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 6.5;
            item.value = 99999;
            item.rare = -12;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.shoot = mod.projectileType("TypeNullProjectile");
            item.shootSpeed = 9f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.3467, 99);
            recipe.AddTile(TileID.412);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
Here is the existing code for my projectile:
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace PebblesStupidContent.Items.Weapons.Melee.Swords.TypeNull
{
    public class TypeNull : ModItem
    {
        public override void SetDefaults()
        {
                    projectile.name = "Type: Null (Projectile)";
                    projectile.width = 94;  
                    projectile.height = 94;
                    projectile.friendly = true;
                    projectile.melee = true;    
                    projectile.tileCollide = false;
                    projectile.penetrate = 999999999999;
                    projectile.timeLeft = 999999999999;
                    projectile.light = 9f;
                    projectile.extraUpdates = 1;
                    projectile.ignoreWater = true;
                }

                public override void AI()      
                {                                                      
                    projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
                }
        }
}
Here is an error encountered while attempting to build and reload:
Code:
C:\Users\Elijah\OneDrive\Documents\My Games\Terraria\ModLoader\Mod Sources\PebblesStupidContent\Projectiles\Weapons\Melee\Swords\TypeNull\TypeNullProjectile.cs(23,31) : CS0115: 'TypeNull.AI()': no suitable method found to override
What does this mean and how can I fix it?
 
um.... this is a long time ago and i am WELL AWARE that coding has changed especially for terraria, but do any of you guys know the code for "shoot mod projectiles" because i did this and it says it cannot find the swords projectile, even though it is in the projectiles folder.
 
Here is the existing code for my sword:
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace PebblesStupidContent.Items.Weapons.Melee.Swords.TypeNull
{
    public class TypeNull : ModItem
    {
        public override void SetStaticDefaults()
        {
            // DisplayName.SetDefault("Type: Null")
            Tooltip.SetDefault("Invalid ID, please terminate to continue");
        }

        public override void SetDefaults()
        {
            item.damage = 9999;
            item.melee = true;
            item.width = 94;
            item.height = 94;
            item.useTime = 10;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 6.5;
            item.value = 99999;
            item.rare = -12;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.shoot = mod.projectileType("TypeNullProjectile");
            item.shootSpeed = 9f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.3467, 99);
            recipe.AddTile(TileID.412);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
Here is the existing code for my projectile:
Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace PebblesStupidContent.Items.Weapons.Melee.Swords.TypeNull
{
    public class TypeNull : ModItem
    {
        public override void SetDefaults()
        {
                    projectile.name = "Type: Null (Projectile)";
                    projectile.width = 94; 
                    projectile.height = 94;
                    projectile.friendly = true;
                    projectile.melee = true;   
                    projectile.tileCollide = false;
                    projectile.penetrate = 999999999999;
                    projectile.timeLeft = 999999999999;
                    projectile.light = 9f;
                    projectile.extraUpdates = 1;
                    projectile.ignoreWater = true;
                }

                public override void AI()     
                {                                                     
                    projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
                }
        }
}
Here is an error encountered while attempting to build and reload:
Code:
C:\Users\Elijah\OneDrive\Documents\My Games\Terraria\ModLoader\Mod Sources\PebblesStupidContent\Projectiles\Weapons\Melee\Swords\TypeNull\TypeNullProjectile.cs(23,31) : CS0115: 'TypeNull.AI()': no suitable method found to override
What does this mean and how can I fix it?
did you add, using servers; to the very top of the code, this might help, yet you might run into my problem
 
failed with : Error: C:\Users\alexl\OneDrive\Dokumente\My Games\Terraria\ModLoader\Mod Sources\MyIceSword\Items\CursedIce.cs(15,23) : error CS1061: 'Projectile' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'Projectile' could be found (are you missing a using directive or an assembly reference?)

whats wrong?
weapon code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace MyIceSword.Items.Weapons
{
public class IceSword : ModItem
{
public override void SetDefaults()
{
item.name = "Ice Sword";
item.damage = 120;
item.melee = true;
item.width = 75;
item.height = 75;
item.toolTip = "You feel dark Power! ";
item.useTime = 8;
item.useAnimation = 8;
item.useStyle = 1;
item.knockBack = 30;
item.value = 1000000;
item.rare = 10;
item.useSound = 1;
item.autoReuse = true;
item.useTurn = true;
item.shoot = mod.ProjectileType("CursedIce");
item.shootSpeed = 12f;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.IceBlade, 1);
recipe.AddIngredient(ItemID.CursedFlammes, 1);
recipe.AddTile(TileID.Hellforge);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

projectile code:

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace MyIceSword.Projectiles
{
public class CursedIce : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "Cursed Ice";
projectile.width = 11;
projectile.height = 20;
projectile.friendly = true;
projectile.melee = true;
projectile.tileCollide = false;
projectile.penetrate = 30;
projectile.timeLeft = 600;
projectile.light = 3f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
}
public override void AI()
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
}
}
}

can anyone help??
 
failed with : Error: C:\Users\alexl\OneDrive\Dokumente\My Games\Terraria\ModLoader\Mod Sources\MyIceSword\Items\CursedIce.cs(15,23) : error CS1061: 'Projectile' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'Projectile' could be found (are you missing a using directive or an assembly reference?)

projectile code:

{
public class CursedIce : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "Cursed Ice";
projectile.name is no longer a thing in tModLoader, so remove it. Instead add:
C#:
public override void SetStaticDefaults()
{
    DisplayName.SetDefault("Cursed Ice");
}
Or you could just leave it blank and tModLoader will automatically assign the projectile a name based on the class name.
 
Add an

Code:
item.shoot = mod.ProjectileType("ProjektileName");
item.shootSpeed = SpeedOfProjektilef;

Example

Sword

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

namespace SwordOfCthulhu.Items.Weapons
{
    public class SwordOfCthulhu : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Sword Of Cthulhu";  
            item.damage = 500;         
            item.melee = true;         
            item.width = 58;           
            item.height = 66;          
            item.toolTip = "You feel celestial Power! ";
            item.useTime = 8;        
            item.useAnimation = 8;  
            item.useStyle = 1;     
            item.knockBack = 6;   
            item.value = 100;     
            item.rare = 10;
            item.useSound = 1;    
            item.autoReuse = true;
            item.useTurn = true;
            item.shoot = mod.ProjectileType("SwordOfCthulhuBeam");
            item.shootSpeed = 12f;                              
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);   
            recipe.AddIngredient(ItemID.TerraBlade, 1);
            recipe.AddIngredient(ItemID.Meowmere, 1);
            recipe.AddIngredient(ItemID.StarWrath, 1);
            recipe.AddIngredient(ItemID.LunarBar, 25);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.SetResult(this);
            recipe.AddRecipe();

        }
    }
}

Projektile (Preojektile File Must be in "Projektiles" Folder)

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

namespace SwordOfCthulhu.Projectiles
{

    public class SwordOfCthulhuBeam : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Sword Of Cthulhu Beam";
            projectile.width = 30;    
            projectile.height = 58;
            projectile.friendly = true;   
            projectile.melee = true;       
            projectile.tileCollide = true;
            projectile.penetrate = 30;   
            projectile.timeLeft = 200;
            projectile.light = 0.75f; 
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;
        }
        public override void AI()        
        {                                                        
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
        }
    }
}


I Hope it helps
Thank you so much, this helped me too! :D
 
Back
Top Bottom