• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Begin your search for Journey's End information here and here. Please report bugs and issues for Journey's End here.
  • For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

tModLoader Official tModLoader Help Thread

Will-Banksy

Skeletron Prime
Alright, thanks so much! :D
Even though that is a complicated process, I will learn.
Probably be useful to create a Helper class with some commonly used/useful functions in, like hasInInventory and hasEquippedAccessory

I’m new to modding and planning on adding a Flower that only spawns in crimson, but for it to make sense I need to make the Deathweed stop spawning in the crimson. I have the code for a flower, but I don’t know how to stop the Deathweed from spawing.
(If anyone wants to know I’m going to make each flower make a potion)
You can probably change that in GlobalTile, but I wouldn't know how sorry
 

AHIBoy

Steampunker
Probably be useful to create a Helper class with some commonly used/useful functions in, like hasInInventory and hasEquippedAccessory


You can probably change that in GlobalTile, but I wouldn't know how sorry
That’s ok, now I can look up Global Tiles since I have not heard of those.
 

jonahr

Terrarian
How do you assign a town NPC head sprite to a town NPC? Is it a line of code? Do you have to name the head sprite file something special?
 

Dacern

Terrarian
Here is some code for an item I'm making, the game seems to load it perfectly fine, but it does not shoot, and it always displays 0 ammo. I knew it probably wouldn't work, as I'm not experienced in coding, and I had nothing to go off of here. I'm wondering if someone can help me to get the slingshot item to use stone blocks instead of typical ammunition.

public class Slingshot : ModItem

{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Uses stone.");
}
public override void SetDefaults()

{


item.damage = 15;
item.ranged = true;
item.width = 20;
item.height = 33;
item.useTime = 25;
item.useAnimation = 25;
item.crit = 13;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 3;
item.value = 200;
item.rare = 1;
item.UseSound = SoundID.Item5;
item.autoReuse = false;
item.shoot = mod.ProjectileType("StoneProj");
item.shootSpeed = 25f;
item.useAmmo = ItemID.StoneBlock;

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Cobweb, 3);
recipe.AddIngredient(ModContent.ItemType<Stick>(), 1);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}


}
 

sparks08

Skeletron
How do you assign a town NPC head sprite to a town NPC? Is it a line of code? Do you have to name the head sprite file something special?
Add [AutoloadHead] before the public class line. Like this:
C#:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace ModName.NPCs
{
    [AutoloadHead]
    public class ModNPC : ModNPC
    {
Make sure you have a texture for the head, make sure it has a _Head.png at the end of it.
 

sparks08

Skeletron
Here is some code for an item I'm making, the game seems to load it perfectly fine, but it does not shoot, and it always displays 0 ammo. I knew it probably wouldn't work, as I'm not experienced in coding, and I had nothing to go off of here. I'm wondering if someone can help me to get the slingshot item to use stone blocks instead of typical ammunition.

public class Slingshot : ModItem

{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Uses stone.");
}
public override void SetDefaults()

{


item.damage = 15;
item.ranged = true;
item.width = 20;
item.height = 33;
item.useTime = 25;
item.useAnimation = 25;
item.crit = 13;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 3;
item.value = 200;
item.rare = 1;
item.UseSound = SoundID.Item5;
item.autoReuse = false;
item.shoot = mod.ProjectileType("StoneProj");
item.shootSpeed = 25f;
item.useAmmo = ItemID.StoneBlock;

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Cobweb, 3);
recipe.AddIngredient(ModContent.ItemType<Stick>(), 1);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}


}
It most likely seems to be due to the fact that the stone block is a vanilla item. Thus, you can do this:
C#:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System;
using Terraria.DataStructures;
using Terraria.Localization;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Linq;

namespace ModName.Items
{
    public class StoneBlock : GlobalItem
    {
        public override void SetDefaults(Item item) {
            if (item.type == ItemID.StoneBlock) {
                item.damage = 15;
                item.ranged = true;
                item.shoot = mod.ProjectileType("StoneProj");
                item.ammo = item.type; // This makes it so the ammo type of this Stone Block is the first one in it's class.
                //item.ammo = ItemID.StoneBlock; // An alternative way to do it, since this is a vanilla item, it has an ID.
            }
        }
    }
}
It makes it so the Stone Block is ammo, and can be used for ammo
 

sparks08

Skeletron
Cannot implicitly convert type 'Terraria.Item[]' to 'bool' Why you gotta do this too me Terraria!?!?!?

