tModLoader Official tModLoader Help Thread

So hey, I've started work on a mod and I'm struggling to cause an effect on enemies when you hit them, like the magma stone. It is a vanilla buff that I'm trying to inflict, just not one that any terraria items use. Any help would be appreciated.
 
Hello, I am trying to create an extraordinary mod but have some struggles only with the NPC. Tried to create myself, tried many other codes as well as example mode. Still NPCS dont appear in my map:(

Simple example which not works in the game:

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

namespace TestMod.Mobs
{
public class Orb : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Orb");
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Zombie];
}

public override void SetDefaults()
{
npc.width = 18;
npc.height = 40;
npc.damage = 14;
npc.defense = 6;
npc.lifeMax = 200;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath2;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 3;
aiType = NPCID.Zombie;
animationType = NPCID.Zombie;
}

public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
return SpawnCondition.OverworldNightMonster.Chance * 0.5f;
}

public override void HitEffect(int hitDirection, double damage)
{
for (int i = 0; i < 10; i++)
{
int dustType = Main.rand.Next(139, 143);
int dustIndex = Dust.NewDust(npc.position, npc.width, npc.height, dustType);
Dust dust = Main.dust[dustIndex];
dust.velocity.X = dust.velocity.X + Main.rand.Next(-50, 51) * 0.01f;
dust.velocity.Y = dust.velocity.Y + Main.rand.Next(-50, 51) * 0.01f;
dust.scale *= 1f + Main.rand.Next(-30, 31) * 0.01f;
}
}
}
}
 
Heya, I'm having a problem with the line of code that messes with the height of the player's hitbox. When I decrease the height so that the player can fit through 1 or 2 blocks, the player's weapon and items end up below the ground when I use them. I use this line of code:
thisPlayer.position = thisPlayer.Bottom;
thisPlayer.height = 13
thisPlayer.Bottom = thisPlayer.position;
Is there any way to code it so that it I change the vertical offset of all weapons the player uses?
 
I have 3 questions I need answered.

Question 1:
I was trying to make something similar to the "Undead" debuff from the example mod in my own mod, but it only works on slow, drawn-out healing, not instantaneous healing. Can someone help me out with that?

Code:
Code:
public override void UpdateBadLifeRegen()
        {
            if (eyezor)
            {
                if (player.lifeRegen > 2)
                {
                    if (vheal = true)
                    {
                    player.lifeRegen = -2 * player.lifeRegen;
                    }
                }
                player.lifeRegenTime = 0;
            }
            if (mystic)
            {
                if (player.lifeRegen > 0)
                {
                    player.lifeRegen = 2 * player.lifeRegen;
                }
                player.lifeRegenTime = 0;
            }
        }

Question 2:
Is there a way to make it look like the player has no eyes? Essentially, a way to make them look like this: tplayer_h13.png
This is because an armor set I'm making requires the player's eyes to be hidden in order to look right.

Question 3: I was trying to change the player's hurt and death sounds when they had certain buffs, but it didn't work.
Code:
        public virtual bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore)
        {
            if (corrupted)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath1, player.Center);
            }
            if (eyezor)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath1, player.Center);
            }
            if (mystic)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath49, player.Center);
            }
            if (psychosis)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath11, player.Center);
            }
            return true;
        }
 
I have 3 questions I need answered.

Question 1:
I was trying to make something similar to the "Undead" debuff from the example mod in my own mod, but it only works on slow, drawn-out healing, not instantaneous healing. Can someone help me out with that?

Code:
Code:
public override void UpdateBadLifeRegen()
        {
            if (eyezor)
            {
                if (player.lifeRegen > 2)
                {
                    if (vheal = true)
                    {
                    player.lifeRegen = -2 * player.lifeRegen;
                    }
                }
                player.lifeRegenTime = 0;
            }
            if (mystic)
            {
                if (player.lifeRegen > 0)
                {
                    player.lifeRegen = 2 * player.lifeRegen;
                }
                player.lifeRegenTime = 0;
            }
        }

Question 2:
Is there a way to make it look like the player has no eyes? Essentially, a way to make them look like this: View attachment 196817
This is because an armor set I'm making requires the player's eyes to be hidden in order to look right.

Question 3: I was trying to change the player's hurt and death sounds when they had certain buffs, but it didn't work.
Code:
        public virtual bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore)
        {
            if (corrupted)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath1, player.Center);
            }
            if (eyezor)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath1, player.Center);
            }
            if (mystic)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath49, player.Center);
            }
            if (psychosis)
            {
                playSound = false;
                Main.PlaySound(SoundID.NPCDeath11, player.Center);
            }
            return true;
        }
