how to make an npc considered a boss

TWillyH

Terrarian
im trying to make a boss and i wrote NPC.boss = true, but its in some sort of limbo boss but not state; it has spawn and death messages, drops lesser healing potions without me adding them to the loot pool manually, and plays the boss 1 music. but it doesnt show up on the map, despawn off screen, show the hp bar, or show up in the boss checklist mod i have downloaded. im guessing the reason it doesnt consider the npc a boss is either because i took some downed boss system from example mod, or because i have the code for dropping the treasure bag and master mode relic commented out as i havent made them yet.
 
Put [AutoloadBossHead] at the top of your file, above your class name to get it show up on the Minimap.

For adding it to boss checklist you have to do that manually, yourself. The bosschecklist github should show you how.
 
autoloadbosshead is there, but its inside the namespace. should i move it above?
 

Attachments

  • Screenshot 2024-04-28 at 3.22.49 PM.png
    Screenshot 2024-04-28 at 3.22.49 PM.png
    31.8 KB · Views: 16
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.Bestiary;
using Terraria.GameContent.ItemDropRules;
using Terraria.Graphics.CameraModifiers;
using Terraria.ID;
using Terraria.ModLoader;

namespace mymodname.NPCs
{

[AutoloadBossHead]
public class bossname : ModNPC
{
public override void SetStaticDefaults()
{
Main.npcFrameCount[Type] = 2;

NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0)
{
Velocity = 1f
};
NPCID.Sets.NPCBestiaryDrawOffset.Add(Type, value);
NPCID.Sets.SpecificDebuffImmunity[Type][BuffID.Confused] = true;
}

public override void SetDefaults()
{
NPC.width = 123;
NPC.height = 159;
NPC.damage = 20;
NPC.defense = 10;
NPC.lifeMax = 6969;
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
NPC.value = 420f;
NPC.knockBackResist = 0f;
NPC.aiStyle = 26;
NPC.boss = true;
NPC.npcSlots = 10f;
}

public override void FindFrame(int frameHeight)
{
int startFrame = 0;
int finalFrame = 1;

int frameSpeed = 2;
NPC.frameCounter += 0.5f;
NPC.frameCounter += NPC.velocity.Length() / 10f;
if (NPC.frameCounter > frameSpeed)
{
NPC.frameCounter = 0;
NPC.frame.Y += frameHeight;

if (NPC.frame.Y > finalFrame * frameHeight)
{
NPC.frame.Y = startFrame * frameHeight;
}
}
}

public override void BossLoot(ref string name, ref int potionType)
{

}

public override void ModifyNPCLoot(NPCLoot npcLoot)
{

//npcLoot.Add(ItemDropRule.BossBag(ModContent.ItemType<bossbag>()));

npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Items.bosstrophy>(), 10));

//npcLoot.Add(ItemDropRule.MasterModeCommonDrop(ModContent.ItemType<Items.bossrelic>()));

npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Item>(), 1, 4, 9));
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Item>(), 3));
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<item>(), 5));
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Item>(), 4));

npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Items.Wearable.bossmask>(), 7));
}

public override void AI()
{
// This should almost always be the first code in AI() as it is responsible for finding the proper player target
if (NPC.target < 0 || NPC.target == 255 || Main.player[NPC.target].dead || !Main.player[NPC.target].active)
{
NPC.TargetClosest();
}

Player player = Main.player[NPC.target];

if (player.dead)
{
// If the targeted player is dead, flee
NPC.velocity.Y -= 0.04f;
// This method makes it so when the boss is in "despawn range" (outside of the screen), it despawns in 10 ticks
NPC.EncourageDespawn(10);
return;
}
}

public override void OnKill()
{
NPC.SetEventFlagCleared(ref DownedBossSystem.downedBossname, -1);
}


public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
{
new MoonLordPortraitBackgroundProviderBestiaryInfoElement(),
new FlavorTextBestiaryInfoElement("entry"),

});
}
}
}
 
i replaced a bunch of the mod specific words with generic placeholders like "item" please tell me if that prevents you from finding the problem
 
If you are setting NPC.boss and autoloadbosshead, that should be enough for the boss to show on the minimap, and all the other boss related defaults. Are you saving your code and rebuilding your mod?
 
yes, i always save and hit build and reload. its possible that the enemy IS a boss, but the boss head file isnt valid because it was a screenshot since the site i used only allowed a limited amount of saves for guests. im about to try it again with a better file.
 
i checked, the game DOES thin the npcs a boss, the map icon and hp bar just dont show up. i just checked and my npc appears in the boss enemy section of the bestiary.
 
its possible the boss isnt behaving because the ai is coded to act like a unicorn (ai style 26), but if i set the ai to -1, what would i write to make it act like a unicorn? (and tp like king slime if the boss gets stuck)
 
Back
Top Bottom