tModLoader [Tutorial] Projectile Guide and Implementation: tModLoader Edition

how to i make a projectile like the magic missile, flamelash, etc... Ive searched literally everywhere and could not find anything. I tried using item.CloneDefaults but that adds the projectile sprite and sound, any help on the code? here's what i have
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace Xrandia.Items.Weapons
{
public class AncientWand : ModItem
{
public override void SetDefaults()
{
//item.CloneDefaults(ItemID.RainbowRod);
item.name = "Ancient Wand"; // possibly resprite it or modify the sprite
item.magic = true;
item.mana = 30;
item.width = 30;
item.height = 32;
item.toolTip = "An old noble wand";
item.useTime = 40;
item.useAnimation = 20;
item.useStyle = 1;
//Item.staff[item.type] = true;
item.noMelee = true;
item.knockBack = 5;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item20;
item.autoReuse = false;
item.shoot = mod.ProjectileType("AncientProjectile");
item.shootSpeed = 10f;
}
/*mod.ProjectileType "AncientProjectile")
{
if (Main.myPlayer == player.whoAmI)
{
int mod; Projectile; Type; ("AncientProjectile") = Projectile.NewProjectile(Main.MouseWorld.X, Main.MouseWorld.Y, speedX, speedY, type, item.damage, item.knockBack, player.whoAmI);
}
}*/

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);// unobtainable
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

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

namespace Xrandia.Projectiles
{
public class AncientProjectile : ModProjectile
{
public override void SetDefaults() //this adds the flamelash skin and the ability to controll it
{
projectile.CloneDefaults(ProjectileID.Flamelash);
projectile.name = "AncientProjectile";
//aiType = ProjectileID.Flamelash;
//projectile.speed = 1f;
projectile.friendly = true;
projectile.width = 16;
projectile.height = 16;
projectile.melee = true;
projectile.damage = 114;
projectile.knockBack = 4;
projectile.magic = true;
projectile.penetrate = 1;
projectile.hostile = false;
projectile.friendly = false;
projectile.tileCollide = true;
projectile.ignoreWater = true;
projectile.alpha = 255;
projectile.timeLeft = 5000;
projectile.penetrate = 1;
projectile.aiStyle = 9;
}

public override void AI() // this may add flamelash
{
//aiType = ProjectileID.Flamelash; // noise

int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("AncientBookDust"));
int num666 = 8;
int num667 = Dust.NewDust(new Vector2(projectile.position.X + (float)num666 + 6, projectile.position.Y + (float)num666), projectile.width - num666 * 2, projectile.height - num666 * 2, 66, 0f, 0f, 0, new Color(255, 255, 0), 1.5f); //projectile dust color
Main.dust[num667].velocity *= 0.5f;
Main.dust[num667].velocity += projectile.velocity * 0.5f;
Main.dust[num667].noGravity = true;
Main.dust[num667].noLight = false;
Main.dust[num667].scale = 2.4f;

projectile.localAI[0] += 1f;
}
}
}

There may be 1 or 2 other errors but please don't mind them.
thanks in advance
 
