• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

tModLoader Official tModLoader Help Thread

MattPatrick

Terrarian
So the people from discord told me that this feature is set to default in 0.11.+ so this is pretty much solved xD. Sorry for this dumb question <3

Hello, can anybody help me to properly setup Visual Studio Community 2019 to work with Terraria?

I have everything ready and up, but i don't know how to setup te Edit and Continue feature.

-eac $(TargetPath)

TargetPath needs to be an especific path? or it's meant to be pasted just like that. Also where do i paste that command?

Should i paste here?
1573578649603.png


Or here? (Build Events tab btw)
1573578497950.png


I've tried everything and can't edit in-game values. Please help :<
 
Last edited:

Samiii

Terrarian
Whenever i try to open the Mod Browser in v0.11.5 it crashes with this crash log:

EDIT: All I had to do was click cancel as the mods were loading in and update the Mod Helpers mod which, I now realise, was causing the problem.

1573600394643.png


anyone know a fix or should i just reinstall terraria?
 
Last edited:

Portulo

Terrarian
Hey! I'm newish to modding, and I have no idea what I'm doing. I have two questions. First, I have an accessory (Yes, Kinkyboots) whose effect should be to have a small chance to confuse the enemy upon hit. I'm trying to make it work, as you can see here:

C#:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace Flummox.Items
{
    public class kinkyboots : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Kinkyboots");
            Tooltip.SetDefault("Attacks have a small chance to confuse enemies");
        }
        public override void SetDefaults()
        {
            item.width = 26;
            item.height = 28;
            item.value = 10;
            item.rare = 2;
            item.accessory = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.SpiderFang, 10);
            recipe.AddIngredient(ItemID.Silk, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
            {
                target.AddBuff(BuffID.Confused, 240)
            }
        }
    }
}

I've tried putting the OnHitNPC method outside of the UpdateAccessory method but it just does nothing, and when I put it inside the UpdateAccessory method, it gives me this log:

