Custom NPC Spawning After a Boss has Been Defeated

llangdxn

Terrarian
I'm currently making some custom town NPCs and I want to make it so my NPCs spawn after the Celestial Pillars + Moon Lord have been defeated.
I've looked at several tutorials on YouTube, looked at several posts on these forums, and even gone through the tModLoader Docs website and can't find anything that explains the code for how to get your custom town NPC to spawn after a boss has been defeated. Most tutorials only talk about having an item in inventory requirement.
Does anybody know the code for this? I've been looking for ages! :(
 
In a ModSystem class, create your own bool to track if your boss is dead. When it dies, set it to true.
Then check if it's true for the spawn condition of your NPC.
 
In a ModSystem class, create your own bool to track if your boss is dead. When it dies, set it to true.
Then check if it's true for the spawn condition of your NPC.
Thanks! :)

Here's the code if anyone else is struggling with this:

C#:
    public override bool CanTownNPCSpawn(int numTownNPCs)
{
    if (NPC.downedMoonlord) // Change "Moonlord" to whichever boss you desire 
    {
        return true;
    }
    return false;
}
 
Back
Top Bottom