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

I am using vanilla AI
Well with Vanilla AI, it is usually difficult to actually change anything, as you don't have the code to mingle with at all, only using the code given. There isn't really a good way to do this unless you look at the Vanilla AI code. What AI ID are you using?
 
King Slime AI
here is the code if you want to take a look:

using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;


namespace YourModName.NPCs.Boss
{
public class NpcName : ModNPC
{
public override void SetDefaults()
{
npc.name = "Crabber";
npc.displayName = "Crabber";
npc.width = 50;
npc.height = 40;
npc.damage = 30;
npc.defense = 5;
npc.lifeMax = 3000;
npc.HitSound = SoundID.NPCHit5;
npc.DeathSound = SoundID.NPCDeath7;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 1;
Main.npcFrameCount[npc.type] = 1;
aiType = NPCID.KingSlime; //npc behavior
animationType = NPCID.KingSlime;
npc.npcSlots = 1f;
npc.boss = true;
music = MusicID.Boss2;
npc.netAlways = true;
}
public override void FindFrame(int frameHeight)
{
npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;

npc.spriteDirection = npc.direction;

}
public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "YourModName/NPCs/Boss/BossName_Head_Boss1"; //the boss head texture
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.LesserHealingPotion; //boss drops
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YourSword"));
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
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] >= 100) // 230 is projectile fire rate
{
float Speed = 20f; //projectile speed
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 8; //projectile damage
int type = mod.ProjectileType("CrabberProjectile"); //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)));
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, NPCID.Crab); //NPC name
}
npc.ai[1] += 0;
}
}
}
 
King Slime AI
here is the code if you want to take a look:

using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;


namespace YourModName.NPCs.Boss
{
public class NpcName : ModNPC
{
public override void SetDefaults()
{
npc.name = "Crabber";
npc.displayName = "Crabber";
npc.width = 50;
npc.height = 40;
npc.damage = 30;
npc.defense = 5;
npc.lifeMax = 3000;
npc.HitSound = SoundID.NPCHit5;
npc.DeathSound = SoundID.NPCDeath7;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 1;
Main.npcFrameCount[npc.type] = 1;
aiType = NPCID.KingSlime; //npc behavior
animationType = NPCID.KingSlime;
npc.npcSlots = 1f;
npc.boss = true;
music = MusicID.Boss2;
npc.netAlways = true;
}
public override void FindFrame(int frameHeight)
{
npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;

npc.spriteDirection = npc.direction;

}
public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "YourModName/NPCs/Boss/BossName_Head_Boss1"; //the boss head texture
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.LesserHealingPotion; //boss drops
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YourSword"));
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
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] >= 100) // 230 is projectile fire rate
{
float Speed = 20f; //projectile speed
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 8; //projectile damage
int type = mod.ProjectileType("CrabberProjectile"); //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)));
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, NPCID.Crab); //NPC name
}
npc.ai[1] += 0;
}
}
}
Oh...

This is simply a matter of copying and pasting. Just copy the "if(npc.ai[1] >= 100)" statement and the stuff within the if statement, then change the values accordingly, if you want, I can explain what all the components of your AI hook does, probably make it more readable too if you want to.
 
c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(85,23) : error CS0136: A local variable named 'Speed' cannot be declared in this scope because it would give a different meaning to 'Speed', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(86,25) : error CS0136: A local variable named 'vector8' cannot be declared in this scope because it would give a different meaning to 'vector8', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(87,21) : error CS0136: A local variable named 'damage' cannot be declared in this scope because it would give a different meaning to 'damage', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(88,21) : error CS0136: A local variable named 'type' cannot be declared in this scope because it would give a different meaning to 'type', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(90,23) : error CS0136: A local variable named 'rotation' cannot be declared in this scope because it would give a different meaning to 'rotation', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(91,21) : error CS0136: A local variable named 'num54' cannot be declared in this scope because it would give a different meaning to 'num54', which is already used in a 'parent or current' scope to denote something else

this error always pops up when i copied and pasted the if(npc.ai[1] >= 100)" and its statment.
 
