tModLoader Tutorial: [3] Items

So, slight error, this is the logs:

Code:
c:\Users\TheGeckoGamer\Documents\My Games\Terraria\ModLoader\Mod Sources\VarietyMod\VarietyMod\Items\SplitterAxe.cs(35,39) : error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)

c:\Users\TheGeckoGamer\Documents\My Games\Terraria\ModLoader\Mod Sources\VarietyMod\VarietyMod\Items\SplitterAxe.cs(35,54) : error CS0246: The type or namespace name 'NPC' could not be found (are you missing a using directive or an assembly reference?)

and this is my code:

Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace VarietyMod.Items
{
    public class SplitterAxe : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Armor Splitter";
            item.damage = 50;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.toolTip = "An axe that can break even the toughest of armor.";
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = 100000;
            item.rare = 2;
            item.useSound = 1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {

            target.AddBuff(BuffID.BrokenArmor, 30);

        }
    }
}

I don't know what this issue is, I'm just trying to make the axe give the broken armor debuff.
Player and NPC are classes in Terraria, so you need using Terraria; at the top.
 
I have a couple questions:

So the mod skeleton has the use animation set to this:
If I wanted to make a spear, would I change the animation, and if so, what should I change it to?

Also, would 3 cover spears, or just shortswords?

EDIT #5,608: I can't read.

Also, I keep getting this error:
Code:
Missing mod: GoofsnSpoofs/Items/Scalpel
   at Terraria.ModLoader.ModLoader.GetTexture(String name)
   at Terraria.ModLoader.Mod.SetupContent()
   at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
This is my code:
Code:
using Terraria.ID;

using Terraria.ModLoader;


namespace GoofsnSpoofs.Items
{

   public class Scalpel : ModItem
   {

     public override void SetDefaults()
     {

       item.name = "Scalpel";

       item.damage = 7;

       item.melee = true;

       item.width = 60;

       item.height = 60;

       item.toolTip = "";

       item.useTime = 20;

       item.useAnimation = 20;

       item.useStyle = 3;

       item.knockBack = 4;

       item.value = 160;

       item.rare = 0;

       item.UseSound = SoundID.Item19;

       item.autoReuse = false;
       }


     public override void AddRecipes()

     {
       ModRecipe recipe = new ModRecipe(mod);

       recipe.AddIngredient(ItemID.IronBar, 5);

       recipe.AddTile(TileID.WorkBenches);

       recipe.SetResult(this);
  
     recipe.AddRecipe();

     }

   }

}
Am I using the wrong file type for my image, or did I mess something up in the coding?
 
Last edited:
I have a couple questions:

So the mod skeleton has the use animation set to this:
If I wanted to make a spear, would I change the animation, and if so, what should I change it to?

Also, would 3 cover spears, or just shortswords?

EDIT: I can't read.

Also, I keep getting this error:
Code:
Missing mod: GoofsnSpoofs/Items/Scalpel
   at Terraria.ModLoader.ModLoader.GetTexture(String name)
   at Terraria.ModLoader.Mod.SetupContent()
   at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

Am I using the wrong file type for my image, or did I mess something up in the coding?
http://forums.terraria.org/index.ph...der-a-modding-api.23726/page-679#post-1122935
 
Thanks, the filename I unzipped to was capitalized in a spot where the original .zip wasn't. Whoops.

Edit: New issue,

Code:
c:\Users\-meep-\Documents\My Games\Terraria\ModLoader\Mod Sources\GoofsNSpoofs\Items\Weapons\Scalpel.cs(1,26) : error CS0234: The type or namespace name 'Projectiles' does not exist in the namespace 'GoofsNSpoofs.Items' (are you missing an assembly reference?)
                 ----
using GoofsNSpoofs.Items.Projectiles;
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;

using Terraria.ModLoader;


namespace GoofsNSpoofs.Items
.Weapons
{

   public class Scalpel : ModItem

   {

     public override void SetDefaults()
     {

       item.name = "Scalpel";

       item.damage = 7;
       item.melee = true;

       item.width = 60;

       item.height = 60;

       item.scale = 1.2f;
       item.maxStack = 1;
       item.toolTip = "It's almost larger than you.";

       item.useTime = 20;

       item.useAnimation = 24;

       item.useStyle = 5;

       item.knockBack = 3f;

       item.useTurn = true;
       item.value = 160;

       item.rare = 0;

       item.UseSound = SoundID.Item19;

       item.autoReuse = false;
       item.noMelee = true;
       item.noUseGraphic = true;
       item.shoot = mod.ProjectileType("ScalpelProjectile");
       item.shootSpeed = 4f;
       
       }


     public override void AddRecipes()

     {

       ModRecipe recipe = new ModRecipe(mod);

       recipe.AddIngredient(ItemID.IronBar, 6);

       recipe.anyIronBar = true;
       recipe.AddTile(TileID.WorkBenches);

       recipe.SetResult(this);
   
       recipe.AddRecipe();

     }

   }

}
 
