tAPI [Tutorial] Custom Bosses - NPC AI and Server Syncing

Thanks. Im probaly gonna need alot more help later so...
[DOUBLEPOST=1453827720,1453827452][/DOUBLEPOST]crap,,, another error
Code:
    using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.NPCs
{
    //ported from my tAPI mod because I'm lazy
    public class Codex : ModNPC
    {
        public override void SetDefaults()
        {
            npc.displayName = "Phantom Codex";
            npc.aiStyle = -1;
            npc.lifeMax = 1000;
            npc.damage = 10;
            npc.defense = 10;
            npc.knockBackResist = 0f; //Immune to knockback
            npc.width = 20;
            npc.height = 20;
            Main.npcFrameCount[npc.type] = 4; //Change to number of images in the sprite
            npc.value = Item.buyPrice(0, 2, 0, 0);
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            music = MusicID.Boss2;
        }

        public override void AI()
        {
            npc.TargetClosest(true);
            Player player = Main.player[npc.target];
            Vector2 moveTo = player.Center + new Vector2(0f, -200f);
            float speed = 5f; //make this whatever you want
            Vector2 move = moveTo - npc.Center; //this is how much your boss wants to move
            float magnitude = Math.Sqrt(move.X * move.X + move.Y * move.Y); //fun with the Pythagorean Theorem
            move *= speed / magnitude; //this adjusts your boss's speed so that its speed is always constant
            npc.velocity = move;
        }
    }
}
:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\Codex.cs(40,19) : error CS0266: Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)

What this is telling you is that your trying to put a value of type double (a decimal form) to a float variable (a different decimal form). So what it is asking you to do is add a "cast", which simply is a way to convert a value to a different type of value. So what you would do is add a variable type in a parenthesis before a value. For example with your problem, you would need to put this "cast" in front of your value being stored, which is your Math.sqrt. Math.sqrt is a function that returns a value of type double, so we put our cast in font of it like this.

Code:
float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);

Before you continue, I would highly recommend you take at least a basic tutorial on programming from places like www.codecademy.com. It will really help you make mods.
 
What this is telling you is that your trying to put a value of type double (a decimal form) to a float variable (a different decimal form). So what it is asking you to do is add a "cast", which simply is a way to convert a value to a different type of value. So what you would do is add a variable type in a parenthesis before a value. For example with your problem, you would need to put this "cast" in front of your value being stored, which is your Math.sqrt. Math.sqrt is a function that returns a value of type double, so we put our cast in font of it like this.

Code:
float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);

Before you continue, I would highly recommend you take at least a basic tutorial on programming from places like www.codecademy.com. It will really help you make mods.
I dont see a C# tut
[DOUBLEPOST=1453831013,1453830928][/DOUBLEPOST]And I used CodeAcadamy before. Thats why i know HTML
 
Hello! I have returned, for decades ago! and i have come with a question!

So, With this terrible AI i created, for some reason, after a few seconds my monsters just stops attacking me and moves straight up or straight down.

Code:
using Terraria;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod.NPCs.Boss
{
    public class Argargothicon : ModNPC
    {
        private float XSpeed;
        private float YSpeed;
        public override void SetDefaults()
        {
            npc.name = "Argargothicon";
            npc.displayName = "Argargothicon";
            npc.width = 420;
            npc.height = 403;
            npc.damage = 32;
            npc.noTileCollide = true;
            npc.defense = 40;
            npc.boss = true;
            npc.lifeMax = 25000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.noGravity = true;
            npc.value = 60f;
            npc.knockBackResist = 0f;
    
        }
        public override void AI()
    {
        if (npc.life < 10000)
        {
            npc.TargetClosest(true);
            Player player = Main.player[npc.target];
        }
        if (npc.life >= 25000)
        {
            npc.TargetClosest(true);
            Player player = Main.player[npc.target];
            Vector2 moveTo = player.Center + new Vector2(0f, -100f); //This is 200 pixels above the center of the player.
            float speed = 5f;
            Vector2 move = moveTo - npc.Center;
            float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            if(magnitude > speed)
                {
                    move *= speed / magnitude;
                }
            float turnResistance = 10f; //the larger this is, the slower the npc will turn
            move = (npc.velocity * turnResistance + move) / (turnResistance + 1f);
            magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            if(magnitude > speed)
                {
                move *= speed / magnitude;
                }
            npc.velocity = move;
        }
    }
    }
}
 
