• Switch 1.4: New patch released Jan 18, details are here. Read the full release details here. Report bugs here.

tModLoader Official tModLoader Help Thread

Boxman1100

Terrarian
I would like to add an image to the game at the cursor while the player is holding an item. Like how chairs and tables do when you hold them. But the image will not be the same as the item. Any help would be apreciated.
 

Marc IceBlade

Terrarian
Hello, I am somewaht new to Modding with tModloader and I ran into a problem that I have not found a solution off yet.
Is there a way to make an Item's sprite bigger or am I always limited too the same size? At the moment I am working on an accessory and the sprite is 40 x 56 pixels, I would need it to be higher, but I can't do it. Tried to resize the sprite sheet accordingly or change item.height and width, but nothing work. So, any way to change this?
 

Skallywag777

Terrarian
Hi all, I'm interested in starting to make some mods, and when I used the skeleton mod and added it to the terraria mod source file, the game refused to build and reload it. Here is where the files are (I made two, just in case I screwed up the first one somehow), and this is my error code:

Screen Shot 2018-07-30 at 11.19.39 PM.png
Screen Shot 2018-07-30 at 11.19.50 PM.png


Thank you so much for any help you can give!
 

Marc IceBlade

Terrarian
@Fallen-Angel
I already tried to redo the size in a sprite maker, it always cuts off at the same part. It works on items in the Inventory, but I am trying to make an armor piece and there it just won't work. Even if I space the sprite sheet correctly (making all 20 sprites 70x40), it still cuts off at the same part.
 

jopojelly

Retinazer
tModLoader
Hi all, I'm interested in starting to make some mods, and when I used the skeleton mod and added it to the terraria mod source file, the game refused to build and reload it. Here is where the files are (I made two, just in case I screwed up the first one somehow), and this is my error code:

View attachment 205866 View attachment 205867

Thank you so much for any help you can give!
On mac and linux, you can't build in game unfortunately. Someone wrote up a guide: https://forums.terraria.org/index.p...der-a-modding-api.23726/page-525#post-1001200
 
Hi all, I'm interested in starting to make some mods, and when I used the skeleton mod and added it to the terraria mod source file, the game refused to build and reload it. Here is where the files are (I made two, just in case I screwed up the first one somehow), and this is my error code:

View attachment 205866 View attachment 205867

Thank you so much for any help you can give!
hastebin your code and go into the discord server and go into #help-with-code
 

LobsterClaws

Spazmatism
Hi all, the most recent tmodloader is not working on either of my Macs. I've tried reinstalling it and installing It manually and with the .jar file, but every single time the re-log screen will come up and then fade to back, and the game just freezes indefinitely, and I have to force quit it. anybody have and workaround/solution for this? Any help is greatly appreciated! ;)
 
Hello, I am trying to make a modded sword, and I'm running into two issues.
1. The sword's sprite doesn't show up when swinging.
2. No matter what I set the item.width and item.height values to, the sword always has a ridiculously long range (It can hit things offscreen)

Here is the code: (I've just started so there's not a lot)

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NinjagoMod.Items
{
public class SwordOfFire : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Sword of Fire");
Tooltip.SetDefault("Forged with gold from the Golden Peaks");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 22;
item.useAnimation = 22;
item.useStyle = 1;
item.knockBack = 6;
item.value = 50000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.noUseGraphic = false;

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.GoldBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();

recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.PlatinumBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}




public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
target.AddBuff(BuffID.OnFire, 300);
}





}
}
 

Will-Banksy

Skeletron Prime
Hey i need some help i cant change the hold offset on my moded gun can any one help
Code:
        // Help, my gun isn't being held at the handle! Adjust these 2 numbers until it looks right.
        /*public override Vector2? HoldoutOffset()
        {
            return new Vector2(10, 0);
        }*/
Found this in ExampleGun in ExampleMod. Hope it helps :)
 

Will-Banksy

Skeletron Prime
Hello, I am trying to make a modded sword, and I'm running into two issues.
1. The sword's sprite doesn't show up when swinging.
2. No matter what I set the item.width and item.height values to, the sword always has a ridiculously long range (It can hit things offscreen)

Here is the code: (I've just started so there's not a lot)

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NinjagoMod.Items
{
public class SwordOfFire : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Sword of Fire");
Tooltip.SetDefault("Forged with gold from the Golden Peaks");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 22;
item.useAnimation = 22;
item.useStyle = 1;
item.knockBack = 6;
item.value = 50000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.noUseGraphic = false;

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.GoldBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();

recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.PlatinumBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}




