tModLoader Official tModLoader Help Thread

ok i look and try thanks :D

Edit: but it also says that the "width" and "height" factor doesn't exist in this context
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Aoa.Items.Weapons
{
    public class dragonslayerspear : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dragonslayer Spear";
            item.damage = 160;
            item.toolTip = "The Spear of Ornstein, one of the four knights who hunted down the dragons. It kept it's thunderous power to hunt down your foes.";
            item.melee = true;
            item.width = 38;
            item.height = 38;
            item.scale = 1.1f;
            item.maxStack = 1;
            item.useTime = 30;
            item.useAnimation = 30;
            item.knockBack = 4f;
            item.useSound = 1;
            item.noMelee = true;
            item.noUseGraphic = true;
            item.useTurn = true;
            item.useStyle = 5;
            item.value = Item.sellPrice(0, 1, 0, 0);
            item.rare = 5;
            item.shoot = mod.ProjectileType("dragonslayerspearprojectile");
            item.shootSpeed = 5f;
        }
        public override void AddRecipes()  //How to craft this item
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Wood, 10);   //you need 10 Wood
            recipe.AddTile(TileID.WorkBenches);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
this is it

Edit: but the problem only shows up when I insert your piece of code
 
Last edited:
No error. So you send probably the wrong file. (Or i have miss a thing, but visualstudio say not error and me too)
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Aoa.Items.Weapons
{
    public class dragonslayerspear : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dragonslayer Spear";
            item.damage = 160;
            item.toolTip = "The Spear of Ornstein, one of the four knights of Gwyn who hunted down the dragons. It kept it's thunderous power to hunt down your foes.";
            item.melee = true;
            item.width = 38;
            item.height = 38;
            item.scale = 1.1f;
            item.maxStack = 1;
            item.useTime = 30;
            item.useAnimation = 30;
            item.knockBack = 4f;
            item.useSound = 1;
            item.noMelee = true;
            item.noUseGraphic = true;
            item.useTurn = true;
            item.useStyle = 5;
            item.value = Item.sellPrice(0, 1, 0, 0);
            item.rare = 5;
            item.shoot = mod.ProjectileType("dragonslayerspearprojectile");
            item.shootSpeed = 5f;
        }
        public override void AddRecipes()  //How to craft this item
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Wood, 10);   //you need 10 Wood
            recipe.AddTile(TileID.WorkBenches);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        { 
            int idx = Projectile.NewProjectile(position.X+(float)width, position.Y+(float)height, speedX, speedY, mod.ProjectileType("thunderbolt"), damage, knockBack, item.owner, 0,0);
            return true; // spear proj
        }
    }
}
this is the full code with the error
 
You know than width and height do not exist ? If you want call that, you need:
-private int width; in the class.
-int width; in the method shoot
-take the width give per the method( here you have not)

Or call the real width than you want, this is item.width.

So that:
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)
{
int idx = Projectile.NewProjectile(position.X+(float)item.width, position.Y+(float)item.height, speedX, speedY, mod.ProjectileType("thunderbolt"), damage, knockBack, item.owner, 0,0);
return true; // spear proj
}
But, i have just fail than i have give you the code, this is that than you put:
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)
{
int idx = Projectile.NewProjectile(position.X, position.Y+, speedX, speedY, mod.ProjectileType("thunderbolt"), damage, knockBack, item.owner, 0,0);
return true; // spear proj
}

You know why my code is broken than i give you? Because i have create a special width+ height for place better the spawn of the projectile, and i have forgot remove , sorry
 