how to i make a projectile like the magic missile, flamelash, etc... Ive searched literally everywhere and could not find anything. I tried using item.CloneDefaults but that adds the projectile sprite and sound, any help on the code? here's what i have
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace Xrandia.Items.Weapons
{
public class AncientWand : ModItem
{
public override void SetDefaults()
{
//item.CloneDefaults(ItemID.RainbowRod);
item.name = "Ancient Wand"; // possibly resprite it or modify the sprite
item.magic = true;
item.mana = 30;
item.width = 30;
item.height = 32;
item.toolTip = "An old noble wand";
item.useTime = 40;
item.useAnimation = 20;
item.useStyle = 1;
//Item.staff[item.type] = true;
item.noMelee = true;
item.knockBack = 5;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item20;
item.autoReuse = false;
item.shoot = mod.ProjectileType("AncientProjectile");
item.shootSpeed = 10f;
}
/*mod.ProjectileType "AncientProjectile")
{
if (Main.myPlayer == player.whoAmI)
{
int mod; Projectile; Type; ("AncientProjectile") = Projectile.NewProjectile(Main.MouseWorld.X, Main.MouseWorld.Y, speedX, speedY, type, item.damage, item.knockBack, player.whoAmI);
}
}*/

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);// unobtainable
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

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

namespace Xrandia.Projectiles
{
public class AncientProjectile : ModProjectile
{
public override void SetDefaults() //this adds the flamelash skin and the ability to controll it
{
projectile.CloneDefaults(ProjectileID.Flamelash);
projectile.name = "AncientProjectile";
//aiType = ProjectileID.Flamelash;
//projectile.speed = 1f;
projectile.friendly = true;
projectile.width = 16;
projectile.height = 16;
projectile.melee = true;
projectile.damage = 114;
projectile.knockBack = 4;
projectile.magic = true;
projectile.penetrate = 1;
projectile.hostile = false;
projectile.friendly = false;
projectile.tileCollide = true;
projectile.ignoreWater = true;
projectile.alpha = 255;
projectile.timeLeft = 5000;
projectile.penetrate = 1;
projectile.aiStyle = 9;
}

public override void AI() // this may add flamelash
{
//aiType = ProjectileID.Flamelash; // noise

int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("AncientBookDust"));
int num666 = 8;
int num667 = Dust.NewDust(new Vector2(projectile.position.X + (float)num666 + 6, projectile.position.Y + (float)num666), projectile.width - num666 * 2, projectile.height - num666 * 2, 66, 0f, 0f, 0, new Color(255, 255, 0), 1.5f); //projectile dust color
Main.dust[num667].velocity *= 0.5f;
Main.dust[num667].velocity += projectile.velocity * 0.5f;
Main.dust[num667].noGravity = true;
Main.dust[num667].noLight = false;
Main.dust[num667].scale = 2.4f;

projectile.localAI[0] += 1f;
}
}
}

There may be 1 or 2 other errors but please don't mind them.
thanks in advance
Need to add "item.channel = true" to your item.
 
It worked!!! THANK YOU!!!!!!

EDIT: Actually it still has the magic missile sprite but it was a step closer... is there a way to get rid of the magic missile sprite?
 
Last edited:
Error:

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMOD\Projectiles\TerraGlaiveProj.cs(63,2) : error CS1513: } expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMOD\Projectiles\TerraGlaiveProj.cs(63,2) : error CS1513: } expected

Code:

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

namespace TutorialMOD.Projectiles
{
public class TerraGlaiveProj : ModProjectile
{
public override void SetDefaults()
{
aiType = ProjectileID.DeathSickle;
projectile.CloneDefaults(ProjectileID.DeathSickle);
projectile.width = 140;
projectile.height = 140;
projectile.name = "Terra Saw";
projectile.damage = 400;
projectile.penetrate = -1;
projectile.tileCollide = false;
projectile.ignoreWater = true;
projectile.melee = true;

}

public override void AI()
{
int minDist = 1000;
int target = 0;
float dX = 0f;
float dY = 0f;
float distance = 0;
float speed = 15f;
if(projectile.ai[0] % 60 == 0)
{
for(int i = 0; i < Main.npc.Length - 1; i++)
{
NPC target = Main.npc;
if(!target.friendly)
{
dX = target.Center.X - projectile.Center.X;
dY = target.Center.Y - projectile.Center.Y;
distance = (float) Math.Sqrt((double)(dX * dX + dY * dY);
if(distance < minDist)
{
minDist = distance;
target = i;
}
}
}

NPC toHit = Main.npc[target];

dX = toHit.Center.X - projectile.Center.X;
dY = toHit.Center.Y - projectile.Center.Y;
distance = (float)Math.Sqrt((double)(dX * dX + dY * dY));
speed /= distance;

projectile.velocity = new Vector2(dX * speed, dY * speed);

}
}


Sorry if it sounds noobish (And for necroing this thread), but what needs to be fixed?
P.S I wanted the projectile to home in on enemies.
 
Thanks, now I feel stupid for not knowing this >.< Ah well, nobody has all the knowledge in the world after all.
P.S when it says "} Expected", does it mean I need to add a }, or change/remove a } ? And where exactly do I have to add/change/remove the }?
It's per function, per class, per namespace, so for every class, function, and namespace, there should be a "{" and a "}". Indentations help identify this problem.
 