[23:07:57] [39/INFO] [tML]: Reading properties: Flummox
[23:07:57] [39/INFO] [tML]: Building: Flummox
[23:07:57] [39/INFO] [tML]: Compiling Flummox.XNA.dll
[23:07:57] [39/INFO] [tML]: Compilation finished with 2 errors and 0 warnings
[23:07:57] [39/ERROR] [tML]: C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected
[23:07:57] [39/ERROR] [tML]: C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(42,0) : error CS1022: Type or namespace definition, or end-of-file expected
[23:07:57] [39/ERROR] [tML]: Compiling Flummox.XNA.dll failed with 2 errors and C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected warnings
Terraria.ModLoader.Exceptions.BuildException: Compiling Flummox.XNA.dll failed with 2 errors and C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected warnings
en Terraria.ModLoader.Core.ModCompile.CompileMod(BuildingMod mod, String outputPath, List`1& refMods, Boolean xna)
en Terraria.ModLoader.Core.ModCompile.BuildModForPlatform(BuildingMod mod, List`1& refMods, Boolean xna)
en Terraria.ModLoader.Core.ModCompile.Build(BuildingMod mod)
en Terraria.ModLoader.Core.ModCompile.BuildAll()
en Terraria.ModLoader.UI.UIBuildMod.<>c.<BuildAll>b__6_0(ModCompile mc)
en Terraria.ModLoader.UI.UIBuildMod.BuildMod(Action`1 buildAction, Boolean reload)
[23:08:02] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1920, Height: 1080, Fullscreen: True, Display: \\.\DISPLAY1
[23:08:06] [1/DEBUG] [tML]: Process.Start (UseShellExecute = True): "C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Logs\client.log"

So my first question is how the heck would I make that work.

My second question is a bit more complicated and I have no clue how to implement it: I have a staff, and I want it to fire three projectiles, one after the other, on a straight line. I've been looking up tutorials on the Internet and I've found a way to make it fire three projectiles at the same time, spreading out:

C#:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Flummox.Dusts;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using System.Threading;
 
namespace Flummox.Items
{
    public class antiqueMicrophone : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Antique Microphone");
            Tooltip.SetDefault("Perfect for singing old-timey songs!");
            Item.staff[item.type] = true;
        }
        public override void SetDefaults()
        {      
            item.damage = 34;                        
            item.magic = true;                     //this make the item do magic damage
            item.width = 58;
            item.height = 58;
            item.useTime = 30;
            item.useAnimation = 30;
            item.useStyle = 5;        //this is how the item is holded
            item.noMelee = true;
            item.knockBack = 2;        
            item.value = 1000;
            item.rare = 6;
            item.mana = 5;             //mana use
            item.UseSound = SoundID.Item21;            //this is the sound when you use the item
            item.autoReuse = true;
            item.shoot = mod.ProjectileType ("alastorBlast");  //this make the item shoot your projectile
            item.shootSpeed = 8f;    //projectile speed when shoot
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
              float numberProjectiles = 3; // This defines how many projectiles to shot
              float rotation = MathHelper.ToRadians(45);
              position += Vector2.Normalize(new Vector2(speedX, speedY)) * 45f; //this defines the distance of the projectiles form the player when the projectile spawns
              for (int i = 0; i < numberProjectiles; i++)
              {
                  Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .4f; // This defines the projectile roatation and speed. .4f == projectile speed
                  Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
              }
              return false;
        }
    }
}

I guess it didn't help that the tutorial wasn't much of a tutorial at all, and the guy didn't explain what he was doing at all. I have zero clue what most of the code or the arguments do. If y'all could help me with any of my problems, even a tiny bit, I would very much appreciate it!
 

Shinkun [ModDev]

Official Terrarian
Hey! I'm newish to modding, and I have no idea what I'm doing. I have two questions. First, I have an accessory (Yes, Kinkyboots) whose effect should be to have a small chance to confuse the enemy upon hit. I'm trying to make it work, as you can see here:

C#:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace Flummox.Items
{
    public class kinkyboots : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Kinkyboots");
            Tooltip.SetDefault("Attacks have a small chance to confuse enemies");
        }
        public override void SetDefaults()
        {
            item.width = 26;
            item.height = 28;
            item.value = 10;
            item.rare = 2;
            item.accessory = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.SpiderFang, 10);
            recipe.AddIngredient(ItemID.Silk, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
            {
                target.AddBuff(BuffID.Confused, 240)
            }
        }
    }
}

I've tried putting the OnHitNPC method outside of the UpdateAccessory method but it just does nothing, and when I put it inside the UpdateAccessory method, it gives me this log:

[23:07:57] [39/INFO] [tML]: Reading properties: Flummox
[23:07:57] [39/INFO] [tML]: Building: Flummox
[23:07:57] [39/INFO] [tML]: Compiling Flummox.XNA.dll
[23:07:57] [39/INFO] [tML]: Compilation finished with 2 errors and 0 warnings
[23:07:57] [39/ERROR] [tML]: C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected
[23:07:57] [39/ERROR] [tML]: C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(42,0) : error CS1022: Type or namespace definition, or end-of-file expected
[23:07:57] [39/ERROR] [tML]: Compiling Flummox.XNA.dll failed with 2 errors and C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected warnings
Terraria.ModLoader.Exceptions.BuildException: Compiling Flummox.XNA.dll failed with 2 errors and C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Mod Sources\Flummox\Items\kinkyboots.cs(35,9) : error CS1513: } expected warnings
en Terraria.ModLoader.Core.ModCompile.CompileMod(BuildingMod mod, String outputPath, List`1& refMods, Boolean xna)
en Terraria.ModLoader.Core.ModCompile.BuildModForPlatform(BuildingMod mod, List`1& refMods, Boolean xna)
en Terraria.ModLoader.Core.ModCompile.Build(BuildingMod mod)
en Terraria.ModLoader.Core.ModCompile.BuildAll()
en Terraria.ModLoader.UI.UIBuildMod.<>c.<BuildAll>b__6_0(ModCompile mc)
en Terraria.ModLoader.UI.UIBuildMod.BuildMod(Action`1 buildAction, Boolean reload)
[23:08:02] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1920, Height: 1080, Fullscreen: True, Display: \\.\DISPLAY1
[23:08:06] [1/DEBUG] [tML]: Process.Start (UseShellExecute = True): "C:\Users\Diego Tapia\Documents\My Games\Terraria\ModLoader\Logs\client.log"

