tModLoader Official tModLoader Help Thread

Then you'll probably want to override this method to check whether or not the head is dead/inactive:
Code:
public override bool CheckActive()
{
    if(Main.npc[npc.ai[3]].active) return false;
    return true;
}
That should work. No other way to know than to test it out!
Well, there is an error:
c:\Users\Hallam\Documents\My Games\Terraria\ModLoader\Mod Sources\ModOfRandomness\NPCs\VlitchWormTail.cs(96,26) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)

This is the new code:
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModOfRandomness.NPCs
{   
    public class VlitchWormTail : ModNPC
    {
        public override void SetDefaults()
        {
            npc.displayName = "Vlitch Gigipede";
            npc.name = "Vlitch Gigipede";
            npc.width = 64;     //this is where you put the npc sprite width.     important
            npc.height = 104;      //this is where you put the npc sprite height.   important
            npc.damage = 180;
            npc.defense = 250;
            npc.lifeMax = 1;
            npc.knockBackResist = 0.0f;
            npc.behindTiles = true;
            npc.noTileCollide = true;
            npc.netAlways = true;
            npc.noGravity = true;
            npc.dontCountMe = true;
            npc.HitSound = SoundID.NPCHit4;
        }

        public override void AI()
        {
            if (npc.ai[0]++ >= 200)
            {
                // Spawn NPC!
                NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("CorruptedWormHead"));

                npc.ai[0] = 0;
            }
            {
                if (npc.ai[3] > 0)
                    npc.realLife = (int)npc.ai[3];
                if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
                    npc.TargetClosest(true);
                if (Main.player[npc.target].dead && npc.timeLeft > 300)
                    npc.timeLeft = 300;
                if (Main.netMode != 1)
                {
                    if (!Main.npc[(int)npc.ai[1]].active)
                    {
                        npc.life = 0;
                        npc.HitEffect(0, 10.0);
                        npc.active = false;
                        NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
                    }
                }
                {
                    if (Main.rand.Next(1) == 0)
                    {
                        int dust = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, mod.DustType("Flame"));
                    }
                }
                if (npc.ai[1] < (double)Main.npc.Length)
                {
                    // We're getting the center of this NPC.
                    Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                    // Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
                    float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
                    float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
                    // We then use Atan2 to get a correct rotation towards that parent NPC.
                    npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
                    // We also get the length of the direction vector.
                    float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
                    // We calculate a new, correct distance.
                    float dist = (length - (float)npc.width) / length;
                    float posX = dirX * dist;
                    float posY = dirY * dist;

                    // Reset the velocity of this NPC, because we don't want it to move on its own
                    npc.velocity = Vector2.Zero;
                    // And set this NPCs position accordingly to that of this NPCs parent NPC.
                    npc.position.X = npc.position.X + posX;
                    npc.position.Y = npc.position.Y + posY;
                }
            }
        }

        public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color drawColor)
        {
            Texture2D texture = Main.npcTexture[npc.type];
            Vector2 origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f);
            Main.spriteBatch.Draw(texture, npc.Center - Main.screenPosition, new Rectangle?(), drawColor, npc.rotation, origin, npc.scale, SpriteEffects.None, 0);
            return false;
        }
        public override bool CheckActive()
        {
            if (Main.npc[npc.ai[3]].active) return false;
            return true;
        }
        public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
        {

            return false;      //this make that the npc does not have a health bar
        }
    }
}
 
Well, there is an error:
c:\Users\Hallam\Documents\My Games\Terraria\ModLoader\Mod Sources\ModOfRandomness\NPCs\VlitchWormTail.cs(96,26) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)