"c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMOD\Items\TerrasteelChalikar.cs(34,30) : error CS0161: 'TutorialMOD.Items.TerrasteelChalikar.CanUseItem(Terraria.Player)': not all code paths return a value"

Code:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TutorialMOD.Items      //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class TerrasteelChalikar : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults (ItemID.DeathSickle);
            item.name = "Terrasteel Chalikar";    //the name displayed when hovering over the Weapon ingame.
            item.damage = 500;    //The damage stat for the Weapon.
            item.melee = true;     //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 120;    //The size of the width of the hitbox in pixels.
            item.height = 120;    //The size of the height of the hitbox in pixels.
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.channel = true;
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 8f;    //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 = 11;   //The color the title of your Weapon when hovering over it ingame      
            item.shoot = mod.ProjectileType("TerrasteelChalikarProj");  //This defines what type of projectile this weapon will shoot
            item.noUseGraphic = true; // this defines if it does not use graphic
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {
                item.useTime = 10;
                item.useAnimation = 10;
                item.shoot = mod.ProjectileType("TerrasteelChalikarProjBoomerang");
                item.shootSpeed *=2f;
            }
        }
       
        public override bool UseItemFrame(Player player)     //this defines what frame the player use when this weapon is used
        {
            player.bodyFrame.Y = 3 * player.bodyFrame.Height;
            return 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
            target.AddBuff(BuffID.Ichor, 300); //Add Ichor buff to the NPC for 5 seconds
        }
    }
}

Help?
 
"c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMOD\Items\TerrasteelChalikar.cs(34,30) : error CS0161: 'TutorialMOD.Items.TerrasteelChalikar.CanUseItem(Terraria.Player)': not all code paths return a value"

Code:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TutorialMOD.Items      //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class TerrasteelChalikar : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults (ItemID.DeathSickle);
            item.name = "Terrasteel Chalikar";    //the name displayed when hovering over the Weapon ingame.
            item.damage = 500;    //The damage stat for the Weapon.
            item.melee = true;     //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 120;    //The size of the width of the hitbox in pixels.
            item.height = 120;    //The size of the height of the hitbox in pixels.
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.channel = true;
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 8f;    //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 = 11;   //The color the title of your Weapon when hovering over it ingame     
            item.shoot = mod.ProjectileType("TerrasteelChalikarProj");  //This defines what type of projectile this weapon will shoot
            item.noUseGraphic = true; // this defines if it does not use graphic
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {
                item.useTime = 10;
                item.useAnimation = 10;
                item.shoot = mod.ProjectileType("TerrasteelChalikarProjBoomerang");
                item.shootSpeed *=2f;
            }
        }
      
        public override bool UseItemFrame(Player player)     //this defines what frame the player use when this weapon is used
        {
            player.bodyFrame.Y = 3 * player.bodyFrame.Height;
            return 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
            target.AddBuff(BuffID.Ichor, 300); //Add Ichor buff to the NPC for 5 seconds
        }
    }
}

Help?
CanUseItem does not return a value at all. Add a return statement after the if statement to return a boolean value of true.
 
"c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\TutorialMOD\Items\TerrasteelChalikar.cs(34,30) : error CS0161: 'TutorialMOD.Items.TerrasteelChalikar.CanUseItem(Terraria.Player)': not all code paths return a value"

Code:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TutorialMOD.Items      //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class TerrasteelChalikar : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults (ItemID.DeathSickle);
            item.name = "Terrasteel Chalikar";    //the name displayed when hovering over the Weapon ingame.
            item.damage = 500;    //The damage stat for the Weapon.
            item.melee = true;     //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 120;    //The size of the width of the hitbox in pixels.
            item.height = 120;    //The size of the height of the hitbox in pixels.
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.channel = true;
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 8f;    //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 = 11;   //The color the title of your Weapon when hovering over it ingame     
            item.shoot = mod.ProjectileType("TerrasteelChalikarProj");  //This defines what type of projectile this weapon will shoot
            item.noUseGraphic = true; // this defines if it does not use graphic
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {
                item.useTime = 10;
                item.useAnimation = 10;
                item.shoot = mod.ProjectileType("TerrasteelChalikarProjBoomerang");
                item.shootSpeed *=2f;
            }
        }
      
        public override bool UseItemFrame(Player player)     //this defines what frame the player use when this weapon is used
        {
            player.bodyFrame.Y = 3 * player.bodyFrame.Height;
            return 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
            target.AddBuff(BuffID.Ichor, 300); //Add Ichor buff to the NPC for 5 seconds
        }
    }
}