So my first question is how the heck would I make that work.

My second question is a bit more complicated and I have no clue how to implement it: I have a staff, and I want it to fire three projectiles, one after the other, on a straight line. I've been looking up tutorials on the Internet and I've found a way to make it fire three projectiles at the same time, spreading out:

C#:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Flummox.Dusts;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using System.Threading;

namespace Flummox.Items
{
    public class antiqueMicrophone : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Antique Microphone");
            Tooltip.SetDefault("Perfect for singing old-timey songs!");
            Item.staff[item.type] = true;
        }
        public override void SetDefaults()
        {     
            item.damage = 34;                       
            item.magic = true;                     //this make the item do magic damage
            item.width = 58;
            item.height = 58;
            item.useTime = 30;
            item.useAnimation = 30;
            item.useStyle = 5;        //this is how the item is holded
            item.noMelee = true;
            item.knockBack = 2;       
            item.value = 1000;
            item.rare = 6;
            item.mana = 5;             //mana use
            item.UseSound = SoundID.Item21;            //this is the sound when you use the item
            item.autoReuse = true;
            item.shoot = mod.ProjectileType ("alastorBlast");  //this make the item shoot your projectile
            item.shootSpeed = 8f;    //projectile speed when shoot
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
              float numberProjectiles = 3; // This defines how many projectiles to shot
              float rotation = MathHelper.ToRadians(45);
              position += Vector2.Normalize(new Vector2(speedX, speedY)) * 45f; //this defines the distance of the projectiles form the player when the projectile spawns
              for (int i = 0; i < numberProjectiles; i++)
              {
                  Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .4f; // This defines the projectile roatation and speed. .4f == projectile speed
                  Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
              }
              return false;
        }
    }
}

I guess it didn't help that the tutorial wasn't much of a tutorial at all, and the guy didn't explain what he was doing at all. I have zero clue what most of the code or the arguments do. If y'all could help me with any of my problems, even a tiny bit, I would very much appreciate it!
First things first, for accessories you should always make them set a player value when equipped, create a new class and name it something like PlayerMod
Here is an example


C#:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ShinkunsAccessories
{
    public class PlayerEditMod : ModPlayer
    {
        public bool KinkyBoots;
        
        public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            if(KinkyBoots) 
            {
                 target.AddBuff(BuffID.Confused, 240);
            }
        }
    }
}
then in your item class make the UpdateEquip event set this boolean to true, so that when the item is equipped the player value will be true, which will execute the code after "if(KinkyBoots)" because that boolean will be true.
So your accessory will look like this:


Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace Flummox.Items
{
    public class kinkyboots : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Kinkyboots");
            Tooltip.SetDefault("Attacks have a small chance to confuse enemies");
        }
        public override void SetDefaults()
        {
            item.width = 26;
            item.height = 28;
            item.value = 10;
            item.rare = 2;
            item.accessory = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.SpiderFang, 10);
            recipe.AddIngredient(ItemID.Silk, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void UpdateEquip(Player player)
        {
            Player.getModPlayer<PlayerEditMod>().KinkyBoots = true;
        }

    }
}
where <PlayerEditMod> is the name of your class that extends ModPlayer

reason your original code doesn't work: you can't override an event inside of a method that overrides another event.

As for the projectile I don't really have much experience with that, but since you're using a for loop to spawn them you could use int i to change the angle slightly so that the first fires a bit down from straight when i = 0, the second projectile fires straight when i = 1 and the last one slightly up when i = 2

You'll have to do some math or clever coding there
hope that helps ^^
 

Shinkun [ModDev]

Official Terrarian
In NPC I'm assuming
Boss1 = eye of cthulu
Boss2 = eater of worlds/brain of cthulu
Boss3 = skeletron

and MechBoss 1 through 3 are those same ones but their mechanical form? 2 always being destroyer of worlds
Is that right?
 

Speeder

Terrarian
There is a mod that can move stuff to chests and whatnot that I wanted to try.