Hello! I have returned, for decades ago! and i have come with a question!

So, With this terrible AI i created, for some reason, after a few seconds my monsters just stops attacking me and moves straight up or straight down.

Code:
using Terraria;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod.NPCs.Boss
{
    public class Argargothicon : ModNPC
    {
        private float XSpeed;
        private float YSpeed;
        public override void SetDefaults()
        {
            npc.name = "Argargothicon";
            npc.displayName = "Argargothicon";
            npc.width = 420;
            npc.height = 403;
            npc.damage = 32;
            npc.noTileCollide = true;
            npc.defense = 40;
            npc.boss = true;
            npc.lifeMax = 25000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.noGravity = true;
            npc.value = 60f;
            npc.knockBackResist = 0f;
  
        }
        public override void AI()
    {
        if (npc.life < 10000)
        {
            npc.TargetClosest(true);
            Player player = Main.player[npc.target];
        }
        if (npc.life >= 25000)
        {
            npc.TargetClosest(true);
            Player player = Main.player[npc.target];
            Vector2 moveTo = player.Center + new Vector2(0f, -100f); //This is 200 pixels above the center of the player.
            float speed = 5f;
            Vector2 move = moveTo - npc.Center;
            float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            if(magnitude > speed)
                {
                    move *= speed / magnitude;
                }
            float turnResistance = 10f; //the larger this is, the slower the npc will turn
            move = (npc.velocity * turnResistance + move) / (turnResistance + 1f);
            magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            if(magnitude > speed)
                {
                move *= speed / magnitude;
                }
            npc.velocity = move;
        }
    }
    }
}
You have see than than npc.life is between 10000-24 999, you have not code? So, this is normal, for me.

After, if you have really not attacked the mob, i have not found problem, sorry ^^.
 
Terraria doesn't recognize 'NewNPC'

c:\Users\Hallam\Documents\My Games\Terraria\ModLoader\Mod Sources\ModOfRandomness\NPC\InfectedEye.cs(77,21) : error CS0234: The type or namespace name 'NewNPC' does not exist in the namespace 'ModOfRandomness.NPC' (are you missing an assembly reference?)

Pls help meh!
 
Terraria doesn't recognize 'NewNPC'

c:\Users\Hallam\Documents\My Games\Terraria\ModLoader\Mod Sources\ModOfRandomness\NPC\InfectedEye.cs(77,21) : error CS0234: The type or namespace name 'NewNPC' does not exist in the namespace 'ModOfRandomness.NPC' (are you missing an assembly reference?)