Here is the part the error is located in.
C#:
    public static void AI(Item item, Player player, NPC npc) {
        if (npc.type == 2) {
            if (player.miscEquips) {
                if (item.type == ModContent.ItemType<SightNecklace>()) {
                    npc.friendly = true;
                    npc.aiStyle = 24;
                    npc.damage = 0;
                }
            }
        }
    }
Of course, I expected it to be complicated, but didn't expect it to be thorny nor tedious.
 

Dacern

Terrarian
I'm going to need more help, as I'm trying to get custom crates to appear, but for that, I'll need to know internal names for biomes. (Or zones, I guess.) The only one I know is that the ocean is called the beach internally, but can anyone help with the rest? If possible, I would like to know about the underworld, granite, spider cave, marble, surface, tundra, mushroom biome, the underground, caverns, and space. Thank you.
 
Last edited:

Will-Banksy

Skeletron Prime
Cannot implicitly convert type 'Terraria.Item[]' to 'bool' Why you gotta do this too me Terraria!?!?!?

Here is the part the error is located in.
C#:
    public static void AI(Item item, Player player, NPC npc) {
        if (npc.type == 2) {
            if (player.miscEquips) {
                if (item.type == ModContent.ItemType<SightNecklace>()) {
                    npc.friendly = true;
                    npc.aiStyle = 24;
                    npc.damage = 0;
                }
            }
        }
    }
Of course, I expected it to be complicated, but didn't expect it to be thorny nor tedious.
You seem to be checking if player.miscEquips is true, but it's an Item[] array, and it can't convert that to a boolean. What exactly is the if(player.miscEquips) meant to be checking?

Can somebody kindly explain how to use tModLoader's decompiler? I was told that it can be used to decompile 1.4.0.5 in this thread, but I can't understand how to work it.
tModLoader doesn't have a decompiler (that I'm aware of), so you're going to have to use something like ilspy or dnspy (or avalonia ilspy if you're on Linux or mac).

I'm going to need more help, as I'm trying to get custom crates to appear, but for that, I'll need to know internal names for biomes. (Or zones, I guess.) The only one I know is that the ocean is called the beach internally, but can anyone help with the rest? If possible, I would like to know about the underworld, granite, spider cave, marble, surface, tundra, mushroom biome, the underground, caverns, and space. Thank you.
If you have access to Terraria's source code, you should be able to find them in Main. Search for 'zone' in Main
 

Phenomalix008

Retinazer
So, I was trying to download tml, but it wouldn't download.

My Steam account is a shared account (I think it's called family share or something). Every time I clicked "Install" from the Steam store, a screen saying "preparing to install" appeared for a split second, and then the page refreshed.

Eventually my dad (the owner of the shared account) downloaded it from his account, and it started working. But now, every time I accept a game invite, it takes me to the Steam store, as if I don't have it downloaded.

Not sure if this is a Steam problem or a Tml problem, but please tell me if there's a solution %:sigh:

Edit: I managed to fix the problem. Hope this doesn't happen to the rest of you!
 
Last edited:

SgtSitdown

Terrarian
Hey all!

So I'm not sure if this is the place to post this, but I am starting work on a mod of my own ( :D ) and I need some help XD
I'm new to coding, but I feel like with a little help I could pick it up quite fast.

So I was wondering, would anyone be willing to sit with me for maybe like, 30mins or so, and just give me the basics of "this means this" in the context of Tmodloader?

I would really appreciate any help honestly, as the mod isn't super-advanced, just long-winded.

Thanks in advance! ^.^
 

Will-Banksy

Skeletron Prime
Hey all!

So I'm not sure if this is the place to post this, but I am starting work on a mod of my own ( :D ) and I need some help XD
I'm new to coding, but I feel like with a little help I could pick it up quite fast.

So I was wondering, would anyone be willing to sit with me for maybe like, 30mins or so, and just give me the basics of "this means this" in the context of Tmodloader?

I would really appreciate any help honestly, as the mod isn't super-advanced, just long-winded.

Thanks in advance! ^.^
I can certainly try to help you with any questions you have, but the best way to learn is to just jump into it. Do have at least a quick look at a C# tutorial (tutorialspoint has a good one I think) as I had no idea how to code when I started modding, and didn't have a look at any tutorials, and it really slowed me down. Once you understand C# a bit (especially object-orientated-programming) you start to understand tModLoader.
tModLoader wiki
tModLoader Documentation (VERY useful)
Download and have a look at Example Mod (download from 'Creating Mods' section here) and feel free to dm me if you need any direct help or whatever
 

NameTaken

Skeletron
Does anybody know how i could make my magic weapon have a 10% chance to shoot out a different projectile? Also, how do i make a projectile shoot projectiles like how the north pole's projectile shoots the snowflakes?
 

Will-Banksy

Skeletron Prime
Does anybody know how i could make my magic weapon have a 10% chance to shoot out a different projectile? Also, how do i make a projectile shoot projectiles like how the north pole's projectile shoots the snowflakes?
In your magic weapon item's class, you'll need to override the Shoot method like so:
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)
{
    // Check for that 10% chance
    if(Main.rand.Next(10) == 0)
    {
        // Change projectileTypeHere to whatever projectile type you want to shoot, with the 10% chance
        type = projectileTypeHere;
    }
    return true; // Fire projectile - with a 10% chance, the type of projectile fired will be changed from item.shoot to projectileTypeHere
}
As for a projectile firing a projectile, have a look at Projectile.NewProjectile(...), calling that method with the appropriate arguments in your projectile's AI() method.
Example code to go in AI():
Code:
if(projectile.timeLeft % 20 == 0) // Every 20 frames/ticks
{
    // Fire a North Pole Snowflake at this projectile's center with velocity of 1 on the y-axis. Change the arguments to whatever you want
    Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0, 1, ProjectileID.NorthPoleSnowflake, damageAmountHere, knockbackAmountHere, projectile.owner);
}
 

