tModLoader Official tModLoader Help Thread

Can somone help me do a throwing weapon ? I've been trying to do it for about a week now. I want to make a weapon similar to a shuriken or throwing knife.
PS. I need help with coding, not spriting.
 

aitype needs to be changed to aiType in order for it to be recognized.

Everything is case-sensitive in C#, so upper and lower-case are important.
 
try adding this to your ModPlayer class
Code:
public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit)
        {
            for (int l = 3; l < 8 + player.extraAccessorySlots; l++)
            {
                if (player.armor[l].type == base.mod.ItemType(">Your Itemname Here<"))
                {
                    target.AddBuff(>Debuff ID< , >How many frames the debuff lasts<);
                    break;
                }
            }
        }
Replace the arrows > <



I usually drag and drop the files into my project.
How do I make it so it's a set bonus for an armor set instead of an accessory?
 
How do I make it so it's a set bonus for an armor set instead of an accessory?

By checking for the armor instead

Code:
public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit)
{
    if (player.armor[0].type == base.mod.ItemType(">Your Helmet Here<")&&
        player.armor[1].type == base.mod.ItemType(">Your Chestplate Here<")&&
        player.armor[2].type == base.mod.ItemType(">Your Leggings Here<"))
    {
       target.AddBuff(>Debuff ID< , >How many frames the debuff lasts<);
    }
}
 
By checking for the armor instead

Code:
public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit)
{
    if (player.armor[0].type == base.mod.ItemType(">Your Helmet Here<")&&
        player.armor[1].type == base.mod.ItemType(">Your Chestplate Here<")&&
        player.armor[2].type == base.mod.ItemType(">Your Leggings Here<"))
    {
       target.AddBuff(>Debuff ID< , >How many frames the debuff lasts<);
    }
}
Now I get to sound like an idiot by asking how to apply the buff to the player, when they hit something with x equiped~
 
Now I get to sound like an idiot by asking how to apply the buff to the player, when they hit something with x equiped~
Replace target.AddBuff with player.AddBuff
The modplayer class has a Player instance that get's inherited, so no need to add it as a parameter.
 
My table is really bugging out with the graphics, table is segmented, ect.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace SpiritMod.Items.Spirit.Tiles
{
    public class SpiritTable : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileTable[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style2x3);
            TileObjectData.newTile.CoordinateHeights = new int[]{ 18 };
            TileObjectData.addTile(Type);
            AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
            AddMapEntry(new Color(30, 144, 255), "Spirit Table");
            disableSmartCursor = true;
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }
        public override void KillMultiTile(int i, int j, int frameX, int frameY)
        {
            Item.NewItem(i * 16, j * 16, 32, 16, mod.ItemType("SpiritTable"));
        }
    }
}
SpiritTable.png
 
My table is really bugging out with the graphics, table is segmented, ect.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace SpiritMod.Items.Spirit.Tiles
{
    public class SpiritTable : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileTable[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style2x3);
            TileObjectData.newTile.CoordinateHeights = new int[]{ 18 };
            TileObjectData.addTile(Type);
            AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
            AddMapEntry(new Color(30, 144, 255), "Spirit Table");
            disableSmartCursor = true;
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }
        public override void KillMultiTile(int i, int j, int frameX, int frameY)
        {
            Item.NewItem(i * 16, j * 16, 32, 16, mod.ItemType("SpiritTable"));
        }
    }
}
View attachment 111963

An ingame screenshot could help out.


Code:
TileObjectData.newTile.CopyFrom(TileObjectData.Style2x3);
Isn't the left number the width and the right one the height?
try swapping them.
 
Last edited:
How would I make a boss give off an environmental effect while it's active? For example, the Nebula Tower/Monolith effect?
 
I've started making a mod from the ground up, and I have no errors from my mod, however I am running into warnings that cause runtime failures from ALL five of the References, which are the XNA Framework files attached to the OP here. When in-game, none of the UI elements show except for the map. Can anyone help interpret this problem in any way?

These are one of the warnings displayed in MVS, and they all display their respective message:

Code:
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Terraria", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

Here's the code from the main file of my mod if it helps.

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

namespace RiruNinjaMain
{
    public class RiruNinjaMod : Mod
    {

        public void SetModInfo(out string name, ref string version, ref string author, ref ModProperties properties)
        {
            name = "Riru Ninja Mod";
            version = "v0.1";
            author = "Rirutsukusan";
            properties.Autoload = true;
            properties.AutoloadSounds = true;
        }

        public override void Load()
        {
            //SetGlobalItem(new MuramasaSword());
            AddItem("Muramasa[RiruNinjaMod]", new MuramasaSword(), "RiruNinjaMod/Weapons/MuramasaSword");
        }



        public override void AddRecipes()
        {
          /*  ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.DirtBlock, 999);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.LifeCrystal, 15);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.ManaCrystal, 9);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(null, "Muramasa[RiruNinjaMod]");
            recipe.AddRecipe();*/
        }
    }
}
 
Last edited:
does anyone know how to do a shortsword where it shoots a projectile straight from its tip that when hitting a target does 4 projectiles straight up, down, left, right?
 
I've started making a mod from the ground up, and I have no errors from my mod, however I am running into warnings that cause runtime failures from ALL five of the References, which are the XNA Framework files attached to the OP here. When in-game, none of the UI elements show except for the map. Can anyone help interpret this problem in any way?

These are one of the warnings displayed in MVS, and they all display their respective message:

Code:
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Terraria", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

Here's the code from the main file of my mod if it helps.

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

namespace RiruNinjaMain
{
    public class RiruNinjaMod : Mod
    {

