tModLoader How to make Vanilla NPC's drop a modded item?

DexavioR

Terrarian
I want to make my Weapon called "WaterKnife" drop with a 10% chance from HM Ocean enemies (jellyfish, sharks, crabs).
Does anyone know how I could do that easily?
Thanks.

And also, if anybody could tell me how to make my throwing weapon act like a boomerang (spin, go out, and retract) that would be great too.
 
Last edited:
I want to make my Weapon called "WaterKnife" drop with a 10% chance from HM Ocean enemies (jellyfish, sharks, crabs).
Does anyone know how I could do that easily?
Thanks.

And also, if anybody could tell me how to make my throwing weapon act like a boomerang (spin, go out, and retract) that would be great too.
For the first thing, check out example global NPC. There you will find an example of dropping mod items from vanilla NPC.

The boomerang thing you might want to study or use the vanilla boomerang ai or code.
 
I want to make my Weapon called "WaterKnife" drop with a 10% chance from HM Ocean enemies (jellyfish, sharks, crabs).
Does anyone know how I could do that easily?
Thanks.

And also, if anybody could tell me how to make my throwing weapon act like a boomerang (spin, go out, and retract) that would be great too.

These code should work for your Item that wil be Dropped

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

namespace YOURMODNAMEHERE
{
    public class ModGlobalNPC : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (Main.rand.Next(10) == 0)
            {
                if (npc.type == NPCID.PinkJellyfish)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
                }
                if (npc.type == NPCID.Shark)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
                }
                if (npc.type == NPCID.Crab)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
                }
            }
        }
    }
}
 
Don't understand really. I put that in the main folder in a "ModGlobalNPC.cs" file, but it gives me this:

c:\Users\Rocket\Documents\My Games\Terraria\ModLoader\Mod Sources\TacticalMod\Items\Tactite.cs(26,32) : error CS0246: The type or namespace name 'NPC' could not be found (are you missing a using directive or an assembly reference?)
 
Don't understand really. I put that in the main folder in a "ModGlobalNPC.cs" file, but it gives me this:

c:\Users\Rocket\Documents\My Games\Terraria\ModLoader\Mod Sources\TacticalMod\Items\Tactite.cs(26,32) : error CS0246: The type or namespace name 'NPC' could not be found (are you missing a using directive or an assembly reference?)
Did you change the Namespace to your mods Namespace?
 
For the text you gave me:

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

namespace TacticalMod.NPCs
{
public class ModGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if (Main.rand.Next(10) == 0)
{
if (npc.type == NPCID.PinkJellyfish)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
if (npc.type == NPCID.Shark)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
if (npc.type == NPCID.Crab)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
}
}
}
}
 
For the text you gave me:

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

namespace TacticalMod.NPCs
{
public class ModGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if (Main.rand.Next(10) == 0)
{
if (npc.type == NPCID.PinkJellyfish)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
if (npc.type == NPCID.Shark)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
if (npc.type == NPCID.Crab)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WaterKnife"));
}
}
}
}
}

YOur jsut dont copy the using part with in,compare your codes top with the one i posted above and you see whats missing
 
Can someone help me to make that my custom tressure bag/box drops vanilla items thanks if you could help
[doublepost=1500698485,1500698426][/doublepost]this is what i've been trying to do
player.QuickSpawnItem = GlobalItem
can someone extend or help me out to make this work or something thanks
 
I'm getting an identifier expected when I changed all "NPC"'s to "Npc" and the NPC in the public override to npc and got rid of the second one. Help please?
 
how do i make 2 separate enemies have different drop rates for items? help?
public override void NPCLoot(NPC npc)
{
if (npc.type == NPCID.EyeofCthulhu)
{
if (Main.rand.Next(2) == 0) { // 1 in 2 chance
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("CthuluRing"));
}
} else if (npc.type == NPCID.Zombie) {
if (Main.rand.Next(5) == 0) { //1 in 5 chance
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("BasicSword"));
}
}

}

Notice how I put The rand if() inside of the npc.type if()? That's how you do it. :gslime:
 
Back
Top Bottom