Help?
CanUseItem does not return a value at all. Add a return statement after the if statement to return a boolean value of true.

It works :) But now every time I use right click to shoot a boomerang version of the weapon, after that I can't use left click to spin the weapon around me (Like the Sky Dragon's Fury), it just shoots the boomerang projectile regardless of the mouse button used. Here's the code:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TutorialMOD.Items      //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class TerrasteelChalikar : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults (ItemID.DeathSickle);
            item.name = "Terrasteel Chalikar";    //the name displayed when hovering over the Weapon ingame.
            item.damage = 500;    //The damage stat for the Weapon.
            item.melee = true;     //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 50;    //The size of the width of the hitbox in pixels.
            item.height = 50;    //The size of the height of the hitbox in pixels.
            item.useTime = 15;   //How fast the Weapon is used.
            item.useAnimation = 15;     //How long the Weapon is used for.
            item.channel = true;
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 8f;    //The knockback stat of your Weapon.
            item.value = Item.buyPrice(1, 50, 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 = 11;   //The color the title of your Weapon when hovering over it ingame      
            item.shoot = mod.ProjectileType("TerrasteelChalikarProj");  //This defines what type of projectile this weapon will shoot
            item.noUseGraphic = true; // this defines if it does not use graphic
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {
                item.name = "Terrasteel Chalikar";
                item.damage = 500;           
                item.melee = true;
                item.width = 50;
                item.height = 50;
                item.useTime = 25;
                item.useAnimation = 25;
                item.noUseGraphic = true;
                item.useStyle = 1;
                item.knockBack = 3;
                item.value = 8;
                item.rare = 6;
                item.shootSpeed = 12f;
                item.shoot = mod.ProjectileType ("TerrasteelChalikarBoomerang");
                item.UseSound = SoundID.Item1;
                item.autoReuse = true;
            }

            for (int i = 0; i < 1000; ++i)
            {
                if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == item.shoot)
                {
                    return false;
                }
            }
            return true;
        }
       
        public override bool UseItemFrame(Player player)     //this defines what frame the player use when this weapon is used
        {
            player.bodyFrame.Y = 3 * player.bodyFrame.Height;
            return 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
            target.AddBuff(BuffID.Ichor, 300); //Add Ichor buff to the NPC for 5 seconds
        }
    }
}
 
It works :) But now every time I use right click to shoot a boomerang version of the weapon, after that I can't use left click to spin the weapon around me (Like the Sky Dragon's Fury), it just shoots the boomerang projectile regardless of the mouse button used. Here's the code:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TutorialMOD.Items      //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class TerrasteelChalikar : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults (ItemID.DeathSickle);
            item.name = "Terrasteel Chalikar";    //the name displayed when hovering over the Weapon ingame.
            item.damage = 500;    //The damage stat for the Weapon.
            item.melee = true;     //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 50;    //The size of the width of the hitbox in pixels.
            item.height = 50;    //The size of the height of the hitbox in pixels.
            item.useTime = 15;   //How fast the Weapon is used.
            item.useAnimation = 15;     //How long the Weapon is used for.
            item.channel = true;
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 8f;    //The knockback stat of your Weapon.
            item.value = Item.buyPrice(1, 50, 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 = 11;   //The color the title of your Weapon when hovering over it ingame     
            item.shoot = mod.ProjectileType("TerrasteelChalikarProj");  //This defines what type of projectile this weapon will shoot
            item.noUseGraphic = true; // this defines if it does not use graphic
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {
                item.name = "Terrasteel Chalikar";
                item.damage = 500;          
                item.melee = true;
                item.width = 50;
                item.height = 50;
                item.useTime = 25;
                item.useAnimation = 25;
                item.noUseGraphic = true;
                item.useStyle = 1;
                item.knockBack = 3;
                item.value = 8;
                item.rare = 6;
                item.shootSpeed = 12f;
                item.shoot = mod.ProjectileType ("TerrasteelChalikarBoomerang");
                item.UseSound = SoundID.Item1;
                item.autoReuse = true;
            }

            for (int i = 0; i < 1000; ++i)
            {
                if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == item.shoot)
                {
                    return false;
                }
            }
            return true;
        }
      
        public override bool UseItemFrame(Player player)     //this defines what frame the player use when this weapon is used
        {
            player.bodyFrame.Y = 3 * player.bodyFrame.Height;
            return 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
            target.AddBuff(BuffID.Ichor, 300); //Add Ichor buff to the NPC for 5 seconds
        }
    }
}
You never set it back to the original
 