NameTaken

Skeletron
In your magic weapon item's class, you'll need to override the Shoot method like so:
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)
{
    // Check for that 10% chance
    if(Main.rand.Next(10) == 0)
    {
        // Change projectileTypeHere to whatever projectile type you want to shoot, with the 10% chance
        type = projectileTypeHere;
    }
    return true; // Fire projectile - with a 10% chance, the type of projectile fired will be changed from item.shoot to projectileTypeHere
}
As for a projectile firing a projectile, have a look at Projectile.NewProjectile(...), calling that method with the appropriate arguments in your projectile's AI() method.
Example code to go in AI():
Code:
if(projectile.timeLeft % 20 == 0) // Every 20 frames/ticks
{
    // Fire a North Pole Snowflake at this projectile's center with velocity of 1 on the y-axis. Change the arguments to whatever you want
    Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0, 1, ProjectileID.NorthPoleSnowflake, damageAmountHere, knockbackAmountHere, projectile.owner);
}
Thanks for the help! It works perfectly!
 

shoelid

Terrarian
Hi everybody! Just looking for a bit of advice. I noticed when messing around with item.buffType there are several ways to assign the same buff. Which way is best for which situation? I've put some examples down below.
C#:
item.buffType = mod.BuffType("GhostbladeBuff"); //can also use item.buffType = BuffType<Buffs.GhostbladeBuff>();

item.buffType = BuffID.AmmoBox; //seems to be used for all vanilla buffs

item.buffType = mod.BuffType("string");

item.buffType = mod.BuffType<modBuff>();//is obsolete

item.buffType = ModContent.BuffType<modBuff>(); //works

item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet.
 

sparks08

Skeletron
Hi everybody! Just looking for a bit of advice. I noticed when messing around with item.buffType there are several ways to assign the same buff. Which way is best for which situation? I've put some examples down below.
C#:
item.buffType = mod.BuffType("GhostbladeBuff"); //can also use item.buffType = BuffType<Buffs.GhostbladeBuff>();

item.buffType = BuffID.AmmoBox; //seems to be used for all vanilla buffs

item.buffType = mod.BuffType("string");

item.buffType = mod.BuffType<modBuff>();//is obsolete

item.buffType = ModContent.BuffType<modBuff>(); //works

item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet.
I'd be glad to help!

First, let's eliminate BuffID.Buff;, why? Because it can only be used for vanilla buffs. Mod buffs don't have stable IDs, another mod may overwrite their IDs.

Next, because mod.BuffType<modBuff>(); is obsolete (you stated it too,) it won't be used.

I also haven't tried item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet. either.

This leaves us to these three.

C#:
item.buffType = mod.BuffType("modBuff");

item.buffType = BuffType<Buffs.modBuff>();

item.buffType = ModContent.BuffType<modBuff>();
In my opinion. mod.BuffType("modBuff"); is the easiest, due to having a simple, easy to remember, code line.
And this can be used too if you want: item.buffType = ModContent.BuffType<modBuff>();
I'm not sure about item.buffType = ModContent.BuffType<modBuff>(); but sure, if it works then you can use it.

You're welcome!
 
Top Bottom