Pls help meh!
Giving us just the error doesn't help us help you at all, you should give us context for the error, meaning giving us the code so we can analyse the problem and tell you the answer to fix said problem.
 
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModOfRandomness.NPC
{
    public class InfectedEye : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Infected Eye";
            npc.displayName = "Infected Eye";
            npc.aiStyle = 5;  //5 is the flying AI
            npc.lifeMax = 10000;   //boss life
            npc.damage = 70;  //boss damage
            npc.defense = 20;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 110;
            npc.height = 166;
            animationType = NPCID.DemonEye;   //this boss will behavior like the DemonEye
            Main.npcFrameCount[npc.type] = 3;    //boss frame/animation
            npc.value = Item.buyPrice(0, 6, 50, 0);
            npc.npcSlots = 1f;
            npc.boss = true; 
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "ModOfRandomness/NPC/InfectedEye_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("Xenomite"));
        }
        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[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            npc.ai[1]++;
            if (npc.ai[1] >= 80)  // 230 is projectile fire rate
            {
                float Speed = 12f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 60;  //projectile damage
                int type = mod.ProjectileType("InfectedEyePro");  //put your projectile
                Main.PlaySound(15, (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;
            }
            if (npc.ai[0] % 600 == 3)  //Npc spown rate

            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("InfectedZombie"));  //NPC name
            }
            npc.ai[1] += 0;
            if (npc.life <= 5000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 3000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 5.98f;
                npc.velocity.Y *= 5.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 2000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 10.98f;
                npc.velocity.Y *= 10.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 1.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 800)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 30.98f;
                npc.velocity.Y *= 30.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 4.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 1.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 50;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
        }
    }
}
 
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModOfRandomness.NPC
{
    public class InfectedEye : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Infected Eye";
            npc.displayName = "Infected Eye";
            npc.aiStyle = 5;  //5 is the flying AI
            npc.lifeMax = 10000;   //boss life
            npc.damage = 70;  //boss damage
            npc.defense = 20;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 110;
            npc.height = 166;
            animationType = NPCID.DemonEye;   //this boss will behavior like the DemonEye
            Main.npcFrameCount[npc.type] = 3;    //boss frame/animation
            npc.value = Item.buyPrice(0, 6, 50, 0);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "ModOfRandomness/NPC/InfectedEye_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("Xenomite"));
        }
        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[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            npc.ai[1]++;
            if (npc.ai[1] >= 80)  // 230 is projectile fire rate
            {
                float Speed = 12f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 60;  //projectile damage
                int type = mod.ProjectileType("InfectedEyePro");  //put your projectile
                Main.PlaySound(15, (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;
            }
            if (npc.ai[0] % 600 == 3)  //Npc spown rate

            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("InfectedZombie"));  //NPC name
            }
            npc.ai[1] += 0;
            if (npc.life <= 5000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 3000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 5.98f;
                npc.velocity.Y *= 5.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 2000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 10.98f;
                npc.velocity.Y *= 10.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 1.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
            npc.ai[1] += 0;
            if (npc.life <= 800)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 30.98f;
                npc.velocity.Y *= 30.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 4.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 1.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 50;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
        }
    }
}
It looks like the NPC class from your mod is conflicting with the NPC class from Terraria. Try Terraria.NPC.NewNPC instead.
 