1. See Potion.cs in ExampleMod,
2. no idea.
3. you wrote virtual instead of override.
[doublepost=1522353557,1522353500][/doublepost]Another reminder to everyone....no one with any skills ever replies in this thread. Please come to the discord server to get help. Otherwise, have fun not getting answers. -> discord.me/tModLoader
 
whenever i play multiplayer (aka host &play) it gets stuck at loading world information. what i have to do is deposit all my modded and vanilla items, and either duplicate my character or make an entirely new one. the mods i have installed are...

Fargo's mutant mod: summons and souls
Veinminer
Recipe Browser
Calamity mod
Boss Checklist
AlchemistNPC
Wheres My Items
Loot Bags
Instant respawn
yet another boss health bar

all mods are up-to-date and it's getting tedious repeating this process. even my brother gets this problem when he hosts. we also now get the problem of it getting stuck on found server.
 
Last edited:
How do I make my sword (In my inventory (And maybe when I use it)) animated? I got the spritesheet with a 2-pixel space on the top and bottom of each sprite. Each sprite is 66x68 and there is 12 sprites, with each sprite using up 10 frames. I tried using ExampleMod's FaceItem to do this, but it comes up with an error:
Code:
c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Items\DivineRage.cs(17,46) : error CS0246: The type or namespace name 'DrawAnimationVertical' could not be found (are you missing a using directive or an assembly reference?)
Code:
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items
{
    public class Face : ModItem
    {
        public override void SetStaticDefaults()
        {
            // See here for help on using Tags: http://terraria.wiki.gg/Chat#Tags
            Tooltip.SetDefault("How are you feeling today?"
                + string.Format("\n[c/FF0000:Colors ][c/00FF00:are ][c/0000FF:fun ]and so are items: [i:{0}][i:{1}][i/s123:{2}]", item.type, mod.ItemType<CarKey>(), ItemID.Ectoplasm));

            Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(30, 4));
            ItemID.Sets.ItemNoGravity[item.type] = true;
        }

        public override void SetDefaults()
        {
            item.width = 20;
            item.height = 20;
            item.value = 100;
            item.rare = 1;
        }

        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }

        public override void ModifyTooltips(List<TooltipLine> tooltips)
        {
            TooltipLine line = new TooltipLine(mod, "Face", "I'm feeling just fine!");
            line.overrideColor = new Color(100, 100, 255);
            tooltips.Add(line);
            foreach (TooltipLine line2 in tooltips)
            {
                if (line2.mod == "Terraria" && line2.Name == "ItemName")
                {
                    line2.overrideColor = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB);
                }
            }
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "ExampleItem");
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace JoshuasMod.Items
{
    public class DivineRage : ModItem
    {
        public override void SetStaticDefaults()
        {
           
DisplayName.SetDefault("Divine Rage");
            Tooltip.SetDefault("Rains down a shower of meteors!");
            Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(12, 10));
            //Have no idea what the numbers in "new DrawAnimationVertical(#, #)" mean. :(
            ItemID.Sets.ItemNoGravity[item.type] = true;
        }
      
        public override void SetDefaults()
        {
            item.damage = 200;
            item.width = 54;
            item.height = 56;
            item.scale = 0.90f;
            item.melee = true;
            item.useTime = 14;  
            item.useAnimation = 14;  
            item.useStyle = 1;
            item.noMelee = false;
            item.knockBack = 10;
            item.value = Item.buyPrice(1, 20, 0, 0);
            item.rare = 11;
            item.UseSound = SoundID.Item71;
            item.autoReuse = true;
            item.shoot = 0;
            item.useTurn = true;
        }
    }
}
How do I fix this?
 
Last edited:
Hello,
Sorry to be a bother but i seem to be having an issue with my tmoder since updating to the 10.3 version (recent update).
Some backstory: On the previous version of Tmod I had patched it using Terraria Patcher and it worked perfectly and everything.
Today's issue: I seem to be having two problems:
1. After updating tmod to play on multiplayer (Join via Steam) with a friend I would connect and log into their world for a couple minutes then I would get kicked out with a Lost Connection error. We've checked and double checked to make sure we had the same mods activated, i checked my router service, etc. and everything seems to be fine, yet i still lose connection from a 1min-5mins interval.
2. In relations to Terraria Patcher, I've been wanting to patch the updated tmod again but when I try to apply the plugins and open the game via steam in doesn't load. There's no crash error and when i checked Task Manager it says that Terraria is running but the game itself never pops up. This is after waiting 10-15 minutes before ending the Task. I've un/reinstalled TPatcher but it doesnt work. The only way to fix the issue is re-updating tmod again with the files. But then again, I'm still having the "Lost Connection" issue. Any help would be much appreciated thank you!

