tModLoader Official tModLoader Help Thread

Help please (bad english is coming!)
someone knows a easy way to make enemys ?like use AI vanilla,because a made a mod with 5 set armors,12 swords,8 guns and 7 accessories, but not enemys :( I want to put my mod to download but I want make enemys frist.If any one knows a easy way to make mobs and bosses,please tell me(if possible make a "exemple code" to me,I like made sprites not codes)
anyway thanks to read!
There is a VERY simple way to create NPCs (Non Playable Characters, in case you didn't know), that doesn't even involve programming AI.
Do note, however, that using this method, you only have access to pre-programmed AI (since you're basically using vanilla AI), which means you can't (for example) make the NPC shoot your own modded projectiles.

Now with that out of the way, let me explain a bit. We can make use of two different variables in a ModNPC class: npc.aiStyle and aiType.
A fast breakdown of the two.
npc.aiStyle: determines what kind of 'style' is used. A good overview can be found here on the wiki. If you follow that link, you can see there are aiStyles called things like 'Slime AI' or 'Fighter AI'. So these are very generic AIs you can assign to your NPC. We can use this to make a slime for example, just by setting npc.aiStyle to 1 in the SetDefaults function of the NPC. That's all there is to it!

aiType: Now this goes a little bit further, so let me get two NPCs out: your average Zombie and an Angry Bones. Now as you might know, there's a difference between these two, but they also have a lot in common. That's because their aiStyle is the same, but their type is different. So the aiStyle takes care of them walking on the ground and jumping, while in this case the type takes care of things like speed and the Angry Bones' little hopping attacks.
So lets say you want your NPC to follow the same pattern as an Angry Bones, you'll have to set npc.aiStyle to 3 (fighter AI) and the aiType to the type of the NPC in question, which is 31 for Angry Bones.

I hope you get the base of it.
 
There is a VERY simple way to create NPCs (Non Playable Characters, in case you didn't know), that doesn't even involve programming AI.
Do note, however, that using this method, you only have access to pre-programmed AI (since you're basically using vanilla AI), which means you can't (for example) make the NPC shoot your own modded projectiles.

Now with that out of the way, let me explain a bit. We can make use of two different variables in a ModNPC class: npc.aiStyle and aiType.
A fast breakdown of the two.
npc.aiStyle: determines what kind of 'style' is used. A good overview can be found here on the wiki. If you follow that link, you can see there are aiStyles called things like 'Slime AI' or 'Fighter AI'. So these are very generic AIs you can assign to your NPC. We can use this to make a slime for example, just by setting npc.aiStyle to 1 in the SetDefaults function of the NPC. That's all there is to it!

aiType: Now this goes a little bit further, so let me get two NPCs out: your average Zombie and an Angry Bones. Now as you might know, there's a difference between these two, but they also have a lot in common. That's because their aiStyle is the same, but their type is different. So the aiStyle takes care of them walking on the ground and jumping, while in this case the type takes care of things like speed and the Angry Bones' little hopping attacks.
So lets say you want your NPC to follow the same pattern as an Angry Bones, you'll have to set npc.aiStyle to 3 (fighter AI) and the aiType to the type of the NPC in question, which is 31 for Angry Bones.

I hope you get the base of it.
Yes you help! I wanna try :) so...thanks again!
 
Is there any way to detect collision between mounts and tiles?
I'm not exactly sure IF I can help you, but that might also be because I'm not sure I understand your question correctly.
I don't think mounts themselves handle collision, since it's all done via the Player.
 
error CS1704: An assembly with the same simple name 'Steamworks.NET, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.

error CS1704: An assembly with the same simple name 'MP3Sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.
this is my error but im not sure if this is the same case as the first one. I used the mod skeleton, and added it to the "C:\Users\Lolz\Documents\My Games\Terraria\ModLoader\Mod Sources" (yes i extracted the skeleton already) but when i build the mod this error shows up. Please help me and thank you in advance :happy:
For the 1st error, rename the steamworks.net.dll file in your Terraria directory to something like steamworks.net123.dll, thatll fix the issue. Dont remove it since it can cause some weird behavior if you do (speaking form experience here)
 
I'm not exactly sure IF I can help you, but that might also be because I'm not sure I understand your question correctly.
I don't think mounts themselves handle collision, since it's all done via the Player.

Thanks for the response. You basically got what I meant, I'm trying to figure out a way to fake mount collision since it doesn't have its own built in. I'm currently trying to figure out how the drill mount does its thing because I think that should work for my purposes. If it doesn't, I figure I'll have to roll my own.
 
help please (bad english coming)
someone knows how make a custom NPC Spawn in events,like blood moon? and how make to put the Spawn only to Hardmode or only to pre hardmode?
I try make a cool mod,but I dont knows much of codes,I like to make sprites :)
Thanks to read!Bye.
 
I want to make a trap tile which can be rotated when hammered, and has 4 frames (1 for each cardinal direction). I copied ExampleBlock as a base, and I'm having a problem where the pink missing-texture color is used for most of the blocks' sides. I do get some of my 4 images to show up in the top row when I have a 2hx4w block of them all together. How do I set it up to use a specific frame based on rotation?

Also, once I get a good, robust, working trap, I think I'll make a pull request to add it to the ExampleMod so others can use it for reference.
 
Could someone please explain why my worm NPC isn't spawning. Even when I sit in the lower cavern layer for 30 minutes.

Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
 {
 int x = spawnInfo.spawnTileX;
 int y = spawnInfo.spawnTileY;
 int tile = (int)Main.tile[x, y].type;
 bool oUnderworld = (y >= (Main.maxTilesY * 0.8f));
 bool oRockLayer = (y <= (Main.maxTilesY * 0.5f));
 return oUnderworld && oRockLayer && Main.evilTiles < 80 && Main.sandTiles < 80 && Main.jungleTiles < 80 && Main.dungeonTiles < 80 && Main.hardMode ? 0.5f : 0f;
 }
 
Could someone please explain why my worm NPC isn't spawning. Even when I sit in the lower cavern layer for 30 minutes.

Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
int x = spawnInfo.spawnTileX;
int y = spawnInfo.spawnTileY;
int tile = (int)Main.tile[x, y].type;
bool oUnderworld = (y >= (Main.maxTilesY * 0.8f));
bool oRockLayer = (y <= (Main.maxTilesY * 0.5f));
return oUnderworld && oRockLayer && Main.evilTiles < 80 && Main.sandTiles < 80 && Main.jungleTiles < 80 && Main.dungeonTiles < 80 && Main.hardMode ? 0.5f : 0f;
}
You have the <= and >= backwards. Also, this probably won't work in multiplayer, since the tile counts are only available to the client. You'll need to use the spawnInfo.player.Zone?? things.
 
You have the <= and >= backwards. Also, this probably won't work in multiplayer, since the tile counts are only available to the client. You'll need to use the spawnInfo.player.Zone?? things.

Oh, dammit. I should've been able to notice that :(

Thank you again, and I'll be trying to get multiplayer working at a later date as well.
 
Code:
using System;

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items.Weapons
{
    public class DiamondSword : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Diamond Sword";
            item.damage = 100;
            item.melee = true;
            item.width = 96;
            item.height = 96;
            item.toolTip = "Cool Modded Sword";
            item.useTime = 6;
            item.useAnimation = 6;    
            item.useStyle = 1;
            item.knockBack = 5;
            item.value = 100;       
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.useTurn = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);     
            recipe.AddIngredient(ItemID.DirtBlock, 1);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override void MeleeEffects(Player player, Rectangle hitbox)
        {
            if (Main.rand.Next(1) == 0)
            {
                int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("DustName"));
            }
        }
    }
}