c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(85,23) : error CS0136: A local variable named 'Speed' cannot be declared in this scope because it would give a different meaning to 'Speed', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(86,25) : error CS0136: A local variable named 'vector8' cannot be declared in this scope because it would give a different meaning to 'vector8', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(87,21) : error CS0136: A local variable named 'damage' cannot be declared in this scope because it would give a different meaning to 'damage', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(88,21) : error CS0136: A local variable named 'type' cannot be declared in this scope because it would give a different meaning to 'type', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(90,23) : error CS0136: A local variable named 'rotation' cannot be declared in this scope because it would give a different meaning to 'rotation', which is already used in a 'parent or current' scope to denote something else

c:\Users\Rowald\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\NPCs\Boss\NpcName.cs(91,21) : error CS0136: A local variable named 'num54' cannot be declared in this scope because it would give a different meaning to 'num54', which is already used in a 'parent or current' scope to denote something else

this error always pops up when i copied and pasted the if(npc.ai[1] >= 100)" and its statment.
You need to rename the variables too.
 
how can i do that?
*Sorry still a quite newbie in coding
So, uhh, variables are probably the first thing you should learn about before starting to code. So you should stop modding for a while to familiarize yourself with the concept of coding by looking at some C# or learn a similar language like Java, which a lesson thing is available at codecademy.com, and then when you have some basic knowledge, you can start over with better understanding and can do some cool stuff.

So anyways, variables are a type of item that stores information depending on the type and the information. There are two types of variables, those being the primitive and object variables. Primitive is the bread and butter of a simple program, though it differs between languages. For C# we have

Code:
int
Stores an Integer

double
Stores a decimal

float
Also stores a decimal, however can store more information than double so this is more widely used

string
Stores a set of characters, like this sentence

char
Stores a single character, like "a"

I'm not going to explain object variables due to it being a sort of advanced thing to you.

Anyways, a type is followed by a name, so it can be referenced later on, so you see things like:

Code:
int num;
double dec1;
float dec2;
string characters;
char character;

From here on, these can now be referenced, however they do not store any information, so we set it equal to something it can store, so here we go:

Code:
int num = 1;
double dec1 = 1.01;
float dec2 = 1.02;
string characters = "String";
char character = 'c';

Notice how some things are wrapped around by quotations, those quotations indicate whether it is a string or a char. What we have are called instantiated variables, meaning they are variables that start with that initial value. Later on, we do not need to use the type indicators anymore since the name of the variable contains both the type and the value, meaning you can do things like have a different variable contain the same value as another variable or modify the value of the variable like this:

Code:
num = 2;
int num2 = num;

That is about the simplest way to explain variables, so you should be able to discern for yourself what you need to do.

Please, look into coding guides like the ones found in the Official tModLoader Help Thread.
 
I know this might sound like i'm not ready but i fully understand most of this but some of it confuses me and i don't know what i'll do! I was hoping someone might be able to help me make a boss? I could send over the texture files for the boss and the lootbag expert item. Would anyone like to do this?
If so then:

Ai= Hover over for a short time then attack melee. (Similar To eye of cthulu

Projectile=I called the projectile i wanted it to shoot called the BetterTerrabeam which is in my projectiles folder

LootBag=I think i can make the lootbag myself but can you make him drop it? If you need any specification then just call it TrueTerraLootBag.

I will provide full credit toward the making of this boss and might even make an item with your profile pic if you want for the lootbag.
Thanks
-Arctic/Haunted
 
Plz help error in line 78
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace KahanMod.NPCs.Bosses
{
    public class Yama : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Yama";
            npc.displayName = "Yama";
            npc.aiStyle = 0; 
            npc.lifeMax = 9000;  
            npc.damage = 40; 
            npc.defense = 25;  
            npc.knockBackResist = 0f;
            npc.width = 60;
            npc.height = 30;
            animationType = NPCID.BoundGoblin; 
            Main.npcFrameCount[npc.type] = 2;   
            npc.value = Item.buyPrice(0, 0, 10, 0);
            npc.npcSlots = 1f;
            npc.boss = true; 
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath17;
            npc.buffImmune[24] = false;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "KahanMod/NPCs/Bosses/Yama_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion;  
             if (Main.expertMode)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YamaTreasureBag"));
            }
            else
          {                           
            int choice = Main.rand.Next(3);
            if (choice == 0)
            {
                  Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YoyoMold"));
            }
            if (choice == 1)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FlailMold"));
            }
            if (choice == 2)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KatanaMold"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RedFragment"), Main.rand.Next(5, 10));
          }
       
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); 
            npc.damage = (int)(npc.damage * 0.6f); 
        }
        public override void AI()
        {
         Player player = Main.player[npc.target];
         Vector2 moveTo = player.Center + new Vector2(0f, -200f);
         float speed = 5f;
         Vector2 move = moveTo - npc.Center;
         float magnitude = Math.Sqrt(move.X * move.X + move.Y * move.Y);            here is the error
         move *= speed / magnitude;
         npc.velocity = move;
        }
    }
}
 