But the mod seemly loads on Windows, but not on Linux, the author said that is because tModLoader do some compatibility shenanigans with mods compiled with old version, and it must be working on Windows and not on Linux...

Can I get more info on that?
 

DoYouEvenCookie

Terrarian
I need a little help.
enemies I create do much more damage with projectiles than with contact, even though I use npc.damage as the damage value for the projectile, and this problem is amplified in expert mode, effectively making projectiles that one shot the player. what gives?
C#:
private void shoot()
{
    int type = mod.ProjectileType("projectile");
    Vector2 velocity = player.Center - npc.Center;
    Vector2 shootFrom = new Vector2(npc.position.X + 24, npc.position.Y + 24);
    Projectile.NewProjectile(shootFrom, velocity, type, npc.damage, 0.0f);
}
 

Death8711

Terrarian
I keep getting this and dont know what to do, can someone help me?

The mod(s) have been automatically been disabled.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Terraria.ModLoader.Core.AssemblyManager.Instantiate(LoadedMod mod)
at Terraria.ModLoader.Core.AssemblyManager.<>c__DisplayClass10_0.<InstantiateMods>b__1(LoadedMod mod)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Terraria.ModLoader.Core.AssemblyManager.InstantiateMods(List`1 modsToLoad, CancellationToken token)
at Terraria.ModLoader.Core.ModOrganizer.LoadMods(CancellationToken token)
at Terraria.ModLoader.ModLoader.Load(CancellationToken token)
 

ConCon

Terrarian
I have been trying to download the latest version of Calamity but it just gets stuck at a full progress bar.

tModLoader version: v0.11.5
Terraria version: 1.3.5.2
OS: Windows 10


Screenshot (1425).png



Edit: I somehow managed to download it again.
 
Last edited:

Azuree15

Terrarian
Hiiii I have this problem... When I've downloaded the lastest modloader I get this Error

System.Threading. SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.
at Terraria.IO.Preferences.Save(Boolean crateFile)
at Terraria.Main.SaveSetting()
at Terraria.Main.OpenSettings()
at Terraria.Main.ClientInitialize()
at Terraria.Main.Initialize()
at Microsoft.Xna.Framework.Game.RunGame(BooleanuseBlockingRun)
at Terraia.Program.LaunchGame_()

I'm not sure as to what that meannnsssssss, BUT i thought it was the same problem as last time, You know the windows defender, So i've allowed it through it.. and i still get the same message.. I could really use some help because the old one was working fine until i saw an update and i updated it and then it give the Error, i thought there was something wrong with the file, So i tried to go back to the 11.4 one and it won't even work anymore. Please help ^^
______________________________

UPDATE: I was able to fix it.. took me a while but i fixed it. so what i did is deleted all the files/folders..
all from
C:\Program Files (x86)\Steam\steamapps\common\Terraria
C:\Users\azure\OneDrive\Documents\My Games\Terraria ( You can save your player and world in a different folder)
Uninstalled from Steam, then reinstalled..
Ohhh and i turned off my Threats & Virus Protection Real time protection.
 
Last edited:
I'm getting an error message: error CS0115 "LemonDemon.SetDefauts" no suitable method to override warnings. Here is my code for y'all.


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


namespace SwordTest.NPCs
{
public class LemonDemon : ModNPC
{
public override void SetDefauts()
{
npc.name = "LemonDemon";
npc.displayname = "Lemon Demon";
npc.width = 42;
npc.width = 31;
npc.damage = 42;
npc.defense = 8;
npc.lifemax = 120;
npc.soundhit = 21;
npc.soundkilled = 24;
npc.value = 60f;
npc.knockBackResist = 0.8;
npc.aiStyle = 14;
main.npcFrameCount[npc.type] = 3;
aiType = NPCID.Demon;
animationType = NPCID.Demon;
}

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return spawnInfo.spawnTileY < Main.maxTilesY - 200 && !Main.dayTime ? 0.5f : 0.5f;
}

public override void FindFrame(int frameHeight)
{
npc.frameCounter -= 0.8f;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)NPCs.frameCounter;
npc.frame.Y = frame * frameHeight;

npc.spriteDirection = npc.direction;
}
public override void NPCLoot()
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Lemon"), 3);
}
}

}
 

SeaGulll

Skeletron
I'm getting an error message: error CS0115 "LemonDemon.SetDefauts" no suitable method to override warnings. Here is my code for y'all.


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


namespace SwordTest.NPCs
{
public class LemonDemon : ModNPC
{
public override void SetDefauts()
{
npc.name = "LemonDemon";
npc.displayname = "Lemon Demon";
npc.width = 42;
npc.width = 31;
npc.damage = 42;
npc.defense = 8;
npc.lifemax = 120;
npc.soundhit = 21;
npc.soundkilled = 24;
npc.value = 60f;
npc.knockBackResist = 0.8;
npc.aiStyle = 14;
main.npcFrameCount[npc.type] = 3;
aiType = NPCID.Demon;
animationType = NPCID.Demon;
}

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return spawnInfo.spawnTileY < Main.maxTilesY - 200 && !Main.dayTime ? 0.5f : 0.5f;
}

public override void FindFrame(int frameHeight)
{
npc.frameCounter -= 0.8f;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)NPCs.frameCounter;
npc.frame.Y = frame * frameHeight;

npc.spriteDirection = npc.direction;
}
public override void NPCLoot()
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Lemon"), 3);
}
}

}
"l" is missing. Change "SetDefauts" to "SetDefaults"
 
I have a problem with my code. I'm getting the error message that "P" doesn't exist. I followed Al0n37 on how to create a boss that shoots projectiles. You can watch it here.

I think I have copied everything and followed everything that he told me to do.

Code:
C++:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModName.Bosses
{
    public class BossName : ModNPC
    {

      


        public override void SetDefaults()
        {
            npc.aiStyle = 5;  //5 is the flying AI
            npc.lifeMax = 500000;   //boss life
            npc.damage = 200;  //boss damage
            npc.defense = 55;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 100;
            npc.height = 100;
            animationType = NPCID.DemonEye;   //this boss will behavior like the DemonEye
            Main.npcFrameCount[npc.type] = 2;    //boss frame/animation
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit5;
            npc.DeathSound = SoundID.NPCDeath7;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;

          
      

          

        }
    
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.GreaterHealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Name"));
        }
        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
        }

        public override void AI()
        {
                npc.ai[1]++;
                if (npc.ai[1] >= 230)
                {
                    float Speed = 20f;
                    Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                    int damage = 80;
                    int type = mod.ProjectileType("Projectile");
                    Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                    float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                    int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation)*Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                    npc.ai[1]=0;
                }
        }

      

    }
}
(Line like 67 or something)
I'm new to coding (I can't code) so it might just be something stupid that I don't recognize. Sorry, if that is the case.
 
Last edited:

Optical Starline

Skeletron Prime
I have a problem with my code. I'm getting the error message that "P" doesn't exist. I followed Al0n37 on how to create a boss that shoots projectiles. You can watch it here.

I think I have copied everything and followed everything that he told me to do.

Code:
C++:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModName.Bosses
{
    public class BossName : ModNPC
    {

     


        public override void SetDefaults()
        {
            npc.aiStyle = 5;  //5 is the flying AI
            npc.lifeMax = 500000;   //boss life
            npc.damage = 200;  //boss damage
            npc.defense = 55;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 100;
            npc.height = 100;
            animationType = NPCID.DemonEye;   //this boss will behavior like the DemonEye
            Main.npcFrameCount[npc.type] = 2;    //boss frame/animation
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit5;
            npc.DeathSound = SoundID.NPCDeath7;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;

         
     

         

        }
   
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.GreaterHealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Name"));
        }
        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
        }

        public override void AI()
        {
                npc.ai[1]++;
                if (npc.ai[1] >= 230)
                {
                    float Speed = 20f;
                    Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                    int damage = 80;
                    int type = mod.ProjectileType("Projectile");
                    Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                    float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                    int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation)*Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                    npc.ai[1]=0;
                }
        }

     

    }
}
(Line like 67 or something)
I'm new to coding (I can't code) so it might just be something stupid that I don't recognize. Sorry, if that is the case.
Al0n37 is ludicrously outdated and should be avoided. Check for better tutorials first off. Secondly, to fix your problem, you need to declare P before you use it. It's being used during the declaration of your rotation float. You need to add Player P = Main.player[npc.target]; in public override void AI(). Then you'll have a vector to call for the rotation float.
 
Thanks! It runs my game now!


It doesn't shoot projectiles though...
Maybe I have to copy the code for the projectiles too.
I thought it was only for the dust animation.
 
Last edited:

g4l4xic

Terrarian
Hello all, I have had a problem for a while that I cant seem to fix myself, even though I've done a lot of research on it. My goal is to generate 4 of my custom ores for my mod when creating/generating a new world, but only the ore Magmalite (it can be seen in my code below) seems to generate when I log into a new world. I've searched a lot of most worlds that I've used to test, and I'm positive that the other ores simply aren't generating. I'm also a relatively new coder, although I understand most of my code. I credit example mod and the makers of it for helping me learn how to make a lot of this stuff, and thank you for any help i get for this problem

What I've tried so far:

  • messing with the code and laying it out in different ways to see if it works, in which those other ways did not work
  • watching and reading various videos and parts of the tmodloader forum that have to do with this, along with reading example mods world gen code section, but I still couldn't figure out the problem with my code that makes it so that only one of the ores generate



C#:
using System.IO;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Generation;

namespace GalandricaMod.Worlds
{
    public class GalandricaWorld : ModWorld
    {
        private const int saveVersion = 0;
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            // Because world generation is like layering several images ontop of each other, we need to do some steps between the original world generation steps.

            // The first step is an Ore. Most vanilla ores are generated in a step called "Shinies", so for maximum compatibility, we will also do this.
            // First, we find out which step "Shinies" is.
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));
            if (ShiniesIndex != -1)
            {
                // Next, we insert our step directly after the original "Shinies" step. 
                // "...OreGen" are methods seen below.
                tasks.Insert(ShiniesIndex + 1, new PassLegacy("Magmalite Ore", MagmaliteOreGen));
                tasks.Insert(ShiniesIndex + 2, new PassLegacy("Liquilate Ore", LiquilateOreGen));
                tasks.Insert(ShiniesIndex + 3, new PassLegacy("Gairswind Ore", GairswindOreGen));
                tasks.Insert(ShiniesIndex + 4, new PassLegacy("Erodate Ore", ErodateOreGen));
            }
        }
        private void MagmaliteOreGen(GenerationProgress progress)
        {
            progress.Message = "Creating the first elemental ores";
            //Put your custom tile block name
            for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)                                                                                                                                      //      |
            {                                                                                                                                                                                                                      //       |
                WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceHigh, (int)WorldGen.worldSurfaceHigh + 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(2, 6), mod.TileType("MagmaliteOreTile"), false, 0f, 0f, false, true);
            }    
        }
        private void LiquilateOreGen(GenerationProgress progress)
        {
            progress.Message = "Creating the first elemental ores";
            for (int l = 0; l < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); l++)                                                                                                                                      //      |
            {                                                                                                                                                                                                                      //       |
                WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceHigh, (int)WorldGen.worldSurfaceHigh + 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(2, 6), mod.TileType("LiquilateOreTile"), false, 0f, 0f, false, true);
            }
        }
        private void GairswindOreGen(GenerationProgress progress)
        {
            progress.Message = "Creating the first elemental ores";
            for (int o = 0; o < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); o++)                                                                                                                                      //      |
            {                                                                                                                                                                                                                      //       |
                WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceHigh, (int)WorldGen.worldSurfaceHigh + 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(2, 6), mod.TileType("GairswindOreTile"), false, 0f, 0f, false, true);
            }
        }
        private void ErodateOreGen(GenerationProgress progress)
        {
            progress.Message = "Creating the first elemental ores";
            for (int p = 0; p < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); p++)                                                                                                                                      //      |
            {                                                                                                                                                                                                                      //       |
                WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceHigh, (int)WorldGen.worldSurfaceHigh + 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(2, 6), mod.TileType("ErodateOreTile"), false, 0f, 0f, false, true);
            }
        }
    }
}
 
Top Bottom