Couple Questions:

  1. What is the "public override void MeleeEffects" for? I got this from a template.
  2. How do I change the crafting recipe without messing up the entire script?
  3. How do I make my Sword Longer in game?
 
Code:
using System;

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items.Weapons
{
    public class DiamondSword : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Diamond Sword";
            item.damage = 100;
            item.melee = true;
            item.width = 96;
            item.height = 96;
            item.toolTip = "Cool Modded Sword";
            item.useTime = 6;
            item.useAnimation = 6; 
            item.useStyle = 1;
            item.knockBack = 5;
            item.value = 100;    
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.useTurn = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);  
            recipe.AddIngredient(ItemID.DirtBlock, 1);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override void MeleeEffects(Player player, Rectangle hitbox)
        {
            if (Main.rand.Next(1) == 0)
            {
                int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("DustName"));
            }
        }
    }
}

Couple Questions:

  1. What is the "public override void MeleeEffects" for? I got this from a template.
  2. How do I change the crafting recipe without messing up the entire script?
  3. How do I make my Sword Longer in game?
1: https://github.com/bluemagic123/tModLoader/wiki/ModItem => Allows you to give this melee weapon special effects, such as creating light or dust.
2: I do not understand, you have a classic recipe here (easy for change after), you search what?
3:
item.useTime = 6;
item.useAnimation = 6;
change that.
 
1: https://github.com/bluemagic123/tModLoader/wiki/ModItem => Allows you to give this melee weapon special effects, such as creating light or dust.
2: I do not understand, you have a classic recipe here (easy for change after), you search what?
3:
item.useTime = 6;
item.useAnimation = 6;
change that.

1 and 2 I got my answer for, but for 3, I am talking about how to give it a bigger hit box, not making it swing slower.
 
Back
Top Bottom