More drops

How do I make NPCs, modded and vanilla (primarily vanilla), drop modded items?
In a GlobalNPC, use the NPCLoot hook and check npc.type against the NPCID of the npc you want to add a drop to: https://github.com/bluemagic123/tModLoader/blob/master/ExampleMod/NPCs/ExampleGlobalNPC.cs#L66

If it is a ModNPC, you don't need to check against npc.type since the code is only executing for your npc.

For the ItemID, use the ItemID.??? for vanilla (check the wiki or autocomplete with Visual Studio) and mod.ItemType("?????") for modItems.
 
In a GlobalNPC, use the NPCLoot hook and check npc.type against the NPCID of the npc you want to add a drop to: https://github.com/bluemagic123/tModLoader/blob/master/ExampleMod/NPCs/ExampleGlobalNPC.cs#L66

If it is a ModNPC, you don't need to check against npc.type since the code is only executing for your npc.

For the ItemID, use the ItemID.??? for vanilla (check the wiki or autocomplete with Visual Studio) and mod.ItemType("?????") for modItems.
Awesome! Thanks.
 
Ok, I came across a bit of a problem:

ANewBeginning.cs(22,83) : error CS0103: The name 'mod' does not exist in the current context

referencing this line of code:

Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("MasamuneBlade"), Main.rand.Next(1, 19));

I've cross-referenced it to what you linked, and the code looks the same (except item, of course). I'm not sure why it's saying this.
 
Ok, I came across a bit of a problem:

ANewBeginning.cs(22,83) : error CS0103: The name 'mod' does not exist in the current context

referencing this line of code:

Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("MasamuneBlade"), Main.rand.Next(1, 19));

I've cross-referenced it to what you linked, and the code looks the same (except item, of course). I'm not sure why it's saying this.
mod is a member variable of ModNPC and GlobalNPC, so they should be there unless you forgot to extend those classes.
 
mod is a member variable of ModNPC and GlobalNPC, so they should be there unless you forgot to extend those classes.
... oh. I did. Accidentally skipped that part. Sorry for bothering you about it, I'm still very new to C#.
 
Back
Top Bottom