Side Note: Steam themselves updated, but i don't think that would have caused such an issue with TMod. It's updated before in the previous TMod version and all was fine in connections, Patcher and Mods.
 
I have EVERY SINGLE BIT of my mod done except for the Expert mode treasure bags. I've made it so that they drop in expert and don't drop in normal, but in expert it drops both the contents of the bag AND the bag. So for example, It drops a minion staff, then you open the bag and it contains a minion staff. If you would like code examples, please tell me so I can give them.
 
if you need help with projectiles, I made a guide https://forums.terraria.org/index.p...weapon-stuff-for-tmodloader-mod-making.68337/
I have EVERY SINGLE BIT of my mod done except for the Expert mode treasure bags. I've made it so that they drop in expert and don't drop in normal, but in expert it drops both the contents of the bag AND the bag. So for example, It drops a minion staff, then you open the bag and it contains a minion staff. If you would like code examples, please tell me so I can give them.
I assume your code looks like this:
Code:
public override void NPCLoot()
        {
            if (Main.expert) //idk the bool for expert but I think this is it
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TreasureBag"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.BossDrop);
        }
so use an if/else statement.
Code:
public override void NPCLoot()
        {
            if (Main.expert) //idk the bool for expert but I think this is it
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TreasureBag"));
            }
            else{
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.BossDrop);
            }
        }
 
every modded item from my :redmunch:ing world is gone. my town had a power outage last night due to storms, so i exited my world and unplugged my pc. now every modded item, block, and npc not in my inventory is gone. what do i do?
 
Got a problem. :(
So, when I fire my projectile, it doesn't change through its frames, it just stays on the first frame. Why's that?
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace JoshuasMod.Projectiles
{
    public class CelicaProj : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            Main.projFrames[projectile.type] = 32;
        }
       
        public override void SetDefaults()
        {
            projectile.damage = 100;
            projectile.scale = 1f;
            projectile.friendly = true;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.timeLeft = 320;
            projectile.width = 66;
            projectile.height = 66;
            projectile.penetrate = -1;
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;
        }

        public override void AI()
        {
            //Making sure the projectile faces the correct way.
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.75f;
           
            //Loop through the 32 animation frames, spending 10 ticks on each.
            if (++projectile.frameCounter >= 32)
            {
                projectile.frameCounter = 0;
                if (++projectile.frame >= 10)
                {
                    projectile.frame = 0;
                }
            }
           
            //This is the dust used, it is the size of the projectile.
            projectile.velocity.Y += projectile.ai[0];
            for (int d = 0; d < 1; d++)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 15, 0f, 0f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.05f);
            }
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 5 * 60);
            target.AddBuff(BuffID.Frostburn, 5 * 60);
            target.AddBuff(BuffID.CursedInferno, 5 * 60);
            target.AddBuff(BuffID.ShadowFlame, 5 * 60);
            target.immune[projectile.owner] = 1;
        }
    }
}
Code:
            item.damage = 180;
            item.width = 66;
            item.height = 66;
            item.scale = 0.85f;
            item.melee = true;
            item.useTime = 18;   
            item.useAnimation = 18;   
            item.useStyle = 1;
            item.noMelee = false;
            item.knockBack = 8;
            item.value = Item.buyPrice(1, 20, 0, 0);
            item.rare = 11;
            item.UseSound = SoundID.Item71;
            item.autoReuse = true;
            item.shoot = mod.ProjectileType("CelicaProj");
            item.shootSpeed = 10f;
            item.useTurn = true;
I didn't have this problem on another projectile with multiple frames. Is it because there's simply too many frames on this projectile?
 