        public void SetModInfo(out string name, ref string version, ref string author, ref ModProperties properties)
        {
            name = "Riru Ninja Mod";
            version = "v0.1";
            author = "Rirutsukusan";
            properties.Autoload = true;
            properties.AutoloadSounds = true;
        }

        public override void Load()
        {
            //SetGlobalItem(new MuramasaSword());
            AddItem("Muramasa[RiruNinjaMod]", new MuramasaSword(), "RiruNinjaMod/Weapons/MuramasaSword");
        }



        public override void AddRecipes()
        {
          /*  ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.DirtBlock, 999);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.LifeCrystal, 15);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(ItemID.ManaCrystal, 9);
            recipe.AddRecipe();

            recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.DirtBlock);
            recipe.SetResult(null, "Muramasa[RiruNinjaMod]");
            recipe.AddRecipe();*/
        }
    }
}
You need to change things to fit the 0.8 style, (no more setmodinfo) see the news post for 0.8 for that. Also, it's odd how you are autoloading but also manually loading that item.
 
You need to change things to fit the 0.8 style, (no more setmodinfo) see the news post for 0.8 for that. Also, it's odd how you are autoloading but also manually loading that item.
Reading that may have helped a little, however i'm still facing the problem I mentioned above. Upon starting over a new project again, the very first thing I did was adding the references. I immediately ran into the said warnings again. Is there something i'm missing from this?

EDIT: I solved the problem! I clicked on the project's name in the Solution Explorer, then clicked on properties. Under the project's properties in the "Build" section, it's Platform Target was selected as "Any CPU". All I had to do was change it to x86, which was sensible to the warnings.
2oNaCiu.png


However another problem still exists, the UI elements still aren't showing up in the game. I took a look at the Example Mod's properties as well, and noticed the "Platform" Selection (Below image, beside "Configuration"). In the Example Mod, there's only one selection, and it's locked on "x86". Mine is locked on "Any CPU". Could this be the problem as to why the UI isn't showing in game?

Dml1wDS.png
 
Last edited:
x-posted from the tModLoader thread because I'm dumb and didn't realize this thread existed.

I just started messing around with tModLoader and am trying to compile something to mess around with. I pulled "ExampleSword" and its image out of the example mod and placed it in Mod Sources/DrewMod/Items/Weapons. Other than build.txt and description.txt, no other files exist under the DrewMod folder. No matter what I try, I get the following error:

Code:
error CS1704: An assembly with the same simple name 'Steamworks.NET, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.

Earlier in this thread someone said that another poster should check that nothing in the mod shares the same class name, but as this is the only item in the mod right now I don't see how that would be a problem. Someone else also brought up a file that included something to the effect of:

Code:
public Enderuim()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true,
};
}

but I don't know what file would contain this. I get this same error when I attempt to compile the example mod. I've been poking around the example mod files for something I may have missed but to no avail. I also tried removing the Steamworks.dll but that gives me a separate error saying that the file is missing. I have no prior experience with C# so I'm learning as I go.
 
x-posted from the tModLoader thread because I'm dumb and didn't realize this thread existed.

I just started messing around with tModLoader and am trying to compile something to mess around with. I pulled "ExampleSword" and its image out of the example mod and placed it in Mod Sources/DrewMod/Items/Weapons. Other than build.txt and description.txt, no other files exist under the DrewMod folder. No matter what I try, I get the following error:

Code:
error CS1704: An assembly with the same simple name 'Steamworks.NET, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.

Earlier in this thread someone said that another poster should check that nothing in the mod shares the same class name, but as this is the only item in the mod right now I don't see how that would be a problem. Someone else also brought up a file that included something to the effect of:

Code:
public Enderuim()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true,
};
}

but I don't know what file would contain this. I get this same error when I attempt to compile the example mod. I've been poking around the example mod files for something I may have missed but to no avail. I also tried removing the Steamworks.dll but that gives me a separate error saying that the file is missing. I have no prior experience with C# so I'm learning as I go.
Just to be clear, you are getting that error when building in game, correct? CSteamworks.dll should be in the terraria steam directory, you shouldn't even touch it, and it shouldn't have even come up. Try this: http://javid.ddns.net/tModLoader/generator/ModSkeletonGenerator.html and also if it's not working, show a screenshot of the error screen and your folder and folder path.
[doublepost=1463984297,1463983995][/doublepost]
Reading that may have helped a little, however i'm still facing the problem I mentioned above. Upon starting over a new project again, the very first thing I did was adding the references. I immediately ran into the said warnings again. Is there something i'm missing from this?

EDIT: I solved the problem! I clicked on the project's name in the Solution Explorer, then clicked on properties. Under the project's properties in the "Build" section, it's Platform Target was selected as "Any CPU". All I had to do was change it to x86, which was sensible to the warnings.
2oNaCiu.png


However another problem still exists, the UI elements still aren't showing up in the game. I took a look at the Example Mod's properties as well, and noticed the "Platform" Selection (Below image, beside "Configuration"). In the Example Mod, there's only one selection, and it's locked on "x86". Mine is locked on "Any CPU". Could this be the problem as to why the UI isn't showing in game?

Dml1wDS.png
None of this matters to tmodloader. tmodloader will build the mod itself and doesn't care what you have in your .sln or .csproj file.

UIElements not showing up: The main cause for this is doing something like: recipe.addTile(ItemID.Anvil); instead of the TileID

Other reasons include throwing exceptions in your code somewhere.

Anyway, if you can't see it immediately, move items out of the mod until you see your problem is fixed, or post the troubling code.
 
Back
Top Bottom