tModLoader Official tModLoader Help Thread

Game recently starting crashing after a minute or so of playing in a world. Have not changed anything and have tested with the mods I'm using and no mods at all and still get the same result. No error log, no details, nothing. Just a crash. I use a bluetooth speaker as my audio device that seems to be the only thing that fixes it. If I use my headset that's just wireless through a dongle it's fine, but my speaker seems to make it crash, but not with any other games or audio streams. It crashes the game and then my speaker is disconnected from the computer and I have to turn it off and back on for it to reconnect.
 
I hope someone sees this and hope I’m asking in the right place:

Since i got a new computer, i´ve been having problems with tmodloader. Every time I start the game, there´s a chance that it would "restart" by going to windowed mode and greeting me with a language selection screen, like i had just installed it. Also, what often happens is my worlds sometimes just fail to load, with there being no backups according to the text that shows up. I believe these problems are related.

If anyone knows the solution to these problems, please let me know.
 
i know this is an old post but i have a question: how to code in a shimmer transmutation (like a sundial changes to a moondial) thats what i want to know and how to code in something like the neptunes shell and how to make accesories be above the armour
 
Last edited:
i know this is an old post but i have a question: how to code in a shimmer transmutation (like a sundial changes to a moondial) thats what i want to know
If you would like to have your custom item be shimmered directly into another item, 1 to 1, then you can set ItemID.Sets.ShimmerTransformToItem. You would normally do this in ModItem.SetStaticDefaults(). Here is an example:
C#:
public class MyModItem : ModItem
{
    // ... ... ...
    public override void SetStaticDefaults()
    {
        ItemID.Sets.ShimmerTransformToItem[this.Type] = ItemID.CopperShortsword;
    }
    // ... ... ...
}
In this example, MyModItem will be turned into a copper short sword when shimmered.
Note that when using this direct conversion, the resulting stack sizes of all output items will be equal to the stack size of the input item.
 
If you would like to have your custom item be shimmered directly into another item, 1 to 1, then you can set ItemID.Sets.ShimmerTransformToItem. You would normally do this in ModItem.SetStaticDefaults(). Here is an example:
C#:
public class MyModItem : ModItem
{
    // ... ... ...
    public override void SetStaticDefaults()
    {
        ItemID.Sets.ShimmerTransformToItem[this.Type] = ItemID.CopperShortsword;
    }
    // ... ... ...
}
In this example, MyModItem will be turned into a copper short sword when shimmered.
Note that when using this direct conversion, the resulting stack sizes of all output items will be equal to the stack size of the input item.
thanks
 
Is there any way to modify the mechs' natural spawn conditions? I am making a boss that needs to be killed in order to "awaken" them.
 
Is there any way to modify the mechs' natural spawn conditions? I am making a boss that needs to be killed in order to "awaken" them.
you probably can using a globalNPC file
 