Got a problem. :(
So, when I fire my projectile, it doesn't change through its frames, it just stays on the first frame. Why's that?
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace JoshuasMod.Projectiles
{
    public class CelicaProj : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            Main.projFrames[projectile.type] = 32;
        }
      
        public override void SetDefaults()
        {
            projectile.damage = 100;
            projectile.scale = 1f;
            projectile.friendly = true;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.timeLeft = 320;
            projectile.width = 66;
            projectile.height = 66;
            projectile.penetrate = -1;
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;
        }

        public override void AI()
        {
            //Making sure the projectile faces the correct way.
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.75f;
          
            //Loop through the 32 animation frames, spending 10 ticks on each.
            if (++projectile.frameCounter >= 32)
            {
                projectile.frameCounter = 0;
                if (++projectile.frame >= 10)
                {
                    projectile.frame = 0;
                }
            }
          
            //This is the dust used, it is the size of the projectile.
            projectile.velocity.Y += projectile.ai[0];
            for (int d = 0; d < 1; d++)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 15, 0f, 0f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.05f);
            }
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 5 * 60);
            target.AddBuff(BuffID.Frostburn, 5 * 60);
            target.AddBuff(BuffID.CursedInferno, 5 * 60);
            target.AddBuff(BuffID.ShadowFlame, 5 * 60);
            target.immune[projectile.owner] = 1;
        }
    }
}
Code:
            item.damage = 180;
            item.width = 66;
            item.height = 66;
            item.scale = 0.85f;
            item.melee = true;
            item.useTime = 18;  
            item.useAnimation = 18;  
            item.useStyle = 1;
            item.noMelee = false;
            item.knockBack = 8;
            item.value = Item.buyPrice(1, 20, 0, 0);
            item.rare = 11;
            item.UseSound = SoundID.Item71;
            item.autoReuse = true;
            item.shoot = mod.ProjectileType("CelicaProj");
            item.shootSpeed = 10f;
            item.useTurn = true;
I didn't have this problem on another projectile with multiple frames. Is it because there's simply too many frames on this projectile?
It's probably because you aren't increasing projectile.frameCounter anywhere meaningful. Put projectile.frameCounter++; before your if statement and remove ++ from inside your if statements.
 
It's probably because you aren't increasing projectile.frameCounter anywhere meaningful.
Removed the "++"'s from the if statements and placed a "projectile.frameCounter++;" before he if statements (Don't know if it's in the right place though, since 'before' could mean anywhere before said if statements). Still stuck on its first frame.
Code:
public override void AI()
        {
            //Making sure the projectile faces the correct way.
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.75f;
        
            //Loop through the 32 animation frames, spending 10 ticks on each.
            projectile.frameCounter++; //"projectile.frameCounter++;" statement must go before the "if" statement. That's before the "if" statement, right? O_o
            if (projectile.frameCounter >= 32)
            {
                projectile.frameCounter = 0;
                if (projectile.frame >= 10)
                {
                    projectile.frame = 0;
                }
            }
        
            //This is the dust used, it is the size of the projectile.
            projectile.velocity.Y += projectile.ai[0];
            for (int d = 0; d < 1; d++)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 15, 0f, 0f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.05f);
            }
        }
Also, what did you mean by "increasing projectile.frameCounter anywhere meaningful"?

P.S Happy birthday :)
 
Removed the "++"'s from the if statements and placed a "projectile.frameCounter++;" before he if statements (Don't know if it's in the right place though, since 'before' could mean anywhere before said if statements). Still stuck on its first frame.
Code:
public override void AI()
        {
            //Making sure the projectile faces the correct way.
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.75f;
       
            //Loop through the 32 animation frames, spending 10 ticks on each.
            projectile.frameCounter++; //"projectile.frameCounter++;" statement must go before the "if" statement. That's before the "if" statement, right? O_o
            if (projectile.frameCounter >= 32)
            {
                projectile.frameCounter = 0;
                if (projectile.frame >= 10)
                {
                    projectile.frame = 0;
                }
            }
       
            //This is the dust used, it is the size of the projectile.
            projectile.velocity.Y += projectile.ai[0];
            for (int d = 0; d < 1; d++)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 15, 0f, 0f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.05f);
            }
        }
Also, what did you mean by "increasing projectile.frameCounter anywhere meaningful"?

P.S Happy birthday :)
Thanks. :happy:
By 'anywhere meaningful', I meant anywhere where you can actually modify the value of a number. You can't change a number in the condition of an if statement.
I had another look at your code, and realised I'd missed a mistake. You are resetting projectile frame to 0 when it exceeds it's max value, but you aren't actually increasing the frame number anywhere. Your code should look like this:
Code:
projectile.frameCounter = 0;
projectile.frame++; //<--new line of code here
if (projectile.frame >= 10)
{
    projectile.frame = 0;
}
 
Back
Top Bottom