Standalone [1.3] tModLoader - A Modding API

I recently tried to create a weapon but when I try to craft it the weapon isn't there


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

namespace ultsword.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(2);
recipe.AddIngredient(15);
recipe.AddIngredient(176);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}

try this:

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

namespace ultsword.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null,ItemID.DirtBlock);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}
 
Added support for mod and dll dependencies
How does one add a dll dependency to the mod? :) My Snippet code will now be a .dll
Because, this is the error I get when loading Snippet.dll
Code:
Could not load file or assembly 'Snippet, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
   at BaseMod.Main.Load()
   at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

Both mod and Snippet.dll use the same framework, Snippet.dll is in Mod Sources and Mods folder, so what's going wrong? ^^

Edit: Building works (Snippet.dll in Mod Sources), but Loading the mod doesn't and gives the above error.
 
Last edited:
Oh god, THANK YOU <3
[DOUBLEPOST=1438672728,1438672559][/DOUBLEPOST]

Not really, no. There's the docs on github which tell you every method there is though, for each class. If you've setup your mod using MVS then it's really easy to find out what's possible due to Intellisense

MVS?
 
I think he means Microsoft Visual Studio, an IDE to make coding easier. Basically, you just add the Terraria.exe that tModLoader is in under the "References" section of the Solution Window, and things related to tModLoader and Terraria will now be seen by intellisense. Basically, if you do something like, "Mod.whatever" after the "." it will come up with a list of public properties and methods from the class, in this case "Mod.cs".

Link to VS 2015 HERE (The community one is free and works well enough for me).
 
Why are you calling it Snippet? if it contains a bunch of useful method you'd might as well call it BaseMod or something

Because the base behind the idea is to provide methods (Snippets) that can do something for you in 1 line that would otherwise take many more lines, such as the QuickRecipe. And as tModLoader grows, I think it'll be quite useful.
BaseMod (currently still 'Extended ExampleMod' in thread) was more on my take to share my 'blank template' that I would use myself, including the Snippet .dll

Microsoft Visual Studio http://forums.terraria.org/index.ph...et-up-your-mod-using-visual-studio-mvs.26476/
 
I recently tried to create a weapon but when I try to craft it the weapon isn't there


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

namespace ultsword.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(2);
recipe.AddIngredient(15);
recipe.AddIngredient(176);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}
Just to make sure, you set your mod's autoload property to true, right?

Can you give me an example of animation code please? I'm bad with this things (Very need to learn CSharp)
It can go something like this, just as an example:
Code:
frameCounter++;
if(frameCounter > 5)
{
    frameCounter = 0;
    frame++;
    frame %= 5;
}


How does one add a dll dependency to the mod? :) My Snippet code will now be a .dll
Because, this is the error I get when loading Snippet.dll
Code:
Could not load file or assembly 'Snippet, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
   at BaseMod.Main.Load()
   at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

Both mod and Snippet.dll use the same framework, Snippet.dll is in Mod Sources and Mods folder, so what's going wrong? ^^

Edit: Building works (Snippet.dll in Mod Sources), but Loading the mod doesn't and gives the above error.
Have you tried putting the dll file in the same directory as Terraria.exe? Dll dependencies are one of the things I haven't tested yet, since I didn't expect many people to use them, but the fact that the mod built is a good sign.
 
Have you tried putting the dll file in the same directory as Terraria.exe? Dll dependencies are one of the things I haven't tested yet, since I didn't expect many people to use them, but the fact that the mod built is a good sign.
It works when I add it to the Terraria folder. But now it seems my code is more buggy, and also WAY slower. When writing 20 projectiles non .dll it would be done in a split second, now it took around 10-15 secs for 20 projectiles. ;o

edit: nvm, I actually added a code that made is so slow (working around with tiles) woops. my bad
 
I'm trying to get an item crafted at an anvil and this is what I have, recipe.AddTile(TileID.Anvil); I'm pretty sure whats in the parentheses is wrong.
 
Just to make sure, you set your mod's autoload property to true, right?


