tModLoader Official tModLoader Help Thread

error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
... i know this asking a lot but can someone help me pls lol im still beginner. heres code below

Getting this issue now - error CS0115: 'Thunderbolt.Items.Weapons.Slimeeradicator.AddRecipe()': no suitable method found to override

I'm gonna put these links here. This isn't "stop asking questions and figure it out yourself", but it IS "sometimes you have to work out the answers on your own" with a little "you probably should learn some basic C# if you're going to mod Terraria."
This setup is for answering questions about modding Terraria, not about teaching folks C# from the ground up. You might get lucky and have someone who knows answer questions like these... but if you're learning both C# and Terraria modding, you'll need to get used to finding examples, looking up error messages, working out what code is doing, chasing little syntax errors, reading up on C# methods related to the hooks and methods you're trying to use, and so forth.

In the end, the problem I see is a LOT of people wanting to mod Terraria and asking the same basic questions over and over without looking first. It makes for a HUGE amount of extra material to search through just to find an answer. Being new to modding AND C#, myself, I can see the frustration from both sides. You should practice picking up habits that help you find answers, by looking for different examples. It also tends to lead you to have other ideas as you find new things!

tModLoader wiki, with tons of tutorials and examples. Try searching for "Vector2" and see how it's used in various ways here, for example!
Quick Terraria-specific C# crash course. it's only 15 pages. You may not get it all immediately, but, as you do stuff and learn things, go back, re-read it, and see how much more you know and can learn.
C# structure guide in a diagram. Keep this handy as you progress.
Example Mod. If you don't download it, read through it here. Take some time to really explore it... not just the code of the items, but the folder structure, naming conventions, and how stuff refers to other stuff.
 
Last edited:
If someone could find me the link to the Hellevator Mod, that would be great please :) i know there was on the mod page some time ago and now i can't find it...
 
Hello! I have one question, I've been looking for a solution to my problem, but I can not understand what's the matter ... Her it is:

Items/SlimeronSword
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.ModItem.AutoStaticDefaults()
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
And my cod if you need:
using Terraria.ID;
using Terraria.ModLoader;


namespace Okraminor.Items
{
public class SlimeronSword : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("SlimeronSword");
Tooltip.SetDefault("This is a modded sword.");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
Hello! I have one question, I've been looking for a solution to my problem, but I can not understand what's the matter ... Her it is:

Items/SlimeronSword
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.ModItem.AutoStaticDefaults()
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
And my cod if you need:
using Terraria.ID;
using Terraria.ModLoader;


namespace Okraminor.Items
{
public class SlimeronSword : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("SlimeronSword");
Tooltip.SetDefault("This is a modded sword.");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Your item is missing a texture.
 
Hello! I have one question, I've been looking for a solution to my problem, but I can not understand what's the matter ... Her it is:

Items/SlimeronSword
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.ModItem.AutoStaticDefaults()
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
And my cod if you need:
using Terraria.ID;
using Terraria.ModLoader;


namespace Okraminor.Items
{
public class SlimeronSword : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("SlimeronSword");
Tooltip.SetDefault("This is a modded sword.");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
https://github.com/blushiemagic/tModLoader/wiki/Basic-tModLoader-Modding-FAQ#terrariamodloadermodgettexturestring-name-error
 
hi, im trying to create a custom NPC. But i am having trouble naming the NPC.

Code:
{
            npc.name = "Custom Town NPC";   //the name displayed when hovering over the npc ingame.
            npc.townNPC = true; 
            npc.friendly = true;  
            npc.width = 18; 
            npc.height = 46; 
            npc.aiStyle = 7; 
            npc.defense = 25; 
            npc.lifeMax = 250;
;

The Npc."Name" Doesn't exist or something AS my MVS is telling me. Am i using the wrong thing?
 
hi, im trying to create a custom NPC. But i am having trouble naming the NPC.

Code:
{
            npc.name = "Custom Town NPC";   //the name displayed when hovering over the npc ingame.
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 46;
            npc.aiStyle = 7;
            npc.defense = 25;
            npc.lifeMax = 250;
;

The Npc."Name" Doesn't exist or something AS my MVS is telling me. Am i using the wrong thing?
Try this
Code:
public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Custom Town NPC");
            Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Guide];
        }