Hi I am a tmodloader user but i check this tapi thingy(because i know it is useful sometimes sometimes it is not conpitiable) anyway i need to know why my boss is not spawning(but i take damage in the same time as summoning because it is big)(also texture didn't appear either) So here is my code(i said i will update today but i can't)
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CraftMaxedHacks.NPCs.Boss
{
    public class KingSharkneon : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Sharkneon";        //boss name
            npc.displayName = "King Sharkneon";        //display name
            npc.aiStyle = 5;  //5 is the flying AI style
            npc.lifeMax = 5000000;   //boss life
            npc.damage = 1000;  //boss damage
            npc.defense = 925;    //boss defense
            npc.knockBackResist = 0f;        //make boss invunerable to knockback
            npc.width = 392;
            npc.height = 390;
            animationType = NPCID.DemonEye;   //this boss will animate like the DemonEye
            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 = true;
            npc.noTileCollide = true;
            npc.buffImmune[24] = true;
            music = MusicID.TheTowers;            //boss music
            npc.netAlways = true;
            if (npc.life <= 3500000)
            {  
            npc.damage = 1500;  //boss damage
            npc.defense = 825;    //boss defense
            }
        }
        public override void HitEffect(int hitDirection, double damage)
        {  
            Main.PlaySound(41, (int)npc.position.X, (int)npc.position.Y, 0);
        }
      
        public override bool Autoload(ref string name, ref string texture, ref string[] altTextures)
        {
            if (npc.life <= 3500000)
            {
                texture = "CraftMaxedHacks/NPCs/Boss/KingSharkneonPhase2";
            }
            return mod.Properties.Autoload;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "CraftMaxedHacks/NPCs/Boss/KingSharkneon_Head_Boss"; //the boss head texture
            if (npc.life <= 3500000)
            {
                bossHeadTexture = "CraftMaxedHacks/NPCs/Boss/KingSharkneonPhase2_Head_Boss";
            }
        }
        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 BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.SuperHealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GreatShark"));
          

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }
        }      
        public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }

            npc.ai[1]++;            //ai 1
            if (npc.ai[1] >= 30)  // 30 is projectile fire rate
            {
                float Speed = 1f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 950;  //projectile damage
                int type = mod.ProjectileType("Bubble");  //put your 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)));
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
            }
            npc.ai[2]++;            //AI 2
          
          
            if (npc.ai[2] % 500 == 3)  //Npc spown rate
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("NeonGuard"));  //NPC name
            }
            if (npc.life <= 3500000)  //when the boss has less than 3500000 health phase 2 will trigger
                npc.ai[3]++;                //Charge Attack
                npc.ai[4]++;                //Phase 2 projectile
            if (npc.ai[3] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
            }
            if (npc.ai[4] >= 5)    // Projectile
            {
                float Speed = 1f;  //projectile speed
                int damage = 960;  //projectile damage
                int type = mod.ProjectileType("Bubble");  //put your projectile
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
            }
        }
    }
}
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CraftMaxedHacks.NPCs.Boss
{
    public class KingSharkneon : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Sharkneon";        //boss name
            npc.displayName = "King Sharkneon";        //display name
            npc.aiStyle = 5;  //5 is the flying AI style
            npc.lifeMax = 5000000;   //boss life
            npc.damage = 1000;  //boss damage
            npc.defense = 925;    //boss defense
            npc.knockBackResist = 0f;        //make boss invunerable to knockback
            npc.width = 392;
            npc.height = 390;
            animationType = NPCID.DemonEye;   //this boss will animate like the DemonEye
            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 = true;
            npc.noTileCollide = true;
            npc.buffImmune[24] = true;
            music = MusicID.TheTowers;            //boss music
            npc.netAlways = true;
            if (npc.life <= 3500000)
            {   
            npc.damage = 1500;  //boss damage
            npc.defense = 825;    //boss defense
            }
        }
        public override void HitEffect(int hitDirection, double damage)
        {   
            Main.PlaySound(41, (int)npc.position.X, (int)npc.position.Y, 0);
        }
       
        public override bool Autoload(ref string name, ref string texture, ref string[] altTextures)
        {
            if (npc.life <= 3500000)
            {
                texture = "CraftMaxedHacks/NPCs/Boss/KingSharkneonPhase2";
            }
            return mod.Properties.Autoload;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "CraftMaxedHacks/NPCs/Boss/KingSharkneon_Head_Boss"; //the boss head texture
            if (npc.life <= 3500000)
            {
                bossHeadTexture = "CraftMaxedHacks/NPCs/Boss/KingSharkneonPhase2_Head_Boss";
            }
        }
        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 BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.SuperHealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GreatShark"));
           

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }

            if (Main.rand.Next(2) == 3)   //item rarity
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName")); //Item spawn
            }
        }       
        public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }

            npc.ai[1]++;            //ai 1
            if (npc.ai[1] >= 30)  // 30 is projectile fire rate
            {
                float Speed = 1f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 950;  //projectile damage
                int type = mod.ProjectileType("Bubble");  //put your 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)));
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
            }
            npc.ai[2]++;            //AI 2
           
           
            if (npc.ai[2] % 500 == 3)  //Npc spown rate
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("NeonGuard"));  //NPC name
            }
            if (npc.life <= 3500000)  //when the boss has less than 3500000 health phase 2 will trigger
                npc.ai[3]++;                //Charge Attack
                npc.ai[4]++;                //Phase 2 projectile
            if (npc.ai[3] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
            }
            if (npc.ai[4] >= 5)    // Projectile
            {
                float Speed = 1f;  //projectile speed
                int damage = 960;  //projectile damage
                int type = mod.ProjectileType("Bubble");  //put your projectile
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
                Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 1f, 0);
            }
        }
    }
}
[doublepost=1486564696,1486564394][/doublepost]whos replying
[doublepost=1486564722][/doublepost]hi
 