c:\Users\tehpootisman\Documents\My Games\Terraria\ModLoader\Mod Sources\NerfMod\Projectiles\ZombieDartProj.cs(32,17) : error CS0103: The name 'npc' does not exist in the current context




How would I make it so that a projectile would do a bajillion (not literally) damage to only specific NPCs, like how the vanilla Stake Launcher will one shot the Vampire NPC?


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

namespace NerfMod.Projectiles
{
    public class ZombieDartProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Zombie Dart";//Name of the projectile, only shows this if you get killed by it
            projectile.width = 8;  //Set the hitbox width
            projectile.height = 8;  //Set the hitbox height
            projectile.aiStyle = 1; //How the projectile works
            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.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.timeLeft = 400; //The amount of time the projectile is alive for
            aiType = 1; // this is the projectile ai style . 1 is for arrows style
        }

        public virtual void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            if (npc.type = NPCID.Zombie)
            {
                crit = true; //I tried another code I found but it didn't work, so I left this little bit here.
            }
        }

    //After the projectile is dead
    public override void Kill(int timeLeft)
        {

            Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, (mod.ItemType("Dart1"))); // This spawns a projectile after this projectile is dead

        }


    }
}
 
How would I make it so that a projectile would do a bajillion (not literally) damage to only specific NPCs, like how the vanilla Stake Launcher will one shot the Vampire NPC?


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

namespace NerfMod.Projectiles
{
    public class ZombieDartProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Zombie Dart";//Name of the projectile, only shows this if you get killed by it
            projectile.width = 8;  //Set the hitbox width
            projectile.height = 8;  //Set the hitbox height
            projectile.aiStyle = 1; //How the projectile works
            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.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.timeLeft = 400; //The amount of time the projectile is alive for
            aiType = 1; // this is the projectile ai style . 1 is for arrows style
        }

        public virtual void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            if (npc.type = NPCID.Zombie)
            {
                crit = true; //I tried another code I found but it didn't work, so I left this little bit here.
            }
        }

    //After the projectile is dead
    public override void Kill(int timeLeft)
        {

            Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, (mod.ItemType("Dart1"))); // This spawns a projectile after this projectile is dead

        }


    }
}
you are on the right track, except you have virtual there, which means you won't override the original, which you should be doing. Change to override.
 
Well, i've changed it, but now I get this error;

c:\Users\tehpootisman\Documents\My Games\Terraria\ModLoader\Mod Sources\NerfMod\Projectiles\ZombieDartProj.cs(30,30) : error CS0115: 'NerfMod.Projectiles.ZombieDartProj.ModifyHitNPC(Terraria.Player, Terraria.NPC, ref int, ref float, ref bool)': no suitable method found to override

Is there something I still need to fix?

I'm still pretty clueless with this form of coding when it's not some really basic stuff.

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