        public override void SetDefaults()
        {
            npc.width = 18;
            npc.height = 46;
            npc.defense = 25;
            npc.lifeMax = 250;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath2;
            npc.value = 60f;
            npc.aiStyle = 7;
            npc.townNPC = true;
            npc.friendly = true; 
            aiType = NPCID.Guide;
            animationType = NPCID.Guide;
 
Pleasehelp.PNG Please explain this error that happened to me all the time
 
Hey everyone. So I'm running tmodloader with calamity and overhaul, using the server client to host the world. When I first start the game, it runs at 144 FPS, then over time it gets lower and lower, the worst case scenario being a completely unplayable <30 FPS. To remedy it, I have to close and restart the terraria client. Is it just me or does everyone have this issue? And if so, is there a way to fix it? Google failed me.

My specs are: i7-7700k, 16GB 2400 RAM, GTX 1060. The Terraria files are on an SSD.
 
Can anyone tell me what happened to "Workplss"? I think I got it through the "No Ammo Required" mod (v0.10.52) but with all the searching I've done, neither of those mods exist any more and there is nothing on the forums. I got the mod October 21st and my friends got it the next day. But after that it vanished. So I was wondering if it is under a new name or what because the mod is great. Really what I'm looking for is a Wiki on the items it added, because I'm at a loss.
Thanks all.

Update:
I'm 90% sure that "Workplss" and "No Ammo Required" are one and the same, and isn't available in tModLoader. Started a wiki to help anyone else and hopefully gain the attention of the mods creator (vortexofrainbows). https://terrariamods.gamepedia.com/Workplss
 
Last edited:
Try this
Code:
public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Custom Town NPC");
            Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Guide];
        }

        public override void SetDefaults()
        {
            npc.width = 18;
            npc.height = 46;
            npc.defense = 25;
            npc.lifeMax = 250;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath2;
            npc.value = 60f;
            npc.aiStyle = 7;
            npc.townNPC = true;
            npc.friendly = true;
            aiType = NPCID.Guide;
            animationType = NPCID.Guide;
Thank you :) Did Wonders!!!!
 
Okay, I'm losing momentum because it's been two days since I've had any victories in this code, so I'm back to here.
I'm trying to animate a critter. It's currently six frames, each frame is 29 pixels high (each frame has two pixels padding at the bottom). The placement doesn't seem to be a problem at this point, but the animation won't take. Here's my animation code, so far as I've worked it out:
Code:
        public override void FindFrame(int frameHeight)
        {
            if (npc.velocity.Y == 0f)      // if no vertical movement happening...
            {
                npc.spriteDirection = npc.direction;
                if (npc.velocity.X == 0f)     // ... and if no horizontal movement, just sit there at frame 0
                {
                    npc.frame.Y = 0;
                    npc.frameCounter = 0;
                    return;
                }
                npc.frameCounter += 1;     //  ... but moving horizontally, start increasing frameCounter
                if (npc.frameCounter > 5)    
                {
                    npc.frame.Y = npc.frame.Y + 1;     // when frameCounter hits 6, increase frame by 1 and reset frameCounter
                    npc.frameCounter = 0;
                }
                if (npc.frame.Y > 5)     // if frame value is greater than 5 (i.e. 6), set it to 0 (because only six frames: 0 through 5)
                {
                    npc.frame.Y = 0;
                    return;
                }
            }
            else      // picks single frame according to movement up or down
            {
                if (npc.velocity.Y < 0f)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y = 5;
                    return;
                }
                if (npc.velocity.Y > 0f)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y = 4;
                    return;
                }
            }
        }

Problem: The critter moves forward, slowly bouncing slightly as it does, but stays at frame 0, no animation, looks like someone's moving a game piece.

Also of note: I'm using
npc.aiStyle = 7;
aiType = NPCID.Bunny;
in SetDefaults, but the critter keeps trying to move forward at a door instead of turning away like Bunnies do.

I'd be grateful for any help. I've been digging around for examples and fiddling with this for too long, and I'm starting to get burnt out being stuck on one little critter.

In this vein, are there any current guides on animating creatures? And/or AI design?
 
