tModLoader Official tModLoader Help Thread

I have an issue regarding weakReferences and bools.
In my mod, I have it so that when a certain mod is loaded, some tiles from that mod are added to the adjTiles list. This works fine.
However, I can't get one mod's tiles to work (SacredTools); Unlike the other mods I'm including, ST has both a check to see if it's loaded and a check to see if a certain boss is downed. The mod loads fine, but when the bool activates, the tile(s) aren't added to the list. Any idea how I could fix this?
The code in question (snipped):
Code:
using Terraria.DataStructures;
using Terraria.Enums;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace UniversalCraft.Tiles
{
    public class UniversalCrafter : ModTile
    {
        public override void SetDefaults()
        {
            List<int> adjTile = new List<int>();
            for (int runs = 0; runs < 400; runs++)
            {
                <vanilla crafting stations>
            }

            if (ModLoader.GetLoadedMods().Contains("AlchemistNPC")) //This bit works.
            {
                Mod alchemistNPC = ModLoader.GetMod("AlchemistNPC");
                for (int runs = 0; runs < 400; runs++)
                {
                    adjTile.Add(alchemistNPC.TileType("WingoftheWorld"));
                    adjTile.Add(alchemistNPC.TileType("MateriaTransmutator"));
                }
            }

            if (ModLoader.GetLoadedMods().Contains("SacredTools")) //This bit doesn't.
            {
                Mod sacredTools = ModLoader.GetMod("SacredTools");

                if (DownedAbaddon == true)
                {
                    for (int runs = 0; runs < 400; runs++)
                    {
                        adjTile.Add(sacredTools.TileType("OblivionForge"));
                    }
                }
            }

            adjTiles = adjTile.ToArray();
        }

        public bool DownedAbaddon
        {
            get { return SacredTools.ModdedWorld.OblivionSpawns; }
        }
    }
}
Hastebin: https://hastebin.com/lecozuzato.cs
Build.txt file:
Code:
author = Creeper Da Snek
version = 1.2.0.1
displayName = Universal Crafter
hideCode = false
hideResources = false
homepage = https://forums.terraria.org/index.php?threads/universal-crafter.62025/
includeSource = true
weakReferences = CalamityMod, SacredTools
I have no idea why you are looping 400 times there. Anyway, DownedAbaddon will always be false when ModTile.SetDefaults runs, since that is when mods are loading. Doing something dynamic like this, I'd suggest putting that particular adjtile logic in GlobalTile.AdjTiles. Doing it in ModTile would be hard to manage since it only happens once.
 
I have no idea why you are looping 400 times there. Anyway, DownedAbaddon will always be false when ModTile.SetDefaults runs, since that is when mods are loading. Doing something dynamic like this, I'd suggest putting that particular adjtile logic in GlobalTile.AdjTiles. Doing it in ModTile would be hard to manage since it only happens once.
Alright. I've moved all the adjTiles code to a GlobalTile file. How would I add all the list items to the tile? I've tried "ModTile.adjTiles = adjTile.ToArray" inside the "if (type == [...] ))" bracket, which gave me this error:
Code:
error CS0120: An object reference is required for the non-static field, method, or property 'Terraria.ModLoader.ModTile.adjTiles'
 
Whenever I try to change my controls, the game wont allow me to left-click anything. I have to minimize the tab or hit my start button and un-minimize the tab to be able to use my left-click. But I still can't change the controls. I uninstalled and re-installed the game as a last resort and I still saw the bug. I have used tModLoader before, but the control settings functioned fine. Earlier today, I downloaded the latest version of a mod (the newest version wasn't on tModLoader; you had to download it off the forums), Calamity, and when I went to change the new controls for new content, I first experienced the bug. I went through my files and deleted the mods, re-installed tModLoader, and still got the bug. Then I went onto my backup vanilla Terraria and yet again saw the bug. Do you have any suggestions? I am un-able to play with the Calamity mod because some of its controls interfere with the default controls of Terraria.
 
Alright. I've moved all the adjTiles code to a GlobalTile file. How would I add all the list items to the tile? I've tried "ModTile.adjTiles = adjTile.ToArray" inside the "if (type == [...] ))" bracket, which gave me this error:
Code:
error CS0120: An object reference is required for the non-static field, method, or property 'Terraria.ModLoader.ModTile.adjTiles'
I didn't say to move it all, just the dynamic stuff. And the documentation says to return an int array, not sure what you are doing with ModTile.adjTiles there....maybe just come to the discord chat, this might take a while to explain.
 
