tModLoader Getting ID for variant NPCs

Aitherix

Terrarian
I'm referring to https://terraria.wiki.gg/NPC_IDs and everything above the blue slime as I'm making a progressive difficulty mod so enemies get stronger over time as you kill the same type.

I'm using GlobalNPC and SetDefaults to change the enemy stats on spawn and update values on CheckDead but for some reason whenever any of the NPCs spawn with a negative ID it returns as a 0 or 1 rather than the id specified in the list. This is what I'm pretty much using:

Code:
using Terraria;
using Terraria.ModLoader;

namespace ProgessiveDiff
{
    internal class ProgessiveDiff : GlobalNPC
    {
        public override bool InstancePerEntity => true;

        public override void SetDefaults(NPC npc)
        {
            // Using name for those segmented enemies
            string findName = NPC.GetFirstNPCNameOrNull(npc.type);

            // Find NPC
            if (findName != null && findName.Length > 0 && NPCListing.killCountNPC.ContainsKey(findName))
            {
                int value = 0;
                // Get KC and add to NPC HP.
                NPCListing.killCountNPC.TryGetValue(findName, out value);
                npc.lifeMax += value;
                }
            }
        }

        public override bool CheckDead(NPC npc)
        {
            // Add NPC to list
            NPCListing.KillCountNPC(npc.TypeName, 1);
            return base.CheckDead(npc);
        }
    }
}

And seems to work fine on pretty much any NPC except the negative ones since it doesn't want to load the name and id. I'm not fond of c# so my formatting isn't exactly the best. Right now I'm storing the name and kill count to a dictionary which is saved to a config file.
 
Last edited:
Using npc.netID instead of npc.type works with negative ID npcs. Negative ID npcs are variants. For instance, you can use
if (npc.netID == NPCID.GreenSlime)
{
// Code that applies to green slimes.
}
 
Back
Top Bottom