Plz help error in line 78
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace KahanMod.NPCs.Bosses
{
    public class Yama : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Yama";
            npc.displayName = "Yama";
            npc.aiStyle = 0;
            npc.lifeMax = 9000; 
            npc.damage = 40;
            npc.defense = 25; 
            npc.knockBackResist = 0f;
            npc.width = 60;
            npc.height = 30;
            animationType = NPCID.BoundGoblin;
            Main.npcFrameCount[npc.type] = 2;  
            npc.value = Item.buyPrice(0, 0, 10, 0);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath17;
            npc.buffImmune[24] = false;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "KahanMod/NPCs/Bosses/Yama_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion; 
             if (Main.expertMode)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YamaTreasureBag"));
            }
            else
          {                          
            int choice = Main.rand.Next(3);
            if (choice == 0)
            {
                  Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YoyoMold"));
            }
            if (choice == 1)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FlailMold"));
            }
            if (choice == 2)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KatanaMold"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RedFragment"), Main.rand.Next(5, 10));
          }
      
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale);
            npc.damage = (int)(npc.damage * 0.6f);
        }
        public override void AI()
        {
         Player player = Main.player[npc.target];
         Vector2 moveTo = player.Center + new Vector2(0f, -200f);
         float speed = 5f;
         Vector2 move = moveTo - npc.Center;
         float magnitude = Math.Sqrt(move.X * move.X + move.Y * move.Y);            here is the error
         move *= speed / magnitude;
         npc.velocity = move;
        }
    }
}
What is the error exactly?
 
Plz help error in line 78
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace KahanMod.NPCs.Bosses
{
    public class Yama : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Yama";
            npc.displayName = "Yama";
            npc.aiStyle = 0;
            npc.lifeMax = 9000;
            npc.damage = 40;
            npc.defense = 25;
            npc.knockBackResist = 0f;
            npc.width = 60;
            npc.height = 30;
            animationType = NPCID.BoundGoblin;
            Main.npcFrameCount[npc.type] = 2; 
            npc.value = Item.buyPrice(0, 0, 10, 0);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath17;
            npc.buffImmune[24] = false;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "KahanMod/NPCs/Bosses/Yama_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion;
             if (Main.expertMode)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YamaTreasureBag"));
            }
            else
          {                         
            int choice = Main.rand.Next(3);
            if (choice == 0)
            {
                  Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YoyoMold"));
            }
            if (choice == 1)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FlailMold"));
            }
            if (choice == 2)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KatanaMold"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RedFragment"), Main.rand.Next(5, 10));
          }
     
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale);
            npc.damage = (int)(npc.damage * 0.6f);
        }
        public override void AI()
        {
         Player player = Main.player[npc.target];
         Vector2 moveTo = player.Center + new Vector2(0f, -200f);
         float speed = 5f;
         Vector2 move = moveTo - npc.Center;
         float magnitude = Math.Sqrt(move.X * move.X + move.Y * move.Y);            here is the error
         move *= speed / magnitude;
         npc.velocity = move;
        }
    }
}
Its translated in polish so i wont translate it perfectly
Cs0266: can not implicitly convert type #double# to #float# . There exist conversion explicit (whether not missing throw?)
 