How do I make a boss only shoot up

here is some code:

if (projectileTimer++ == 100) // EVERY 60 TICKS EQUALS TO 1 SECOND
{
Main.PlaySound(SoundID.NPCHit52, npc.position); // plays a sound

Player player = Main.player[npc.target];

float projectileSpeed = 12f;
int damage = 200; // The damage your projectile deals.
float knockBack = 3;
int type = mod.ProjectileType("laser5");

Vector2 velocity = Vector2.Normalize(new Vector2(player.position.X + player.width / 2, player.position.Y + player.height / 2) -
new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2)) * projectileSpeed;

Projectile.NewProjectile(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2, velocity.X, velocity.Y, type, damage, knockBack, Main.myPlayer);
projectileTimer = 0;


}
 
Last edited:
How do I make a boss only shoot up

here is some code:

if (projectileTimer++ == 100) // EVERY 60 TICKS EQUALS TO 1 SECOND
{
Main.PlaySound(SoundID.NPCHit52, npc.position); // plays a sound

Player player = Main.player[npc.target];

float projectileSpeed = 12f;
int damage = 200; // The damage your projectile deals.
float knockBack = 3;
int type = mod.ProjectileType("laser5");

Vector2 velocity = Vector2.Normalize(new Vector2(player.position.X + player.width / 2, player.position.Y + player.height / 2) -
new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2)) * projectileSpeed;

Projectile.NewProjectile(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2, velocity.X, velocity.Y, type, damage, knockBack, Main.myPlayer);
projectileTimer = 0;


}
Inside the newProjectile bit, replace velocity.X and velocity.Y with 0 and a negative number of your choice. The bigger the number, the faster it will shoot.
 
Hi guys, I've got a problem after updating tmodloader to the newest version (I'll refer to it as the .3). I have some mods downloaded, and everything was going fine till I had the .1 version. However, after i updated to .3, like a half of my mods stopped working - the game logs told me that the mods that are not working are for older versions only (.1,.2). So I decided to swap back to the .1 version, but then the other half of the mods stopped working because they are for the .3 version. Those mods are like alchemistnpc, recipebrowser, luiafk.. And now I don't know what to do. I thought about downloading older versions of those mods but I cannot find them anywhere. Any help appreciated :)
 
Hi guys, I've got a problem after updating tmodloader to the newest version (I'll refer to it as the .3). I have some mods downloaded, and everything was going fine till I had the .1 version. However, after i updated to .3, like a half of my mods stopped working - the game logs told me that the mods that are not working are for older versions only (.1,.2). So I decided to swap back to the .1 version, but then the other half of the mods stopped working because they are for the .3 version. Those mods are like alchemistnpc, recipebrowser, luiafk.. And now I don't know what to do. I thought about downloading older versions of those mods but I cannot find them anywhere. Any help appreciated :)
I think you will just have to wait till the remainder of the mods update.
 
Hi guys, I've got a problem after updating tmodloader to the newest version (I'll refer to it as the .3). I have some mods downloaded, and everything was going fine till I had the .1 version. However, after i updated to .3, like a half of my mods stopped working - the game logs told me that the mods that are not working are for older versions only (.1,.2). So I decided to swap back to the .1 version, but then the other half of the mods stopped working because they are for the .3 version. Those mods are like alchemistnpc, recipebrowser, luiafk.. And now I don't know what to do. I thought about downloading older versions of those mods but I cannot find them anywhere. Any help appreciated :)
.1 mods should have no trouble loading on .3, if you mention the actual errors you get while loading .1 mods on .3, we can probably help.
 
Can someone spot why a simple bool method isn't working?

I receive an error statement that my return is not a bool.

Specifically, the error reads
'NPCBehavior.CanBeHitByItem(NPC, Player, Item)': return type must be 'bool?' to match overridden member 'GlobalNPC.CanBeHitByItem(NPC, Player, Item)' [RedParty]'

And here's my code:
Code:
        public override bool CanBeHitByItem(NPC npc, Player player, Item item)
        {
            return (npc.Equals("Merchant") && item.netID.Equals("3509"));
        }

I am using the GlobalNPC class. I want for people to be able to attack the Merchant with pickaxes.

Thanks.
 
:pinky:When using the newest tmodloader everything works until the loading screen reaches setting up when that happens the game will stop working and force me to close it. Do you have any idea how to fix this issue?
Thanks
 
Last edited:
I want to make a sword where it shoots a projectile when it hits an enemy, instead of shooting a projectile on swing. How do I do that?