you probably can using a globalNPC file
Their spawn logic is far from that of regular NPCs (they're bosses after all), so changing their spawn chance in any way would be futile. I could just:
C#:
public override void OnSpawn(NPC npc, IEntitySource source)
    { if (!DownedBossSystem.downedBoss && npc.type is NPCID.Retinazer or NPCID.Spazmatism or NPCID.SkeletronPrime or NPCID.TheDestroyer) npc.active = false; }
But the next question would be how to remove the warning in the beginning of the night. Overriding their spawning logic would be a simpler and more elegant approach.

Edit: I figured it out.
C#:
public class MyMod : Mod
{
    public override void Load()
    {
        On_Main.NewText_string_byte_byte_byte += StopMechSpawnMSG;
    }

    private void StopMechSpawnMSG(On_Main.orig_NewText_string_byte_byte_byte orig, string text, byte R, byte G, byte B)
    {
        string msg28 = Language.GetTextValue("LegacyMisc.28");
        string msg29 = Language.GetTextValue("LegacyMisc.29");
        string msg30 = Language.GetTextValue("LegacyMisc.30");
        if (!DownedBossSystem.downedBoss && (text == msg28 || text == msg29 || text == msg30)) return;

        orig(text, R, G, B);
    }

    public override void Unload()
    {
        On_Main.NewText_string_byte_byte_byte -= StopMechSpawnMSG;
    }
}
Still, this is rather a temporary solution for me. Any suggestions/corrections are welcome.
 
Last edited:
Can't generate text because I have no idea how Microsoft.Xna.Framework.Rectangle or what location is. I know it's a set of x,y coordinates to determine where it spawns, but inputing player.Center just doesnt work. Im new to c# programming
CombatText.NewText(player.Center, Color.Green, 3, false, false);
C#:
CombatText.NewText(player.Center, Color.Green, d4, false, false);
 
Last edited:
Can't generate text because I have no idea how Microsoft.Xna.Framework.Rectangle or what location is. I know it's a set of x,y coordinates to determine where it spawns, but inputing player.Center just doesnt work. Im new to c# programming
CombatText.NewText(player.Center, Color.Green, 3, false, false);
C#:
CombatText.NewText(player.Center, Color.Green, d4, false, false);
The first argument of both overloads of CombatText.NewText() is a Rectangle.
The Rectangle struct is defined in the "Microsoft.Xna.Framework" namespace, which means you will need a "using" at the top of your file with that namespace to access it. The Rectangle struct has 4 variables that compose it (all of type int) describing the rectangle's X, Y, Width, and Height. The constructor takes 4 values to represent those in that order.
The X and Y of this rectangle specify the center of the text to create, and the Width and Height define the range of the randomization of the position. The second argument is the color, of course. The third argument is the only difference between the 2 overloads, one taking an int and the other taking a String.
C#:
CombatText.NewText(new Rectangle((int)Player.Center.X, (int)Player.Center.Y, 0, 0), Color.Red, "word!");
CombatText.NewText(new Rectangle((int)Player.Center.X, (int)Player.Center.Y, 32, 16), Color.Blue, 53);
There are also 2 more arguments that are option called "dramatic" and "dot". They both default to false and just change some things for the text. I don't know what they are normally used for.
 
Thanks, I ended up figuring it out in another way, but yours is waaay cleaner. I just found it hard because I first couldn't use Vector2, but then I found out you can split it into the players x and y, but then I tried inputing the Rectangle (player.center.x, player.center, 0, 0), and it wasn't working. Now that I look at both codes, i realize I was missing the "new". Do you mind explaining why it's needed?

Code:
int first = (int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10);
            int second = (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10);
            Rectangle rectangle1 = new Rectangle(first, second, 0, 0);
            Random rand = new Random();

            int d4 = rand.Next(1, 5);  // creates a number between 1 and 4
            CombatText.NewText(rectangle1, color1, d4, false, false);
Muuuuuch cleaner
Code:
CombatText.NewText(new Rectangle((int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10), (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10),0,0), new Color(151, 107, 75), d4, false, false);
 
Last edited:
Thanks, I ended up figuring it out in another way, but yours is waaay cleaner. I just found it hard because I first couldn't use Vector2, but then I found out you can split it into the players x and y, but then I tried inputing the Rectangle (player.center.x, player.center, 0, 0), and it wasn't working. Now that I look at both codes, i realize I was missing the "new". Do you mind explaining why it's needed?

Code:
int first = (int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10);
            int second = (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10);
            Rectangle rectangle1 = new Rectangle(first, second, 0, 0);
            Random rand = new Random();

            int d4 = rand.Next(1, 5);  // creates a number between 1 and 4
            CombatText.NewText(rectangle1, color1, d4, false, false);
Muuuuuch cleaner
Code:
CombatText.NewText(new Rectangle((int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10), (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10),0,0), new Color(151, 107, 75), d4, false, false);
because you're creating a NEW rectangle, that's pretty basic programming knowledge

I HIGHLY recommend getting into C# programming first and understanding all the basics, as well as using Visual Studio with the TML coding environment setup so you have an easier time coding

I spent my first 3 years coding my mod in notepad++ and that :red: was NOT a pleasant experience I'll tell you that
I do not wish such trial and error nonsense upon anyone
 
because you're creating a NEW rectangle, that's pretty basic programming knowledge

I HIGHLY recommend getting into C# programming first and understanding all the basics, as well as using Visual Studio with the TML coding environment setup so you have an easier time coding

I spent my first 3 years coding my mod in notepad++ and that :red: was NOT a pleasant experience I'll tell you that
I do not wish such trial and error nonsense upon anyone
I sure am learning lots. I do understand the basics of programming, the problem is lots of them have different ways of doing it.
Also, can I ask you for help? I´m making a mod based on luck, and I have a 20 sided dice that applies the same buff with different results by saving a rnd in Projectile.ai[0], but I can't seem to take that value from my weapon/item (it deals no damage but i like to see it spawn a projectile cause it looks cool) and move that same value into a different class, in this case, my Buff/Debuff. Is there any workaround besides having the Buff/Debuff having its own rnd so I don't loose the visuals?

Also, I'm planning on making some card games (go fish, blackjack, poker, Solitaire, Uno) and play against a TownNpc as a way to unlock/win stuff. Could there be a way were I use Items given by a shop to play inside the same shop. Would that be possible?

TL;DR Need to move an int from one class to another, and could I play card games in a shop menu?
Thanks :D
 
Last edited:
Thanks, I ended up figuring it out in another way, but yours is waaay cleaner. I just found it hard because I first couldn't use Vector2, but then I found out you can split it into the players x and y, but then I tried inputing the Rectangle (player.center.x, player.center, 0, 0), and it wasn't working. Now that I look at both codes, i realize I was missing the "new". Do you mind explaining why it's needed?

Code:
int first = (int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10);
            int second = (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10);
            Rectangle rectangle1 = new Rectangle(first, second, 0, 0);
            Random rand = new Random();

            int d4 = rand.Next(1, 5);  // creates a number between 1 and 4
            CombatText.NewText(rectangle1, color1, d4, false, false);
Muuuuuch cleaner
Code:
CombatText.NewText(new Rectangle((int)player.Center.X + (player.direction * 20) + (int)(player.velocity.X * 10), (int)player.Center.Y + 40 + (int)(player.velocity.Y * 10),0,0), new Color(151, 107, 75), d4, false, false);
Well, it's actually a bit confusing, but the new keyword works differently for things of type struct and things of type object. When using the new keyword, it is only ever placed before a call to the type's constructor (a special function called when defining/creating an instance). Constructors themselves are always named the same thing as their type and are always preceded with the new keyword (as far as I know).
- When using "new" for a struct's constructor, an instance of the struct is returned.
- When using "new" for an object's constructor, a (managed) pointer to a newly "malloced" instance of the type of the object is returned.

"Rectangle" is a struct, which means that when you do Rectangle myRect = new Rectangle(64, 96, 8, 8), you are making a an instance of a "Rectangle" and storing/copying it to the variable named "myRect". In the case of CombatText.NewText(), you are using the new keyword to make a new "Rectangle" that is being passed directly to the function. Storing this in a variable and then passing the variable will have the exact same result, but with extra steps.

If you have a variable who's type is a struct (like one of type "Rectangle") and you want to define it but don't need the constructor, you can do: Rectangle myRect = default(Rectangle). This will set all values/fields the struct is composed of to their default. The difference between using default and using new is that using default does not actually make a new instance of the struct, but instead, directly sets the values of the variable itself (remember, new makes a new instance of the struct from the constructor which is then copied when other things are assigned to it). It's also important to note that since the default keyword just modifies a variable, trying to use it as a function argument will result in the compiler: creating an extra local variable, defining it with default, then passing this variable as the argument.
 
Hey, I have been having an error, and I can't figure out why, mainly because I am struggling with reading it . I was wondering if anyone could help me. I have a screenshot and the document as well. I was running fine yesterday, and I haven't changed anything, minus my Hz on my speakers, thinking that was the problem, but I have now changed that back.

and a link to the mods I am using
Steam Workshop::Expanded Terraria

1751560786967.png
 

Attachments

  • 1751560667322.png
    1751560667322.png
    97.9 KB · Views: 4
  • client.log
    client.log
    705.3 KB · Views: 5
Last edited:
Disable the Fancy Lighting mod
 
Back
Top Bottom