Override Void for Melee Projectiles

xd Demi

Terrarian
What is the Override void for projectiles basically exactly like the meowmere. The sword that I'm making is basically the meowmere retextured and is more powerful but shoots projectiles slower but deals more damage. I got the basics down for coding except for this Override void () I just want to know what the override void

Error :

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(102,30) : error CS0111: Type 'DemiMod.Items.Barkbasenji' already defines a member called 'OnHitNPC' with the same parameter types

Code :

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

namespace DemiMod.Items
{
public class Barkbasenji : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Barkbasenji"); //The weapon's name when shown in-game.
DisplayName.SetDefault("BarkbasenjiProj");
}

public override void SetDefaults()
{
item.useStyle = 1;
item.UseSound = SoundID.Item1;
item.damage = 270;
item.width = 50;
item.height = 58;
item.useTime = 20;
item.useAnimation = 18;
item.melee = true;
item.expert = false;
item.autoReuse = true;
item.noUseGraphic = false;
item.useTurn = true;
item.noMelee = false;
item.value = Item.sellPrice(1, 50, 0, 0);
item.shoot = 0;
item.scale = 0.7f;
}

public override bool AltFunctionUse(Player player)
{
return true;
}

public override bool CanUseItem(Player player)
{
if (player.altFunctionUse == 2)
{
item.useStyle = 1;
item.UseSound = SoundID.Item1;
item.damage = 270;
item.width = 50;
item.height = 58;
item.useTime = 20;
item.useAnimation = 18;
item.melee = true;
item.expert = false;
item.autoReuse = true;
item.noUseGraphic = true;
item.useTurn = false;
item.noMelee = false;
item.value = Item.sellPrice(1, 50, 0, 0);
item.shoot = mod.ProjectileType("Barkbasenji");
item.shootSpeed = 18f;
item.scale = 0.7f;
}
else
{
item.useStyle = 1;
item.UseSound = SoundID.Item1;
item.damage = 270;
item.width = 50;
item.height = 58;
item.useTime = 20;
item.useAnimation = 18;
item.melee = true;
item.expert = false;
item.autoReuse = true;
item.noUseGraphic = false;
item.useTurn = true;
item.noMelee = false;
item.value = Item.sellPrice(1, 50, 0, 0);
item.shoot = 0;
item.scale = 0.7f;
}
return base.CanUseItem(player);
}

public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.CursedInferno, 0 * 60); //Add CursedInferno buff to the NPC for 5 seconds.
projectile.width = 24;
projectile.height = 24;
projectile.timeLeft = 15;
projectile.penetrate = -1;
projectile.scale = 0.6f;
projectile.ignoreWater = true;
projectile.melee = true;
projectile.friendly = true;
projectile.tileCollide = true;
}

public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
//The sound code for the projectile.
projectile.soundDelay--;
if (projectile.soundDelay <= 0)
{
Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 15);
projectile.soundDelay = 45;
}

//How the projectile works.
Player player = Main.player[projectile.owner];
if (Main.myPlayer == projectile.owner)
{
if (!player.channel || player.noItems || player.CCed)
{
projectile.Kill();
}
}
Lighting.AddLight(projectile.Center, 0f, 1f, 0f); //This is the Projectile's light color (RGB)

projectile.Center = player.MountedCenter;
projectile.position.X += player.width / 2 * player.direction;
projectile.spriteDirection = player.direction;
projectile.rotation += 0.36f * player.direction; //This is the Projectile's Spinning/Rotation Speed
if (projectile.rotation > MathHelper.TwoPi)
{
projectile.rotation -= MathHelper.TwoPi;
}
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D texture = Main.projectileTexture[projectile.type];
spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, null, Color.White, projectile.rotation, new Vector2(texture.Width / 2, texture.Height / 2), projectile.scale, projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f);
return false;
}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.CursedInferno, 1 * 60); //Add CursedInferno Buff to the NPC for 5 seconds.
target.immune[projectile.owner] = 2;
}
}
}
 

Attachments

You should only have one override void OnHitNPC. Move the code into one.
 
