Hallam_9K
Empress of Light
Well, there is an error:Then you'll probably want to override this method to check whether or not the head is dead/inactive:
That should work. No other way to know than to test it out!Code:public override bool CheckActive() { if(Main.npc[npc.ai[3]].active) return false; return true; }
c:\Users\Hallam\Documents\My Games\Terraria\ModLoader\Mod Sources\ModOfRandomness\NPCs\VlitchWormTail.cs(96,26) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
This is the new code:
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModOfRandomness.NPCs
{
public class VlitchWormTail : ModNPC
{
public override void SetDefaults()
{
npc.displayName = "Vlitch Gigipede";
npc.name = "Vlitch Gigipede";
npc.width = 64; //this is where you put the npc sprite width. important
npc.height = 104; //this is where you put the npc sprite height. important
npc.damage = 180;
npc.defense = 250;
npc.lifeMax = 1;
npc.knockBackResist = 0.0f;
npc.behindTiles = true;
npc.noTileCollide = true;
npc.netAlways = true;
npc.noGravity = true;
npc.dontCountMe = true;
npc.HitSound = SoundID.NPCHit4;
}
public override void AI()
{
if (npc.ai[0]++ >= 200)
{
// Spawn NPC!
NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("CorruptedWormHead"));
npc.ai[0] = 0;
}
{
if (npc.ai[3] > 0)
npc.realLife = (int)npc.ai[3];
if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
npc.TargetClosest(true);
if (Main.player[npc.target].dead && npc.timeLeft > 300)
npc.timeLeft = 300;
if (Main.netMode != 1)
{
if (!Main.npc[(int)npc.ai[1]].active)
{
npc.life = 0;
npc.HitEffect(0, 10.0);
npc.active = false;
NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
}
}
{
if (Main.rand.Next(1) == 0)
{
int dust = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, mod.DustType("Flame"));
}
}
if (npc.ai[1] < (double)Main.npc.Length)
{
// We're getting the center of this NPC.
Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
// Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
// We then use Atan2 to get a correct rotation towards that parent NPC.
npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
// We also get the length of the direction vector.
float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
// We calculate a new, correct distance.
float dist = (length - (float)npc.width) / length;
float posX = dirX * dist;
float posY = dirY * dist;
// Reset the velocity of this NPC, because we don't want it to move on its own
npc.velocity = Vector2.Zero;
// And set this NPCs position accordingly to that of this NPCs parent NPC.
npc.position.X = npc.position.X + posX;
npc.position.Y = npc.position.Y + posY;
}
}
}
public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color drawColor)
{
Texture2D texture = Main.npcTexture[npc.type];
Vector2 origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f);
Main.spriteBatch.Draw(texture, npc.Center - Main.screenPosition, new Rectangle?(), drawColor, npc.rotation, origin, npc.scale, SpriteEffects.None, 0);
return false;
}
public override bool CheckActive()
{
if (Main.npc[npc.ai[3]].active) return false;
return true;
}
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
{
return false; //this make that the npc does not have a health bar
}
}
}