Last edited:
Could you post the error and the code it's pointing to? Otherwise we have nothing to work with.
this is just someof the coding that is from the tutorial so i have the basics saved into my pc. but i think there is a code im missing or something because when i open modloader and go to mod sources and just to build + reload mod it just simply gives me this error...

an error acurred while compiling a mod
c:\User\kayko\OneDrive\Documents\My Games\Terraria\Modloader\Mod Sources\MyFirstMod.cs(78,10) : error CS1585: Member modifier 'static' must precede the member type and name


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyFirstMod
{
    class MyFirstMod : Mod
    {
        public MyFirstMod()
        {   
           
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
       
         public override void AddRecipes()
         {   
         ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin);
        recipe.AddRecipe();
       
        recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock, 10);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin, 10);
        recipe.AddRecipe();
       
        recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.Wood);
        recipe.anyWood = true;
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin);
        recipe.AddRecipe();
       
        recipe = ModRecipe(this);
        recipe.AddIngredient(ItemID.GoldCoin);
        recipe.needWater = true;
        recipe.SetResult(ItemID.Wood);
        recipe.AddRecipe();
       
        List<Recipe> rec = Main.recipe.ToList();
        int numberRecipesRemoved = 0;
        numberRecipesRemoved += rec.RemoveAll(x => x.createItem.type == ItemID.AlphabetStatueT);
        Main.recipe = rec.ToArray();
        Array.Resize(ref Main.recipe, Recipe.maxRecipes);
        Recipe.numRecipes -= numberRecipesRemoved;
       
        List<Recipe> rec = Main.recipe.ToList();
        int numberRecipesRemoved = 0;
        numberRecipesRemoved += rec.RemoveAll(x => x.createItem.type == ItemID.AlphabetStatueU);
        rec.Where(x => x.createItem.type == ItemID.AlphabetStatueT).ToList().ForEach(s =>
        {
            for (int i = 0; i < s.requiredItem.Length; i++
            {
                s.requiredItem[i] = new Item();
            }
            s.requiredItem[0].SetDefaults(ItemID.Wood, false);
            s.requiredItem[0].stack = 10;
           
            s.createItem.SetDefaults(ItemID.Clentaminator, false);
            s.createItem.stack = 10;
        });
        Main.recipe = rec.ToArray();
        Array.Resize(ref Main.recipe, Recipe.maxRecipes);
        Recipe.numRecipes -= numberRecipesRemoved;
    }
   
    pupblic static void Log(Array array)
    {
        foreach (var item in array)
        }
            ErrorLogger.Log(item.ToString());
        }
           
        }
    }
}
 
this is just someof the coding that is from the tutorial so i have the basics saved into my pc. but i think there is a code im missing or something because when i open modloader and go to mod sources and just to build + reload mod it just simply gives me this error...

an error acurred while compiling a mod
c:\User\kayko\OneDrive\Documents\My Games\Terraria\Modloader\Mod Sources\MyFirstMod.cs(78,10) : error CS1585: Member modifier 'static' must precede the member type and name


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyFirstMod
{
    class MyFirstMod : Mod
    {
        public MyFirstMod()
        {  
          
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
      
         public override void AddRecipes()
         {  
         ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin);
        recipe.AddRecipe();
      
        recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock, 10);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin, 10);
        recipe.AddRecipe();
      
        recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.Wood);
        recipe.anyWood = true;
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.GoldCoin);
        recipe.AddRecipe();
      
        recipe = ModRecipe(this);
        recipe.AddIngredient(ItemID.GoldCoin);
        recipe.needWater = true;
        recipe.SetResult(ItemID.Wood);
        recipe.AddRecipe();
      
        List<Recipe> rec = Main.recipe.ToList();
        int numberRecipesRemoved = 0;
        numberRecipesRemoved += rec.RemoveAll(x => x.createItem.type == ItemID.AlphabetStatueT);
        Main.recipe = rec.ToArray();
        Array.Resize(ref Main.recipe, Recipe.maxRecipes);
        Recipe.numRecipes -= numberRecipesRemoved;
      
        List<Recipe> rec = Main.recipe.ToList();
        int numberRecipesRemoved = 0;
        numberRecipesRemoved += rec.RemoveAll(x => x.createItem.type == ItemID.AlphabetStatueU);
        rec.Where(x => x.createItem.type == ItemID.AlphabetStatueT).ToList().ForEach(s =>
        {
            for (int i = 0; i < s.requiredItem.Length; i++
            {
                s.requiredItem[i] = new Item();
            }
            s.requiredItem[0].SetDefaults(ItemID.Wood, false);
            s.requiredItem[0].stack = 10;
          
            s.createItem.SetDefaults(ItemID.Clentaminator, false);
            s.createItem.stack = 10;
        });
        Main.recipe = rec.ToArray();
        Array.Resize(ref Main.recipe, Recipe.maxRecipes);
        Recipe.numRecipes -= numberRecipesRemoved;
    }
  
    pupblic static void Log(Array array)
    {
        foreach (var item in array)
        }
            ErrorLogger.Log(item.ToString());
        }
          
        }
    }
}
You've spelled public wrong at your last method signature :p
 