Send the code, so ^^.
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TerrariaEnhanced.Projectiles
{
    public class DemonKnife : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.VampireKnife);
            projectile.name = "Demon Knife";
        }
       
        public override void AI()
        {
            projectile.ai[0] += 1f;
            if (projectile.ai[0] >= 30f)
            {
                projectile.alpha += 3;
                projectile.damage = (int)((double)projectile.damage * 0.9);
                projectile.knockBack = (float)((int)((double)projectile.knockBack * 0.9));
            }
            if (projectile.ai[0] < 30f)
            {
                projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
            }
            if (projectile.velocity.Y > 16f)
            {
                projectile.velocity.Y = 16f;
            }
            float num472 = projectile.Center.X;
            float num473 = projectile.Center.Y;
            float num474 = 400f;
            bool flag17 = false;
            for (int num475 = 0; num475 < 200; num475++)
            {
                if (Main.npc[num475].CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1))
                {
                    float num476 = Main.npc[num475].position.X + (float)(Main.npc[num475].width / 2);
                    float num477 = Main.npc[num475].position.Y + (float)(Main.npc[num475].height / 2);
                    float num478 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num476) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num477);
                    if (num478 < num474)
                    {
                        num474 = num478;
                        num472 = num476;
                        num473 = num477;
                        flag17 = true;
                    }
                }
            }
            if (flag17)
            {
                float num483 = 3f;
                num483 = 6f;
                Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                float num484 = num472 - vector35.X;
                float num485 = num473 - vector35.Y;
                float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485));
                num486 = num483 / num486;
                num484 *= num486;
                num485 *= num486;
                projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f;
                projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f;
                return;
            }
            if (Main.rand.Next(6) == 0)
            {
                Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 20, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f);
            }
        }
       
        public override void Kill(int timeLeft)
        {
            for (int num303 = 0; num303 < 3; num303++)
            {
                int num304 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 20, 0f, 0f, 100, default(Color), 0.8f);
                Main.dust[num304].noGravity = true;
                Main.dust[num304].velocity *= 1.2f;
                Main.dust[num304].velocity -= projectile.oldVelocity * 0.3f;
            }
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.player[Main.myPlayer].lifeSteal <= 0f)
            {
                return;
            }
            Main.player[Main.myPlayer].lifeSteal -= num;
            int num2 = projectile.owner;
            Projectile.NewProjectile(target.position.X, target.position.Y, 0f, 0f, mod.ProjectileType("DemonHeal"), 0, 0f, projectile.owner, (float)num2, num);
        }
    }
}
 
no problem, but none of the codes you sent works either :/

when I try the first i can load it but the spear doesn't shoot anything

when I try the second i get these:
c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,71) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,73) : error CS1026: ) expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,79) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,79) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,81) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,87) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,87) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,89) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,122) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,122) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,124) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,130) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,130) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,132) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,141) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,141) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,143) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,153) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,153) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,155) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,156) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,156) : error CS1525: Invalid expression term ','

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,157) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,158) : error CS1002: ; expected

c:\Users\Erwin\Documents\My Games\Terraria\ModLoader\Mod Sources\Aoa\Items\Weapons\dragonslayerspear.cs(44,158) : error CS1525: Invalid expression term ')'
 
Because i have forgot remove a thing, you can re-read for be sure than the code give per a guy is good? :p
I have forgot remove a "+"

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
int idx = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("thunderbolt"), damage, knockBack, item.owner, 0,0);
return true; // spear proj
}
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Aoa.Items.Weapons
{
    public class dragonslayerspear : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dragonslayer Spear";
            item.damage = 160;
            item.toolTip = "The Spear of Ornstein, one of the four knights of Gwyn who hunted down the dragons. It kept it's thunderous power to hunt down your foes.";
            item.melee = true;
            item.width = 38;
            item.height = 38;
            item.scale = 1.1f;
            item.maxStack = 1;
            item.useTime = 30;
            item.useAnimation = 30;
            item.knockBack = 4f;
            item.useSound = 1;
            item.noMelee = true;
            item.noUseGraphic = true;
            item.useTurn = false;
            item.useStyle = 5;
            item.value = Item.sellPrice(0, 1, 0, 0);
            item.rare = 5;
            item.shoot = mod.ProjectileType("dragonslayerspearprojectile");
            item.shootSpeed = 5f;
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int idx = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("thunderbolt"), damage, knockBack, item.owner, 0,0);
            return true; // spear proj
        }
        public override void AddRecipes()  //How to craft this item
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Wood, 10);   //you need 10 Wood
            recipe.AddTile(TileID.WorkBenches);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }       
    }
}
of the spear
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Aoa.Projectiles
{
    public class thunderbolt : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Thunderbolt";  //projectile name
            projectile.width = 20;       //projectile width
            projectile.height = 28;  //projectile height
            projectile.friendly = true;      //make that the projectile will not damage you
            projectile.melee = true;         //
            projectile.tileCollide = true;   //make that the projectile will be destroed if it hits the terrain
            projectile.penetrate = 0;      //how many npc will penetrate
            projectile.timeLeft = 200;   //how many time this projectile has before disepire
            projectile.light = 0.75f;    // projectile light
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;  
        }
        public override void AI()           //this make that the projectile will face the corect way
        {                                                           // |
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; 
        }
    }
}
and the projectile i want to shoot
 
Back
Top Bottom