tModLoader How to change an existing NPC's drops

huntermangus70

Terrarian
Hi I'm new if you couldn't tell by the question. I'm wondering how to add a drop to an npc already in Terraria. Any help is appreciated.
 
Make a file named 'ModGlobalNPC' and put this in it:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace <modname>
{
    public class ModGlobalNPC : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            //The if (Main.rand.Next(x) == 0) determines how rare the drop is. To find the percent of a drop, divide 100 by your desired percent, minus the percent sign. Ex: A 2% chance would be 100% / 2%, or 50. This is what you put in place of x.

            if (Main.rand.Next(50) == 0) //2% chance
            {
                if (<npc.type(<npcname>)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, <If using a Vanilla item, ItemID.<itemid>. If using a modded item, mod.ItemType("mod item id")>);
                }
            }
        }
    }
}
Anything with // infront of it is a comment, anything with <> around it is something to replace.
Edit: Changed key because code doesn't show color.
 
if (<npc.type(<npcname>)

Actually this line doesn't doesn't make sense could you make a working example of this one line... (I can't get it to work because I'm not really understanding what you want me to put in place of the <> statements)



P.S. the parenthesis () are not balanced in it either.
 
Actually this line doesn't doesn't make sense could you make a working example of this one line... (I can't get it to work because I'm not really understanding what you want me to put in place of the <> statements)



P.S. the parenthesis () are not balanced in it either.
Code:
if (npc.type == NPCID.BlackRecluse)
I messed up on the main post, sorry.
 
Hi i am making an npc that drops loot i have done everything correctly but i still get an error
It says the name mod does not exist in the current context

Code:
using Terraria.ModLoader;
using Terraria;
using Terraria.ID;
using Microsoft.Xna.Framework;

namespace AOT.Ememies
{
public class CollosalTitan : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("CollosalTitan");
Main.npcFrameCount[NPC.type] = Main.npcFrameCount[2];
}

public override void SetDefaults()
{
NPC.width = 100;
NPC.height = 100;
NPC.damage = 76;
NPC.defense = 5;
NPC.lifeMax = 250;
NPC.value = 50000f;
NPC.aiStyle = 1;
NPC.HitSound = SoundID.NPCHit2;
NPC.DeathSound = SoundID.NPCDeath2;
AIType = NPCID.Zombie;
AnimationType = NPCID.Zombie;
}

public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
return spawnInfo.Player.ZoneOverworldHeight && NPC.downedBoss1 ? 0.1f : 0.2f;
}

public override void FindFrame(int frameHeight)
{
NPC.frameCounter++;
if(NPC.frameCounter >= 20)
{
NPC.frameCounter = 0;
}
NPC.frame.Y = (int)NPC.frameCounter / 10 * frameHeight;
}

public override void ModifyNPCLoot(NPCLoot npcLoot)
{
Item.NewItem((int)NPC.position.X, (int)NPC.position.Y,NPC.width, NPC.height,mod.ItemType("TitanBlade"), 1);
}
}
}
 
Back
Top Bottom