I now that Im asking a lot of things but its the last time
Code:
 if (npc.ai[0] % 600 == 3)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("TorturedSoul"));  //NPC name
            }
            npc.ai[1] += 0;
        }
Boss doesnt spawn npcs
 
I now that Im asking a lot of things but its the last time
Code:
 if (npc.ai[0] % 600 == 3)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("TorturedSoul"));  //NPC name
            }
            npc.ai[1] += 0;
        }
Boss doesnt spawn npcs
I would like to have the whole code, because it seems like you are just adding things at random.
 
I would like to have the whole code, because it seems like you are just adding things at random.
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace KahanMod.NPCs.Bosses
{
    public class Yama : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Yama";
            npc.displayName = "Yama";
            npc.aiStyle = 0; 
            npc.lifeMax = 9000;  
            npc.damage = 40; 
            npc.defense = 25;  
            npc.knockBackResist = 0f;
            npc.width = 60;
            npc.height = 30;
            animationType = NPCID.BoundGoblin; 
            Main.npcFrameCount[npc.type] = 2;   
            npc.value = Item.buyPrice(0, 0, 10, 0);
            npc.npcSlots = 1f;
            npc.boss = true; 
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath17;
            npc.buffImmune[24] = false;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "KahanMod/NPCs/Bosses/Yama_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion;  
             if (Main.expertMode)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YamaTreasureBag"));
            }
            else
          {                           
            int choice = Main.rand.Next(3);
            if (choice == 0)
            {
                  Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YoyoMold"));
            }
            if (choice == 1)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FlailMold"));
            }
            if (choice == 2)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KatanaMold"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RedFragment"), Main.rand.Next(5, 10));
          }
       
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); 
            npc.damage = (int)(npc.damage * 0.6f); 
        }
        public override void AI()
        {
         Player player = Main.player[npc.target];
         Vector2 moveTo = player.Center + new Vector2(0f, -200f);
         float speed = 3f;
         Vector2 move = moveTo - npc.Center;
         float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
         move *= speed / magnitude;
         npc.velocity = move;
       
         if (npc.ai[0] % 600 == 3)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("TorturedSoul")); 
            }
            npc.ai[1] += 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 KahanMod.NPCs.Bosses
{
    public class Yama : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Yama";
            npc.displayName = "Yama";
            npc.aiStyle = 0;
            npc.lifeMax = 9000; 
            npc.damage = 40;
            npc.defense = 25; 
            npc.knockBackResist = 0f;
            npc.width = 60;
            npc.height = 30;
            animationType = NPCID.BoundGoblin;
            Main.npcFrameCount[npc.type] = 2;  
            npc.value = Item.buyPrice(0, 0, 10, 0);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath17;
            npc.buffImmune[24] = false;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "KahanMod/NPCs/Bosses/Yama_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion; 
             if (Main.expertMode)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YamaTreasureBag"));
            }
            else
          {                          
            int choice = Main.rand.Next(3);
            if (choice == 0)
            {
                  Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YoyoMold"));
            }
            if (choice == 1)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FlailMold"));
            }
            if (choice == 2)
            {
                 Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KatanaMold"));
            }
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RedFragment"), Main.rand.Next(5, 10));
          }
      
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale);
            npc.damage = (int)(npc.damage * 0.6f);
        }
        public override void AI()
        {
         Player player = Main.player[npc.target];
         Vector2 moveTo = player.Center + new Vector2(0f, -200f);
         float speed = 3f;
         Vector2 move = moveTo - npc.Center;
         float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
         move *= speed / magnitude;
         npc.velocity = move;
      
         if (npc.ai[0] % 600 == 3)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("TorturedSoul"));
            }
            npc.ai[1] += 0;
        }
    }
}
Ok, so basically, what you are doing is trying to spawn an NPC when the counter divided by 600 gets a remainder of 3. The only problem is that you never set up the counter at all, meaning you can just add "npc.ai[0] += 1" anywhere inside the AI. Instead of checking if the remainder is 3, just switch the 3 to 0. You can remove the "npc.ai[1] += 0" since you never use that counter.
 
Back
Top Bottom