I did that and got about 20 errors, I'm going to try fix it:

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Accessories\Losthandle.cs(48,21) : error CS1001: Identifier expected

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(91,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(92,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(93,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(94,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(95,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(96,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(97,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(98,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(99,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(100,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(101,17) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(103,40) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(103,66) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(104,17) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(108,20) : error CS0136: A local variable named 'player' cannot be declared in this scope because it would give a different meaning to 'player', which is already used in a 'parent or current' scope to denote something else

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(108,41) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(109,34) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(113,21) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(116,31) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(118,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(119,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(120,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(121,13) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(122,17) : error CS0103: The name 'projectile' does not exist in the current context

c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\DemiMod\Items\Barkbasenji.cs(124,17) : error CS0103: The name 'projectile' does not exist in the current context
 
Why do you have the projectile code inside the code for the weapon? They should be in separate files.
 
Oh okay they were separate but I put them together because I saw a post that seemed like it was supposed to be one code. I'll separate them and see what errors occur.
 
I have the same problem. I have an on hit effect for two different swords and got the same error.
sword 1
Code:
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria;

namespace TorchicFlamesMod.Items
{
    public class BlazingFlameSword : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Blazing Flame Sword");
            Tooltip.SetDefault("You have proven yourself worthy of the full power of this sword! It now emanates a brilliant flame and has a powerful, icy aura coursing through it!");
        }
        public override void SetDefaults()
        {
            item.damage = 450;
            item.melee = true;
            item.width = 100;
            item.height = 100;
            item.useTime = 3;
            item.useAnimation = 8;
            item.useStyle = 1;
            item.knockBack = 7;
            item.value = 100000000;
            item.rare = 13;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.shoot = mod.ProjectileType("BlazingBeam");
            item.shootSpeed = 8f
        }

            public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) {
            // Add Onfire buff to the NPC for a while.
            // 60 frames = 1 second
            target.AddBuff(BuffID.OnFire, 3600);
        }
        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) {
            // Add Onfire buff to the NPC for a while.
            // 60 frames = 1 second
            target.AddBuff(BuffID.Frostburn, 3600);
        }
        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) {
            // Add Onfire buff to the NPC for a while.
            // 60 frames = 1 second
            target.AddBuff(BuffID.Daybroken, 3600);
        }
            public override void MeleeEffects(Player player, Rectangle hitbox) {
            if (Main.rand.NextBool(3)) {
                //Emit dusts when swing the sword
                Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, DustID.Fire);
            }
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(mod.ItemType("BurningFlameSword"), 1);
            recipe.AddIngredient(ItemID.Meowmere, 1);
            recipe.AddIngredient(ItemID.Daybreak, 1);
            recipe.AddIngredient(ItemID.SolarFragment, 20);
            recipe.AddTile(TileID.AncientManipulator);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    public override bool AltFunctionUse(Player player) {
            return true;
        }
    public override bool CanUseItem(Player player) {
            if (player.altFunctionUse == 2) {
                item.useStyle = 3;
                item.useTime = 2;
                item.useAnimation = 7;
                item.damage = 400;
                item.shoot = ProjectileID.Fireball;
                item.shootSpeed = 5f
            }
            else {
                item.useStyle = 1;
                item.useTime = 3;
                item.useAnimation = 8;
                item.damage = 450;
                item.shoot = mod.ProjectileType("BlazingBeam");
                item.shootSpeed = 8f
            }
            return base.CanUseItem(player);
        }

    }
}

sword 2
Code:
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria;

namespace TorchicFlamesMod.Items
{
    public class BurningFlameSword : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Burning Flame Sword");
            Tooltip.SetDefault("This powered up sword harnesses the power of the supreme flame well");
        }
        public override void SetDefaults()
        {
            item.damage = 140;
            item.melee = true;
            item.width = 60;
            item.height = 60;
            item.useTime = 5;
            item.useAnimation = 14;
            item.useStyle = 1;
            item.knockBack = 5;
            item.value = 100000;
            item.rare = 9;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

            public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) {
            // Add Onfire buff to the NPC for a while.
            // 60 frames = 1 second
            target.AddBuff(BuffID.OnFire, 1800);
        }
            public override void MeleeEffects(Player player, Rectangle hitbox) {
            if (Main.rand.NextBool(3)) {
                //Emit dusts when swing the sword
                Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, DustID.Fire);
            }
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(mod.ItemType("BasicFlameSword"), 1);
            recipe.AddIngredient(mod.ItemType("Ashesofaherossword"), 1);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
[doublepost=1546376461,1546376241][/doublepost]Also, can you not have multiple on hit effects for a sword? When i temporarily removed sword 2, I got the same error, but it said OnHitNPC has already been defined in sword 1
[doublepost=1546376903][/doublepost]If anyone knows how to fix this, please help!
[doublepost=1546377037][/doublepost]I compacted the code in sword 1 with the onhit effects
 
Back
Top Bottom