public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
target.AddBuff(BuffID.OnFire, 300);
}





}
}
That is odd, as I copied the code and had no problems. As for the range, check the size of your sprite, as this code works fine.
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NinjagoMod.Items
{
    public class SwordOfFire : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Sword of Fire");
            Tooltip.SetDefault("Forged with gold from the Golden Peaks");
        }
       
        public override void SetDefaults()
        {
            item.damage = 25;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.useTime = 22;
            item.useAnimation = 22;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = 50000;
            item.rare = 2;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.noUseGraphic = false;
        }
   
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.GoldBar, 15);
            recipe.AddIngredient(ItemID.Diamond, 1);
            recipe.AddIngredient(ItemID.Ruby, 5);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();

            recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.PlatinumBar, 15);
            recipe.AddIngredient(ItemID.Diamond, 1);
            recipe.AddIngredient(ItemID.Ruby, 5);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 300);
        }
    }
}
 

reedeklar

Terrarian
Code:
        // Help, my gun isn't being held at the handle! Adjust these 2 numbers until it looks right.
        /*public override Vector2? HoldoutOffset()
        {
            return new Vector2(10, 0);
        }*/
Found this in ExampleGun in ExampleMod. Hope it helps :)
Thanks
 

DatScoot シ

Terrarian
Hey uhh this might sound stupid... but I'm making my own NPC for Terraria and I wanted to know how I make my NPC attack at day if it's AI type is 3, so the fighter AI. This AI makes it so the NPC only attacks you at night, but I want it to attack at day. I've searched all over the internet and I couldn't find an answer on how to do this. Here's my code (still work in progress don't mind the stupid values & properties):

Code:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework;
using System.IO;
using ReLogic;
using System;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework.Graphics;
using Terraria.Localization;


namespace PurxyMod.NPCs
{
    public class GoblinBush : ModNPC
    {

        const int COOLDOWN = 110;
        int remaining_cooldown = 0;
        Random rnd = new Random();

        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Bush Goblin");
        }


        public override void SetDefaults()
        {
            npc.width = 18;
            npc.height = 40;
            npc.damage = 12;
            npc.defense = 5;
            npc.lifeMax = 500;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 100f;
            npc.knockBackResist = 0.75f;
            npc.aiStyle = 3;
            Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Zombie];
            aiType = 3; // aiType = 3;
            animationType = NPCID.Zombie;
        }

        public override void PostAI()
        {
            {
                Vector2 target = Main.player[npc.target].position;
                float dist = Vector2.Distance(npc.position, target);
                {
                    if (dist < 500f)
                    {

                        if (remaining_cooldown == 0)
                        {
                            Vector2 speed = target - npc.position;
                            speed.Normalize();
                            speed *= 11f;
                            int proj = Projectile.NewProjectile(npc.position.X, npc.position.Y, speed.X, speed.Y, mod.ProjectileType("SeedProjectile"), npc.damage, 1f);
                            remaining_cooldown = COOLDOWN;
                        }

                        if (remaining_cooldown == COOLDOWN)
                        {
                            Main.PlaySound(SoundID.Item63, Convert.ToInt32(npc.position.X), Convert.ToInt32(npc.position.Y));
                        }
                        remaining_cooldown -= 1;  
                    }
                }             
            }

            if (Main.rand.Next(1000) == 0)
            {
                Main.PlaySound(SoundID.ZombieMoan, Convert.ToInt32(npc.position.X), Convert.ToInt32(npc.position.Y));
            }
        }

        public override void NPCLoot()
        {
            if (Main.rand.Next(11) == 0)
            {
                Item.NewItem(npc.getRect(), ItemID.Blowpipe);
            }
            Item.NewItem(npc.getRect(), ItemID.TatteredCloth, Main.rand.Next(4));
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            return 0.5f;
        }
    }
}
 
Hi I'm making multiple enemies that are having trouble spawning in correctly. For example a meteor enemy, a desert enemy and an underworld enemy are spawning almost everywhere. Can someone help please? here is the code for the enemies:

Meteorite Enemy:
Code:
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;


namespace SlimeMod.NPCs.Enemies
{
    public class MeteorSlime : ModNPC
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Meteor Slime");
        }
        public override void SetDefaults()
        {
            npc.width = 32;
            npc.height = 24;
            npc.damage = 38;
            npc.defense = 4;
            npc.lifeMax = 45;
            npc.HitSound = SoundID.NPCHit3;
            npc.DeathSound = SoundID.NPCDeath3;
            npc.value = 60f;
            npc.knockBackResist = 1f;
            npc.aiStyle = 1;
            Main.npcFrameCount[npc.type] = 2;
            animationType = 1;
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            return !Main.dayTime && spawnInfo.player.ZoneMeteor ? 1f : 0.5f;
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.9F;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;
        }
            public override void OnHitPlayer(Player player, int damage, bool crit)
        {
            if (Main.rand.Next(2) == 0) // the chance
            {
                player.AddBuff(BuffID.OnFire, 480, true);
            }
        }
        public override void NPCLoot()
        {
       
            Item.NewItem(npc.getRect(), ItemID.Gel, 1 + Main.rand.Next(3)); //1, 2, or 3
            if (Main.rand.Next(3) < 1)
                Item.NewItem(npc.getRect(), ItemID.Meteorite, 1);
   
        }
    }
}