This is the new code:
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModOfRandomness.NPCs
{  
    public class VlitchWormTail : ModNPC
    {
        public override void SetDefaults()
        {
            npc.displayName = "Vlitch Gigipede";
            npc.name = "Vlitch Gigipede";
            npc.width = 64;     //this is where you put the npc sprite width.     important
            npc.height = 104;      //this is where you put the npc sprite height.   important
            npc.damage = 180;
            npc.defense = 250;
            npc.lifeMax = 1;
            npc.knockBackResist = 0.0f;
            npc.behindTiles = true;
            npc.noTileCollide = true;
            npc.netAlways = true;
            npc.noGravity = true;
            npc.dontCountMe = true;
            npc.HitSound = SoundID.NPCHit4;
        }

        public override void AI()
        {
            if (npc.ai[0]++ >= 200)
            {
                // Spawn NPC!
                NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("CorruptedWormHead"));

                npc.ai[0] = 0;
            }
            {
                if (npc.ai[3] > 0)
                    npc.realLife = (int)npc.ai[3];
                if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
                    npc.TargetClosest(true);
                if (Main.player[npc.target].dead && npc.timeLeft > 300)
                    npc.timeLeft = 300;
                if (Main.netMode != 1)
                {
                    if (!Main.npc[(int)npc.ai[1]].active)
                    {
                        npc.life = 0;
                        npc.HitEffect(0, 10.0);
                        npc.active = false;
                        NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
                    }
                }
                {
                    if (Main.rand.Next(1) == 0)
                    {
                        int dust = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, mod.DustType("Flame"));
                    }
                }
                if (npc.ai[1] < (double)Main.npc.Length)
                {
                    // We're getting the center of this NPC.
                    Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                    // Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
                    float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
                    float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
                    // We then use Atan2 to get a correct rotation towards that parent NPC.
                    npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
                    // We also get the length of the direction vector.
                    float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
                    // We calculate a new, correct distance.
                    float dist = (length - (float)npc.width) / length;
                    float posX = dirX * dist;
                    float posY = dirY * dist;

                    // Reset the velocity of this NPC, because we don't want it to move on its own
                    npc.velocity = Vector2.Zero;
                    // And set this NPCs position accordingly to that of this NPCs parent NPC.
                    npc.position.X = npc.position.X + posX;
                    npc.position.Y = npc.position.Y + posY;
                }
            }
        }

        public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color drawColor)
        {
            Texture2D texture = Main.npcTexture[npc.type];
            Vector2 origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f);
            Main.spriteBatch.Draw(texture, npc.Center - Main.screenPosition, new Rectangle?(), drawColor, npc.rotation, origin, npc.scale, SpriteEffects.None, 0);
            return false;
        }
        public override bool CheckActive()
        {
            if (Main.npc[npc.ai[3]].active) return false;
            return true;
        }
        public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
        {

            return false;      //this make that the npc does not have a health bar
        }
    }
}
Lol, that's MB.
Code:
if (Main.npc[(int)npc.ai[3]].active) return false;
it had to be cast as an integer.
 
I need some help. how do i make a boss spawnable only in the hallowed biome? and how do i make a NPC randomly spawn ONLY in the hallowed biome? How do i drain mana with an accessory? How do i add the hermes boots fast running effect?
 
I need some help. how do i make a boss spawnable only in the hallowed biome? and how do i make a NPC randomly spawn ONLY in the hallowed biome? How do i drain mana with an accessory? How do i add the hermes boots fast running effect?
That's quite a low of questions...
I'm guessing you have an items that spawns the boss? If so, you could to something like
Code:
public override bool CanUseItem(Player player)
{
    return player.ZoneHoly;
}
Add that to your item and you can only use it when you're in the Hallowed Biome.

(Almost) the same for the NPC:
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(spawnInfo.player.ZoneHoly)
        return 0.5F;
    return 0;
}

To drain mana with an accessory, something like the following will work:
Code:
public override void UpdateAccessory(Player player, bool hideVisual)
{
    player.manaRegen -= 2;
}

As for the Hermes boots effect"
Code:
public override void UpdateAccessory(Player player, bool hideVisual)
{
    player.accRunSpeed = 6;
}

Hope that helps!
 
I had done my bag with a bit help from that but i got an error
Screenshot_57.png
 
hello. i need help. How does one set an ingredient to be an item from ones mod. thanks in advance :D
Translation: "how do i set an ingredient to be an item from my mod. You are the best person in the world if you know this :D"
 
hello. i need help. How does one set an ingredient to be an item from ones mod. thanks in advance :D
Translation: "how do i set an ingredient to be an item from my mod. You are the best person in the world if you know this :D"
You know the AddIngredient method? There are two ways to call that method.
1: to add a vanilla item
Code:
recipe.AddIngredient(ItemID.DirtBlock, 10);
or 2: to add a ModItem:
Code:
recipe.AddIngredient(null, "MyModItem", 10);
 
so basically i just need to put the name of the moditem in inverted commas? thanks. and yes i do know the AddIngredient method. i just didnt know what i was supposed to put if i wanted an item from my mod to be an ingredient. thank you friend
You know the AddIngredient method? There are two ways to call that method.
1: to add a vanilla item
Code:
recipe.AddIngredient(ItemID.DirtBlock, 10);
or 2: to add a ModItem:
Code:
recipe.AddIngredient(null, "MyModItem", 10);
 
Im having a few problems with one of my NPCs
ArmoredPuritySpirit.png
This is the sprite of the NPc
Screenshot_60.png
This is what i get ingame and this is the ''2nd animation part that i get''
Screenshot_61.png
My code for the frames is this
Screenshot_62.png
also i have the NPCs aistyle set to 5 ''the flying AI'' but its not flying.
 
Back
Top Bottom