Last edited:
Okay, I'm losing momentum because it's been two days since I've had any victories in this code, so I'm back to here.
I'm trying to animate a critter. It's currently six frames, each frame is 29 pixels high (each frame has two pixels padding at the bottom). The placement doesn't seem to be a problem at this point, but the animation won't take. Here's my animation code, so far as I've worked it out:
Code:
        public override void FindFrame(int frameHeight)
        {
            if (npc.velocity.Y == 0f)      // if no vertical movement happening...
            {
                npc.spriteDirection = npc.direction;
                if (npc.velocity.X == 0f)     // ... and if no horizontal movement, just sit there at frame 0
                {
                    npc.frame.Y = 0;
                    npc.frameCounter = 0;
                    return;
                }
                npc.frameCounter += 1;     //  ... but moving horizontally, start increasing frameCounter
                if (npc.frameCounter > 5)
                {
                    npc.frame.Y = npc.frame.Y + 1;     // when frameCounter hits 6, increase frame by 1 and reset frameCounter
                    npc.frameCounter = 0;
                }
                if (npc.frame.Y > 5)     // if frame value is greater than 5 (i.e. 6), set it to 0 (because only six frames: 0 through 5)
                {
                    npc.frame.Y = 0;
                    return;
                }
            }
            else      // picks single frame according to movement up or down
            {
                if (npc.velocity.Y < 0f)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y = 5;
                    return;
                }
                if (npc.velocity.Y > 0f)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y = 4;
                    return;
                }
            }
        }

Problem: The critter moves forward, slowly bouncing slightly as it does, but stays at frame 0, no animation, looks like someone's moving a game piece.

Also of note: I'm using
npc.aiStyle = 7;
aiType = NPCID.Bunny;
in SetDefaults, but the critter keeps trying to move forward at a door instead of turning away like Bunnies do.

I'd be grateful for any help. I've been digging around for examples and fiddling with this for too long, and I'm starting to get burnt out being stuck on one little critter.

In this vein, are there any current guides on animating creatures? And/or AI design?
Lets see, I've never animated a NPC before but I have made a complex projectile animation, so I'll see if I can help.

npc.frame.Y is the vertical position of the NPC's texture in pixels. When you animate, you should increase this by the height of your frame instead of 1. To save time, I'll give you a snippet of how I animate my projectile.
Code:
int wFrame = 0; //Whip's frame of animation

public override void PostAI() //this is where the animation happens -- projectiles don't have FindFrame
{
    if (projectile.ai[0] == 1) //While flying
    {
        projectile.frameCounter++;
        if (projectile.frameCounter > 5) //Every 6 frames
        {
            wFrame++; //Animate!
            projectile.frameCounter = 0; //reset frame counter
        }
        if (wFrame > 10 || wFrame < 7) //After the last frame, or if outside of the flight animation
            wFrame = 7; //Go back to the first frame
        }
    }
    projectile.frame = wFrame; //sets the frame of whip to my calced frame -- projectiles are different to NPC's, though
}
Projectiles are a bit different to NPC's though. "projectile.frame = wFrame;" won't work, you'd need something more like "npc.frame.Y = wFrame * npc.frame.Height;"

Though, wFrame is short for Whip's Frame. You should probably call it something else because Whip doesn't like it if you steal his frame's name. ;)

As for the behaviour of your critter when walking into walls, I had a look through the NPC's code and found the following in the function AI_007_TownEntities.
Code:
if (this.type >= 0 && NPCID.Sets.TownCritter[this.type] && this.target == 255)
{
    this.TargetClosest(true);
    if (this.position.X < Main.player[this.target].position.X)
    {
        this.direction = 1;
        this.spriteDirection = this.direction;
    }
    if (this.position.X > Main.player[this.target].position.X)
    {
        this.direction = -1;
        this.spriteDirection = this.direction;
    }
    if (this.homeTileX == -1)
    {
        this.homeTileX = (int)((this.position.X + (float)(this.width / 2)) / 16f);
    }
}
So I think that either you need to set NPCID.Sets.TownCritter[npc.type] to true in SetStaticDefaults, or copy and clean the above code into PostAI.

Hope you find this useful. :)
 
Lets see, I've never animated a NPC before but I have made a complex projectile animation, so I'll see if I can help.
snip
If I let it run using generic critter code, the frames actually animate alright, BUT since Bunny looks for seven frames, my critter flickers out every seventh animation because it only has six frames.

It seems more like I'm just having trouble getting the frames for my custom animation to advance... with various iterations of the above, it stays stuck on frame 0. I fiddled with "Main.npcFrameCount[npc.type] = 6;" in SetStaticDefaults and had rolling frame animation problems when I reduced it (back when I was experimenting with generic anim for Bunny), so that seems to inform the system what to look for (using 174 Ypixel PNG, six frame count, so each frame is 29 pixel frame height). Under the generic code, it seems to see the frame height alright, and frame 0 is appearing complete and in-place as-is, so I think it's seeing frame height with this mechanic.