yo ho,its even morning
(i posted on night)
There's no need to spam a thread in hopes of an answer.
Especially with a question like this; since it isn't really a problem that can be solved without testing (unless you have a deep understanding of AI and even then...)
I'll try having a look at it, but no promises. Most AI's are huge chunks of code, which not everyone wants to spit through to find your problem.
Just a heads up.
 
  • Like
Reactions: 000
so i read this entire thread and half the comments and yet still cant find a simple way to make my boss (float above shooting projectiles. once it gets to half health it needs to change and kinda like cthulhu but it cant dash towards you or it wont work. and i want it to shoot enemies like cthulhu but all i can figure out how to do is act like demon eyes
 
Hejo Guys, i am pretty new into this whole Modding Stuff. I tried to create a Worm Boss just like the Eater of worlds. (i used a template)
It all works fine, he spawns, music kicks in, he attacks me...
BUT
After some time parts of him despawn. And if i die the Head stays and keeps following me :O
Halp plz :D
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MementoMod.NPCs.DimensionWorm
{
    public class WormHead : ModNPC
    {

        public override void SetDefaults()
        {
            npc.name = "The Eater of Dimensions";        //this is the npc Name
            npc.displayName = "The Eater of Dimensions";
            npc.lifeMax = 750000;        //this is the npc health
            npc.damage = 200;    //this is the npc damage
            npc.defense = 100;         //this is the npc defense
            npc.aiStyle = -1;
            npc.knockBackResist = 0f;
            npc.width = 200; //this is where you put the npc sprite width.     important
            npc.height = 318; //this is where you put the npc sprite height.   important
            npc.boss = true;
            npc.lavaImmune = true;       //this make the npc immune to lava
            npc.noGravity = true;           //this make the npc float
            npc.noTileCollide = true;        //this make the npc go tru walls
            npc.behindTiles = true;
            Main.npcFrameCount[npc.type] = 1;
            npc.value = Item.buyPrice(0, 20, 0, 0);
            npc.npcSlots = 5f;
            npc.netAlways = true;
            music = MusicID.Boss2;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            animationType = NPCID.TheDestroyer;
            NPCID.Sets.MustAlwaysDraw[npc.type] = true;
            npc.behindTiles = true;
            npc.value = 120000f;
            npc.alpha = (int) byte.MaxValue;
        }
       
        public override void AI()
        {
            if (npc.localAI[0] == 0f)
            {
                Main.PlaySound(SoundID.Roar, npc.position, 0);
                npc.localAI[0] = 1f;
            }
            npc.velocity.Y += 1f;
            if (npc.timeLeft > 10)
            {
                npc.timeLeft = 10;
            }
        }
       
        public override bool Autoload(ref string name, ref string texture, ref string[] altTextures)
        {
            texture = "MementoMod/NPCs/DimensionWorm/WormHead";
            return mod.Properties.Autoload;
        }
       
        public virtual bool CheckActive()
        {
            return true;
        }

        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("DimensionBreaker"));
        }
        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 bool PreAI()
        {
            if (Main.netMode != 1)
            {
                // So, we start the AI off by checking if npc.ai[0] is 0.
                // This is practically ALWAYS the case with a freshly spawned NPC, so this means this is the first update.
                // Since this is the first update, we can safely assume we need to spawn the rest of the worm (bodies + tail).
                if (npc.ai[0] == 0)
                {
                    // So, here we assing the npc.realLife value.
                    // The npc.realLife value is mainly used to determine which NPC loses life when we hit this NPC.
                    // We don't want every single piece of the worm to have its own HP pool, so this is a neat way to fix that.
                    npc.realLife = npc.whoAmI;
                    // LatestNPC is going to be used later on and I'll explain it there.
                    int latestNPC = npc.whoAmI;

                    // Here we determine the length of the worm.
                    // In this case the worm will have a length of 10 to 14 body parts.
                    int randomWormLength = Main.rand.Next(40, 40);
                    for (int i = 0; i < randomWormLength; ++i)
                    {
                        // We spawn a new NPC, setting latestNPC to the newer NPC, whilst also using that same variable
                        // to set the parent of this new NPC. The parent of the new NPC (may it be a tail or body part)
                        // will determine the movement of this new NPC.
                        // Under there, we also set the realLife value of the new NPC, because of what is explained above.
                        latestNPC = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("WormBody"), npc.whoAmI, 0, latestNPC);
                        Main.npc[(int)latestNPC].realLife = npc.whoAmI;
                        Main.npc[(int)latestNPC].ai[3] = npc.whoAmI;
                    }
                    // When we're out of that loop, we want to 'close' the worm with a tail part!
                    latestNPC = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("WormTail"), npc.whoAmI, 0, latestNPC);
                    Main.npc[(int)latestNPC].realLife = npc.whoAmI;
                    Main.npc[(int)latestNPC].ai[3] = npc.whoAmI;

                    // We're setting npc.ai[0] to 1, so that this 'if' is not triggered again.
                    npc.ai[0] = 1;
                    npc.netUpdate = true;
                }
            }

            int minTilePosX = (int)(npc.position.X / 16.0) - 1;
            int maxTilePosX = (int)((npc.position.X + npc.width) / 16.0) + 2;
            int minTilePosY = (int)(npc.position.Y / 16.0) - 1;
            int maxTilePosY = (int)((npc.position.Y + npc.height) / 16.0) + 2;
            if (minTilePosX < 0)
                minTilePosX = 0;
            if (maxTilePosX > Main.maxTilesX)
                maxTilePosX = Main.maxTilesX;
            if (minTilePosY < 0)
                minTilePosY = 0;
            if (maxTilePosY > Main.maxTilesY)
                maxTilePosY = Main.maxTilesY;

            bool collision = false;
            // This is the initial check for collision with tiles.
            for (int i = minTilePosX; i < maxTilePosX; ++i)
            {
                for (int j = minTilePosY; j < maxTilePosY; ++j)
                {
                    if (Main.tile[i, j] != null && (Main.tile[i, j].nactive() && (Main.tileSolid[(int)Main.tile[i, j].type] || Main.tileSolidTop[(int)Main.tile[i, j].type] && (int)Main.tile[i, j].frameY == 0) || (int)Main.tile[i, j].liquid > 64))
                    {
                        Vector2 vector2;
                        vector2.X = (float)(i * 16);
                        vector2.Y = (float)(j * 16);
                        if (npc.position.X + npc.width > vector2.X && npc.position.X < vector2.X + 16.0 && (npc.position.Y + npc.height > (double)vector2.Y && npc.position.Y < vector2.Y + 16.0))
                        {
                            collision = true;
                            if (Main.rand.Next(100) == 0 && Main.tile[i, j].nactive())
                                WorldGen.KillTile(i, j, true, true, false);
                        }
                    }
                }
            }
            // If there is no collision with tiles, we check if the distance between this NPC and its target is too large, so that we can still trigger 'collision'.
            if (!collision)
            {
                Rectangle rectangle1 = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height);
                int maxDistance = 800;
                bool playerCollision = true;
                for (int index = 0; index < 255; ++index)
                {
                    if (Main.player[index].active)
                    {
                        Rectangle rectangle2 = new Rectangle((int)Main.player[index].position.X - maxDistance, (int)Main.player[index].position.Y - maxDistance, maxDistance * 2, maxDistance * 2);
                        if (rectangle1.Intersects(rectangle2))
                        {
                            playerCollision = false;
                            break;
                        }
                    }
                }
                if (playerCollision)
                    collision = true;
            }

            // speed determines the max speed at which this NPC can move.
            // Higher value = faster speed.
            float speed = 40f;
            // acceleration is exactly what it sounds like. The speed at which this NPC accelerates.
            float acceleration = 0.17f;

            Vector2 npcCenter = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f);
            float targetXPos = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2);
            float targetYPos = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2);

            float targetRoundedPosX = (float)((int)(targetXPos / 16.0) * 16);
            float targetRoundedPosY = (float)((int)(targetYPos / 16.0) * 16);
            npcCenter.X = (float)((int)(npcCenter.X / 16.0) * 16);
            npcCenter.Y = (float)((int)(npcCenter.Y / 16.0) * 16);
            float dirX = targetRoundedPosX - npcCenter.X;
            float dirY = targetRoundedPosY - npcCenter.Y;

            float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
            // If we do not have any type of collision, we want the NPC to fall down and de-accelerate along the X axis.
            if (!collision)
            {
                npc.TargetClosest(true);
                npc.velocity.Y = npc.velocity.Y + 0.11f;
                if (npc.velocity.Y > speed)
                    npc.velocity.Y = speed;
                if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.4)
                {
                    if (npc.velocity.X < 0.0)
                        npc.velocity.X = npc.velocity.X - acceleration * 1.1f;
                    else
                        npc.velocity.X = npc.velocity.X + acceleration * 1.1f;
                }
                else if (npc.velocity.Y == speed)
                {
                    if (npc.velocity.X < dirX)
                        npc.velocity.X = npc.velocity.X + acceleration;
                    else if (npc.velocity.X > dirX)
                        npc.velocity.X = npc.velocity.X - acceleration;
                }
                else if (npc.velocity.Y > 4.0)
                {
                    if (npc.velocity.X < 0.0)
                        npc.velocity.X = npc.velocity.X + acceleration * 0.9f;
                    else
                        npc.velocity.X = npc.velocity.X - acceleration * 0.9f;
                }
            }
            // Else we want to play some audio (soundDelay) and move towards our target.
            else
            {
                if (npc.soundDelay == 0)
                {
                    float num1 = length / 40f;
                    if (num1 < 10.0)
                        num1 = 10f;
                    if (num1 > 20.0)
                        num1 = 20f;
                    npc.soundDelay = (int)num1;
                    Main.PlaySound(15, (int)npc.position.X, (int)npc.position.Y, 1);
                }
                float absDirX = Math.Abs(dirX);
                float absDirY = Math.Abs(dirY);
                float newSpeed = speed / length;
                dirX = dirX * newSpeed;
                dirY = dirY * newSpeed;
                if (npc.velocity.X > 0.0 && dirX > 0.0 || npc.velocity.X < 0.0 && dirX < 0.0 || (npc.velocity.Y > 0.0 && dirY > 0.0 || npc.velocity.Y < 0.0 && dirY < 0.0))
                {
                    if (npc.velocity.X < dirX)
                        npc.velocity.X = npc.velocity.X + acceleration;
                    else if (npc.velocity.X > dirX)
                        npc.velocity.X = npc.velocity.X - acceleration;
                    if (npc.velocity.Y < dirY)
                        npc.velocity.Y = npc.velocity.Y + acceleration;
                    else if (npc.velocity.Y > dirY)
                        npc.velocity.Y = npc.velocity.Y - acceleration;
                    if (Math.Abs(dirY) < speed * 0.2 && (npc.velocity.X > 0.0 && dirX < 0.0 || npc.velocity.X < 0.0 && dirX > 0.0))
                    {
                        if (npc.velocity.Y > 0.0)
                            npc.velocity.Y = npc.velocity.Y + acceleration * 2f;
                        else
                            npc.velocity.Y = npc.velocity.Y - acceleration * 2f;
                    }
                    if (Math.Abs(dirX) < speed * 0.2 && (npc.velocity.Y > 0.0 && dirY < 0.0 || npc.velocity.Y < 0.0 && dirY > 0.0))
                    {
                        if (npc.velocity.X > 0.0)
                            npc.velocity.X = npc.velocity.X + acceleration * 2f;
                        else
                            npc.velocity.X = npc.velocity.X - acceleration * 2f;
                    }
                }
                else if (absDirX > absDirY)
                {
                    if (npc.velocity.X < dirX)
                        npc.velocity.X = npc.velocity.X + acceleration * 1.1f;
                    else if (npc.velocity.X > dirX)
                        npc.velocity.X = npc.velocity.X - acceleration * 1.1f;
                    if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.5)
                    {
                        if (npc.velocity.Y > 0.0)
                            npc.velocity.Y = npc.velocity.Y + acceleration;
                        else
                            npc.velocity.Y = npc.velocity.Y - acceleration;
                    }
                }
                else
                {
                    if (npc.velocity.Y < dirY)
                        npc.velocity.Y = npc.velocity.Y + acceleration * 1.1f;
                    else if (npc.velocity.Y > dirY)
                        npc.velocity.Y = npc.velocity.Y - acceleration * 1.1f;
                    if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.5)
                    {
                        if (npc.velocity.X > 0.0)
                            npc.velocity.X = npc.velocity.X + acceleration;
                        else
                            npc.velocity.X = npc.velocity.X - acceleration;
                    }
                }
            }
            // Set the correct rotation for this NPC.
            npc.rotation = (float)Math.Atan2(npc.velocity.Y, npc.velocity.X) + 1.57f;
           
            // Some netupdate stuff (multiplayer compatibility).
            if (collision)
            {
                if (npc.localAI[0] != 1)
                    npc.netUpdate = true;
                npc.localAI[0] = 1f;
            }
            else
            {
                if (npc.localAI[0] != 0.0)
                    npc.netUpdate = true;
                npc.localAI[0] = 0.0f;
            }
            if ((npc.velocity.X > 0.0 && npc.oldVelocity.X < 0.0 || npc.velocity.X < 0.0 && npc.oldVelocity.X > 0.0 || (npc.velocity.Y > 0.0 && npc.oldVelocity.Y < 0.0 || npc.velocity.Y < 0.0 && npc.oldVelocity.Y > 0.0)) && !npc.justHit)
                npc.netUpdate = true;

            return false;
        }

        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? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
        {
            scale = 1.9f;   //this make the NPC Health Bar biger
            return null;
        }
    }
}
 