You've spelled public wrong at your last method signature :p
for :red: sakes you have got to be kidding me!!!!! lol omg i hate my life haha
[doublepost=1486834112,1486833846][/doublepost]
You've spelled public wrong at your last method signature :p
we have a problem... another error

except now it says

an error acurred while compiling a mod
c:\User\kayko\OneDrive\Documents\My Games\Terraria\Modloader\Mod Sources\MyFirstMod.cs(82,19) : error CS1519: Invalid token '(' in class, struct, or interface member declaration
 
for :red: sakes you have got to be kidding me!!!!! lol omg i hate my life haha
[doublepost=1486834112,1486833846][/doublepost]
we have a problem... another error

except now it says

an error acurred while compiling a mod
c:\User\kayko\OneDrive\Documents\My Games\Terraria\Modloader\Mod Sources\MyFirstMod.cs(82,19) : error CS1519: Invalid token '(' in class, struct, or interface member declaration
You forgot to close the for loop on the part where you remove the recipes.
 
where i dont know coding very well thats al ive started and dont really understand where to close the loop
[doublepost=1486835102,1486834609][/doublepost]yeah i cant find out where to close the loop for all i know it looks fine to me but im new to modding and trying to atleast finish my foundation of the mod so i can start adding items and stuff but i cant finish the foundation of the mod in the first place
You forgot to close the for loop on the part where you remove the recipes.
 
where i dont know coding very well thats al ive started and dont really understand where to close the loop
[doublepost=1486835102,1486834609][/doublepost]yeah i cant find out where to close the loop for all i know it looks fine to me but im new to modding and trying to atleast finish my foundation of the mod so i can start adding items and stuff but i cant finish the foundation of the mod in the first place
Code:
for (int i = 0; i < s.requiredItem.Length; i++
That's the line I'm talking about. You'll need to put a ) at the end of that line.
 
it says now the same error
Double check all your syntax. By this I mean your line endings (semicolons and the sorts) and check ALL your opening and closing brackets. For every opening bracket there should be a closing at the correct position.
 
ive
Double check all your syntax. By this I mean your line endings (semicolons and the sorts) and check ALL your opening and closing brackets. For every opening bracket there should be a closing at the correct position.
ive tried everything everything looks finej even tried another moding foundation thats suppose to work with tmodloader but still doesnt work
 
ive

ive tried everything everything looks finej even tried another moding foundation thats suppose to work with tmodloader but still doesnt work
Could you post your current error and code once again? I'll be home later today, so I can rework your code to show you the do's and don'ts.
 
this is my current code i reset it because nothing was working and yet this one still doesnt work this is the only part im having troubles with. te items and stuff i can code but this foundation for that wont work in general yet i cant seem to find any duplicate of anything even removed everything from the mod sources that might have same codes
Code:
using Terraria.ModLoader;

namespace LenZoReforged
{
    class LenZoReforged : Mod
    {
        public LenZoReforged()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
    }
}

error CS1703: An assembly with the same identity 'Newtonsoft.json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' has already been imported. Try removing one of the duplicate references.
 
this is my current code i reset it because nothing was working and yet this one still doesnt work this is the only part im having troubles with. te items and stuff i can code but this foundation for that wont work in general yet i cant seem to find any duplicate of anything even removed everything from the mod sources that might have same codes
Code:
using Terraria.ModLoader;

namespace LenZoReforged
{
    class LenZoReforged : Mod
    {
        public LenZoReforged()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
    }
}

error CS1703: An assembly with the same identity 'Newtonsoft.json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' has already been imported. Try removing one of the duplicate references.
Look in your Steam Terraria folder. If you see a file called `Newtonsoft.json` remove it.
 
Back
Top Bottom