However, the above is pulled from Vanilla Bunny animation code (under VanillaFindFrame) and boiled down slightly because Vanilla code is a bit overwrought when taken piecemeal (this code used eight lines to establish "npc.spriteDirection = npc.direction;"), so, at this point, I'm just walking through the code trying to work out the logic (thus the comments), and wondering why it won't advance from 0 when in motion. Additional note: when it does move, it bobs up and down a little (I think in time with Bunny hops, so not unusual), but, even though Y position is changing regularly, the code at the bottom for Y velocity frames is also not kicking in.

I'm going to worry about AI issues once I have this animation stuff worked out and understand it a bit better; there's a lot of AI work I'd like to do, if I can just get the basics to basically behave. That addendum gives me a place to start looking, though.

Edit: Actually, there's a lot of mechanical stuff there that either shows me something or confirms something I thought I'd worked out, so thanks!
 
Last edited:
Hello, ive been trying to use Tmod Loader but this keeps popping up

Field not found: 'Terraria.Entity.name'.
at imkSushisNamePack.imkSushisNamePackGlobalItem.SetDefaults(Item item)
at Terraria.ModLoader.ItemLoader.SetDefaults(Item item, Boolean createModItem)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

as soon as i open this shows, how can i fix this?
 
Hello, ive been trying to use Tmod Loader but this keeps popping up

Code:
Field not found: 'Terraria.Entity.name'.
at imkSushisNamePack.imkSushisNamePackGlobalItem.SetDefaults(Item item)
at Terraria.ModLoader.ItemLoader.SetDefaults(Item item, Boolean createModItem)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

as soon as i open this shows, how can i fix this?
What mods do you have enabled?
 
I'm making a magic weapon and these errors keep popping up

c:\Users\Skultar\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Weapons\MagicWeapon.cs.cs(21,4) : error CS0118: 'Terraria.ModLoader.ModItem.item' is a 'property' but is used like a 'type'

c:\Users\Skultar\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Weapons\MagicWeapon.cs.cs(32,21) : error CS1061: 'Terraria.ModLoader.Mod' does not contain a definition for 'projectileType' and no extension method 'projectileType' accepting a first argument of type 'Terraria.ModLoader.Mod' could be found (are you missing a using directive or an assembly reference?)

Here is my code

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

namespace MyMod.Items.Weaopns
{
public class MagicWeapon : ModItem
{
public override void SetDefaults()
{
{
DisplayName.SetDefault("magic");
Tooltip.SetDefault("a magic weapon");
}

item.damage = 1000;
item.magic = true;
item.width = 24;
item height = 28;
item.useTime = 0;
item.useAnimation = 0;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 2;
item.value = 1000;
item.rare = 6;
item.mana = 1;
item.UseSound = SoundID.Item21;
item.autoReuse = true;
item.shoot = mod.projectileType ("MagicProjectile");
item.shootSpeed = 8f;
}
}
}
 
I'm making a magic weapon and these errors keep popping up

c:\Users\Skultar\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Weapons\MagicWeapon.cs.cs(21,4) : error CS0118: 'Terraria.ModLoader.ModItem.item' is a 'property' but is used like a 'type'

c:\Users\Skultar\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Weapons\MagicWeapon.cs.cs(32,21) : error CS1061: 'Terraria.ModLoader.Mod' does not contain a definition for 'projectileType' and no extension method 'projectileType' accepting a first argument of type 'Terraria.ModLoader.Mod' could be found (are you missing a using directive or an assembly reference?)

Here is my code

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

namespace MyMod.Items.Weaopns
{
    public class MagicWeapon : ModItem
    {
        public override void SetDefaults()
        {
            {      
            DisplayName.SetDefault("magic");
            Tooltip.SetDefault("a magic weapon");
            }

            item.damage = 1000;
            item.magic = true;
            item.width = 24;
            item height = 28;
            item.useTime = 0;
            item.useAnimation = 0;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 2;
            item.value = 1000;
            item.rare = 6;
            item.mana = 1;
            item.UseSound = SoundID.Item21;
            item.autoReuse = true;
            item.shoot = mod.projectileType ("MagicProjectile");
            item.shootSpeed = 8f;
        }
    }
}
For one, fix the misspelling on Line 7; It might affect the file.
Secondly, on Line 32, change mod.projectileType to mod.ProjectileType; These things are really case-sensitive.
 
Back
Top Bottom