It can go something like this, just as an example:
Code:
frameCounter++;
if(frameCounter > 5)
{
    frameCounter = 0;
    frame++;
    frame %= 5;
}
So I made like this:
Code:
AnimateTile(ref int frame, ref int frameCounter)
{
    frameCounter++;
    if(frameCounter > 8)
    {
        frameCounter = 0;
        frame++;
        frame %= 8;
    }
}
But it now says that
Code:
c:\My Documents\My Games\Terraria\ModLoader\Mod Sources\Tremor\Tiles\BlastFurnaceTile.cs(28,1) : error CS1520: Methods should include the return type
28 line is "AnimateTile(ref int frame, ref int frameCounter)".
 
So I made like this:
Code:
AnimateTile(ref int frame, ref int frameCounter)
{
    frameCounter++;
    if(frameCounter > 8)
    {
        frameCounter = 0;
        frame++;
        frame %= 8;
    }
}
But it now says that
Code:
c:\My Documents\My Games\Terraria\ModLoader\Mod Sources\Tremor\Tiles\BlastFurnaceTile.cs(28,1) : error CS1520: Methods should include the return type
28 line is "AnimateTile(ref int frame, ref int frameCounter)".
who the hell would use a method but not override it?
 
try this:

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

namespace ultsword.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null,ItemID.DirtBlock);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}
it gives me these error when i try to build it
c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\core.cs(19,25) : error CS0118: 'ultsword' is a 'namespace' but is used like a 'type'

c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(28,27) : error CS0103: The name 'ItemID' does not exist in the current context
here is my core.cs
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using core;

namespace core{
public class Core : Mod
{
public override void SetModInfo(out string name, ref ModProperties properties)
{
name = "core";
properties.Autoload = true;
}

public override void Load()
{
AddItem("ultsword", new ultsword());



}

/* public override void AddRecipes();
{
RecipeHelper.AddVanillaRecipes(this);
} */
}
}
 
it gives me these error when i try to build it
c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\core.cs(19,25) : error CS0118: 'ultsword' is a 'namespace' but is used like a 'type'

c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(28,27) : error CS0103: The name 'ItemID' does not exist in the current context
here is my core.cs
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using core;

namespace core{
public class Core : Mod
{
public override void SetModInfo(out string name, ref ModProperties properties)
{
name = "core";
properties.Autoload = true;
}

public override void Load()
{
AddItem("ultsword", new ultsword());



}

/* public override void AddRecipes();
{
RecipeHelper.AddVanillaRecipes(this);
} */
}
}

(c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\core.cs(19,25) : error CS0118: 'ultsword' is a 'namespace' but is used like a 'type')
I think you need to use (Your mod Name).Items

(c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(28,27) : error CS0103: The name 'ItemID' does not exist in the current context)
Just include the Terraria.ID

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

namespace core.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null,ItemID.DirtBlock);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}

Pro Tip: Use Visual Studio to Make these files. It wold be soo easy to see the errors =D
 
(c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\core.cs(19,25) : error CS0118: 'ultsword' is a 'namespace' but is used like a 'type')
I think you need to use (Your mod Name).Items

(c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(28,27) : error CS0103: The name 'ItemID' does not exist in the current context)
Just include the Terraria.ID

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

namespace core.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null,ItemID.DirtBlock);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
}

Pro Tip: Use Visual Studio to Make these files. It wold be soo easy to see the errors =D
now its giving me the error
c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(34,2) : error CS1513: } expected
 
now its giving me the error
c:\Users\joshuaho\Documents\My Games\Terraria\ModLoader\Mod Sources\ultsword\ultsword.cs(34,2) : error CS1513: } expected
Your either missing a "}" or have an extra ")", ";" or something else that is unnecessary in place of the "}", and the culprit is likely line 34 in your code. If these solutions don't sound right, try posting your code in a code tag.
 
Your either missing a "}" or have an extra ")", ";" or something else that is unnecessary in place of the "}", and the culprit is likely line 34 in your code. If these solutions don't sound right, try posting your code in a code tag.
i already have a } in my 34 line
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace core.Items {
public class ultsword : ModItem
{
public override void SetDefaults()
{
item.name = "ultsword";
item.damage = 500;
item.melee = true;
item.width = 40;
item.height = 40;
item.toolTip = "die.";
item.useTime = 1;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 14;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null,ItemID.DirtBlock);
recipe.SetResult(this);
//recipe.AddTile(134);
recipe.AddRecipe();
}
}
 
Back
Top Bottom