Desert Enemy:
Code:
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;


namespace SlimeMod.NPCs.Enemies
{
    public class CactusSlime : ModNPC
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Cactus Slime");
        }
        public override void SetDefaults()
        {
            npc.width = 40;
            npc.height = 40;
            npc.damage = 16;
            npc.defense = 4;
            npc.lifeMax = 45;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 60f;
            npc.knockBackResist = 1f;
            npc.aiStyle = 1;
            Main.npcFrameCount[npc.type] = 2;
            animationType = 1;
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            return Main.dayTime && spawnInfo.player.ZoneDesert ? 1f : 0.5f;
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.9F;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

        }
             public override void OnHitPlayer(Player player, int damage, bool crit)
        {
            if (Main.rand.Next(2) == 0) // the chance
            {
                player.AddBuff(BuffID.Poisoned, 300, true);
            }
        }
        public override void NPCLoot()
        {
       
            Item.NewItem(npc.getRect(), ItemID.Gel, 1 + Main.rand.Next(3)); //1, 2, or 3
            if (Main.rand.Next(10000) < 1)
                Item.NewItem(npc.getRect(), ItemID.SlimeStaff, 1);
            Item.NewItem(npc.getRect(), ItemID.Cactus, 4 + Main.rand.Next(7));
       
        }
    }
}

Underworld Enemy:
Code:
usingTerraria;
usingMicrosoft.Xna.Framework;
usingTerraria.ID;
usingTerraria.ModLoader;


namespaceSlimeMod.NPCs.Enemies
{
publicclassSpikedLavaSlime : ModNPC
{
publicoverridevoidSetStaticDefaults()
 {
DisplayName.SetDefault("Spiked Lava Slime");
 }
publicoverridevoidSetDefaults()
{
npc.width=40;
npc.height=40;
npc.damage=16;
npc.defense=4;
npc.lifeMax=45;
npc.HitSound=SoundID.NPCHit1;
npc.DeathSound=SoundID.NPCDeath1;
npc.value=60f;
npc.knockBackResist=1f;
npc.aiStyle=1;
Main.npcFrameCount[npc.type] =2;
animationType=1;
}

publicoverridefloatSpawnChance(NPCSpawnInfo spawnInfo)
{
returnspawnInfo.player.ZoneUnderworldHeight0.5f : 0.3f;
}
publicoverridevoidFindFrame(int frameHeight)
{
npc.frameCounter-=0.9F;
npc.frameCounter%=Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y=frame * frameHeight;

}
publicoverridevoidOnHitPlayer(Player player, int damage, bool crit)
{
if (Main.rand.Next(2) ==0) // the chance
{
player.AddBuff(BuffID.Poisoned, 300, true);
}
}
}
}
 

MilkDud

Terrarian
Can someone help?
I keep getting this error:
c:\Users\russell\Documents\My Games\Terraria\ModLoader\Mod Sources\SwordsMod\NPCs\Bosses\BossName.cs(16,7) : error CS1014: A get or set accessor expected
I dont know how to fix.
My code is this:

using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace SwordsMod.NPCs.Bosses
{
public class BossName : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault ("The Mindless Glutton");
}
public override void SetDefaults()
{
npc.aiStyle = 5; //5 is the flying AI
npc.lifeMax = 333000; //boss life
npc.damage = 299; //boss damage
npc.defense = 100; //boss defense
npc.knockBackResist = 0f;
npc.width = 100;
npc.height = 100;
animationType = NPCID.KingSlime;
Main.npcFrameCount[npc.type] = 2; //boss frame/animation
npc.value = Item.buyPrice(0, 40, 75, 45);
npc.npcSlots = 1f;
npc.boss = true;
npc.lavaImmune = true;
npc.noGravity = false;
npc.noTileCollide = true;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath2;
npc.buffImmune[24] = true;
music = MusicID.Boss2;
npc.netAlways = true;
}
public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "SwordsMod/NPCs/Bosses/BossName_Head_Boss"; //the boss head texture
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.LesserHealingPotion; //boss drops
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YourSword"));
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
}
}
 

The_Nugget_Hole

Terrarian
Yah Same Here, But does anyone have the Martian Saucer AI code I need it for my project I'm doing :(. I'm trying to make a flying Monster Boss and I want it to behave like a Martian Saucer, I NEED HELP NEED MARTIAN SAUCER AI CODE :(
 
Last edited:
Top Bottom