namespace NerfMod.Projectiles
{
    public class ZombieDartProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Zombie Dart";//Name of the projectile, only shows this if you get killed by it
            projectile.width = 8;  //Set the hitbox width
            projectile.height = 8;  //Set the hitbox height
            projectile.aiStyle = 1; //How the projectile works
            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.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.timeLeft = 400; //The amount of time the projectile is alive for
            aiType = 1; // this is the projectile ai style . 1 is for arrows style
        }

        public override void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            if (npc.type = NPCID.Zombie)
            {
                target.life = 0f;
            }
        }

        //After the projectile is dead
        public override void Kill(int timeLeft)
        {

            Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, (mod.ItemType("Dart1"))); // This spawns a projectile after this projectile is dead

        }

    }
}
 
Last edited:
Well, i've changed it, but now I get this error;



Is there something I still need to fix?

I'm still pretty clueless with this form of coding when it's not some really basic stuff.

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



namespace NerfMod.Projectiles
{
    public class ZombieDartProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Zombie Dart";//Name of the projectile, only shows this if you get killed by it
            projectile.width = 8;  //Set the hitbox width
            projectile.height = 8;  //Set the hitbox height
            projectile.aiStyle = 1; //How the projectile works
            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.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.timeLeft = 400; //The amount of time the projectile is alive for
            aiType = 1; // this is the projectile ai style . 1 is for arrows style
        }

        public override void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            if (npc.type = NPCID.Zombie)
            {
                target.life = 0f;
            }
        }

        //After the projectile is dead
        public override void Kill(int timeLeft)
        {

            Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, (mod.ItemType("Dart1"))); // This spawns a projectile after this projectile is dead

        }

    }
}
I don't think the ModProjectile hook has the player parameter, you need to use an IDE or look up these things in the documentation.
 
I don't think the ModProjectile hook has the player parameter, you need to use an IDE or look up these things in the documentation.


I think I might've found the problem for that particular error, I think I was missing "ref int hitDirection"


Unfortunately now i'm getting this error:

c:\Users\tehpootisman\Documents\My Games\Terraria\ModLoader\Mod Sources\NerfMod\Projectiles\ZombieDartProj.cs(34,17) : error CS0103: The name 'npc' does not exist in the current context


but hey, it's like almost half past midnight where i am, I think getting past that override issue was a satisfying victory.
 
I think I might've found the problem for that particular error, I think I was missing "ref int hitDirection"


Unfortunately now i'm getting this error:




but hey, it's like almost half past midnight where i am, I think getting past that override issue was a satisfying victory.
Well, in the parameters there you named the NPC instance target, so either change that to npc or change the npc in the body to target
 
Well, i've changed it, but now I get this error;



Is there something I still need to fix?

I'm still pretty clueless with this form of coding when it's not some really basic stuff.

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



namespace NerfMod.Projectiles
{
    public class ZombieDartProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Zombie Dart";//Name of the projectile, only shows this if you get killed by it
            projectile.width = 8;  //Set the hitbox width
            projectile.height = 8;  //Set the hitbox height
            projectile.aiStyle = 1; //How the projectile works
            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.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
            projectile.timeLeft = 400; //The amount of time the projectile is alive for
            aiType = 1; // this is the projectile ai style . 1 is for arrows style
        }

        public override void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
        {
            if (npc.type = NPCID.Zombie)
            {
                target.life = 0f;
            }
        }

        //After the projectile is dead
        public override void Kill(int timeLeft)
        {

            Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, (mod.ItemType("Dart1"))); // This spawns a projectile after this projectile is dead

        }

    }
}

As Jopo has said in the previous post, you would need to change "npc" to "target" inside your if statement because "npc" does not exist in the current context, meaning that the variable "npc" does not exist in your code. You can either change the NPC parameter's name to "npc" or just change "npc.type" to "target.type".

And I'm just going to add the documentation on the hook you are using right here, so don't mind this...

Code:
public override void ModifyHitNPC (NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
}

So... most of this stuff is pretty self explanatory, but in case you were wondering what "ref" is before the variable types, it's something like "reference". What this means is that instead of just sending a value over as a parameter, it sends the "reference" point of the variable instead, allowing you to modify this value, which is stored in a different location of memory, inside the hook. This means that you can change the damage using the variable "damage" to modify it. Note that changing a value in a parameter ONLY works if it has "ref" in front of the variable.
 
Back
Top Bottom