How would you make your own AI for a boss instead of just using examples of it from vanilla Terraria such as npc.aiStyle = #?
if tModLoader works any way like tAPI or tConfig used to work on that regard, just giving your NPC's .cs file an AI method override will be enough to have the NPC run its own routine instead of taking from aiStyle. Granted, I would still suggest to set aiStyle to -1 to make sure it breaks every tie with vanilla NPCs. Again, if it works anywhere as similarly as the previous APIs, using PreAI instead should even allow you to run an "additional" pre-cycle right before the vanilla AI, effectively allowing you to tweak it to a certain extent.

As far as coding your own AI goes, it's mostly just a matter of creative thinking. You simply use the information the game gives you (positions, velocities, new projectile calls, and so on), give the AI conditions and apply your changes to velocity, or create projectiles. The npoc.ai[] array is especially useful for this, and especially for timers, as npc.ai[] is the only array of variables (that i know of) outside of velocity and position that are synced over multiplayer.
The npc.localAI[] array might also be useful if you ever need multiple NPCs to interact with each others and share variables, but same can be done with the npc.ai[] array and to even greater effect as it will ensure the NPCs interractions are also properly synced over multiplayer.
 
question pls. How can I make my boss fire two projectiles at a time? I tested my boss and it was quite weak and i didn't want to increase damage or projectile fire rate. I want my boss to fire two projectiles at the same time or in a short delay, how can I do that?
 
question pls. How can I make my boss fire two projectiles at a time? I tested my boss and it was quite weak and i didn't want to increase damage or projectile fire rate. I want my boss to fire two projectiles at the same time or in a short delay, how can I do that?
Are you using a vanilla AI or a custom AI?
 
Back
Top Bottom