If it helps, here is the code of the item I want to implement this into.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace swordmod.Items.Weapons
{
    public class UnholyGenesis : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Unholy Genesis");
            Tooltip.SetDefault("Inflicts the fire of the elements and impedes enemy abilities");
        }
        public override void SetDefaults()
        {
            item.damage = 200;
            item.melee = true;
            item.width = 80;
            item.height = 80;
            item.useTime = 18;
            item.useAnimation = 15;
            item.useStyle = 1;
            item.knockBack = 5;
            item.value = 10000;
            item.rare = 7;
            item.UseSound = SoundID.Item20;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "BiomeCatalyst", 1);
            recipe.AddIngredient(null, "soulblade", 1);
            recipe.AddIngredient(null, "lightblade", 1);
            recipe.AddIngredient(ItemID.SoulofLight, 5);
            recipe.AddIngredient(ItemID.SoulofNight, 5);
            recipe.AddIngredient(ItemID.Ectoplasm, 5);
            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, 540);
            target.AddBuff(BuffID.Daybreak, 540);
            target.AddBuff(BuffID.Burning, 540);
        }
    }
}
 
Whenever I enter a situation (boss battle, biome, etc) that uses custom music, it locks my music slider to 0% until the music stops, at which point I can manually drag it back up.

I'm planning on uninstalling/reinstalling, but I just wanted to check to see if this was a known issue first. The only thing I saw when looking for a solution was someone with my exact problem on /r/terraria... with a single upvote and no comments, from 2 months ago. :sigh:

My mods list:
ThoriumMod
AlchemistNPC
HelpfulHotkeys
MoreChestLoot
WingSlot
imkSushisMod
MagicStorage
CalamityMod [From the mod page, not from the browser]
Fargowiltas
RecipeBrowser

It's happening for both Thorium and Calamity stuff for sure, so it's not just one of them that's bugged. My friend on the server say their music is working just fine, as well.
 
Got 6 questionI am stuck with, mainly on projectiles. :^I
1) I know how to make a projectile come from the top of the screen going downwards towards the cursor (Like the Star Wrath), but how do I make it come from the bottom of the screen going upwards towards the cursor? Do I need to change the variables to something else?
Code:
for (int index = 0; index < numberProjectiles; ++index)
            {
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(100) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //This defines the projectile width, direction and position.
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-100, 100);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile X position speed and randomness.
                float SpeedY = num17 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile Y position speed and randomness.
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 1.50f, SpeedY * 0.65f, ProjectileID.StarWrath, damage * 1, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5)); //The "Star Wrath" projectile's velocity is 35%  less than the original projectile's speed (0.65f).
            }
            return false;
2) How do I make my projectile spawn a 6 x 1 column of fire, like the Cursed Flames weapon?
3) How do I make a 'Nettle Burst' or 'Vilethorn'-like projectile which shoots a spear-like projectile stopping after around 20 tiles or so?
4) Is there a code for shooting projectiles 'minigun' style?
5) How to make projectiles spawn where my cursor is?
6) How to make projectiles spawn in a circle, slightly away and pointing to the cursor?
 
Last edited:
我想知道是安装了Terraria的tModLoader如何使用Texture Pack
[doublepost=1520761676,1520761612][/doublepost]我想知道是安装了Terraria的tModLoader如何使用Texture Pack
[doublepost=1520761768][/doublepost]I want to know is installed tModLoader of Terraria how to use Texture PackI
 
我想知道是安装了Terraria的tModLoader如何使用Texture Pack
[doublepost=1520761676,1520761612][/doublepost]我想知道是安装了Terraria的tModLoader如何使用Texture Pack
[doublepost=1520761768][/doublepost]I want to know is installed tModLoader of Terraria how to use Texture PackI
place zip files in Documents\My Games\Terraria\ModLoader\TexturePacks
 
Hey, I'm posting this here because I'm getting the issue while on tModLoader.
My brother is trying to join my world, and when he does, he is prompted with a password, but in this password field he cannot type anything, none of the buttons on the keyboard do anything. Is anyone familiar with this bug?
~~~EDIT: It seems that nothing in Terraria is accepting keyboard text input.
 
I want to know what can I do to open tModLoader
 

Attachments

  • %N4(PI2T[ZH`2KH0{X54ASS.png
    %N4(PI2T[ZH`2KH0{X54ASS.png
    31.7 KB · Views: 242
Back
Top Bottom