tModLoader New Mod Idea - banner drops being random again

breadbin

Terrarian
I prefer the way Terraria used to handle banners in that there was a random chance of a drop of a banner when you killed an enemy. I think it was 1.3 when they patched that to set the banners to drop every 50th kill. Would it be possible to make this happen? I'd love to have a go at it myself but I have limited programming experience and no modding experience. Could anyone point me in the right direction or where to start? Does it seem like something that would be easy or difficult to accomplish?
 
Sure, this seems simple enough. :) Other than the general tModLoader tutorial stuff, here are some pointers on how you could do this.

To make vanilla NPCs drop items, you're gonna need to create a class extending GlobalNPC, and override NPCLoot(). (tModLoader/tModLoader) You can use Item.NPCtoBanner() and Item.BannerToItem() to find the ItemID of the banner for the particular NPC. Then you just need to do a random number check, and drop the banner item using Item.NewItem().

Stopping the banner from dropping after every 50th kill is a bit trickier. If you look at lines 34-104 of Terraria.NPC.NPCLoot() (as decompiled by the latest version of dnSpy), you'll see the code that makes this happen. To stop this bit of code from running entirely, you have a couple of options.
You could set NPCID.Sets.ExcludedFromDeathTally to true for every enemy. This is not ideal though, as it would completely break the tally counter as well.
You could alternatively mess with ItemID.Sets.KillsToBanner. This determines how many kills it takes for a particular banner item to make it drop. You could effectively make the banners impossible to obtain this way, by setting this value to something ridiculous (like int.MaxValue) for every item.
Or, you could try to do it with IL injection, but that is kinda complicated, so it's best to avoid it if possible.
 
Back
Top Bottom