Jump to content

All enemies have additional drop


Recommended Posts

So i'm trying to make it so when my character kills any creature, the creature drops the item. Sort of like adding one more additional item into its drop table

I believe some mods do this but most of them are in Chinese and their mod layout is very different from the standard one.

If there's a mod out there that does this in the workshop, can you redirect me to it? Thanks

Link to comment
Share on other sites

There are a few ways to go about it. One, where the item can drop from lootdroppers no matter how they die, involves altering the GenerateLoot() function of the lootdropper component on all monsters, by doing an AddComponentPostInit. You make a copy of the old function, then in your new function your run the old function, and save the result from it, which is a list of prefabs, and then you add something to that list. What you need to be careful about, is only applying the change to the appropriate things. So for example, checking that they have the tag "monster" on them, but they don't all have that tag, so you need to go through their prefabs to make sure you "hit" all the prefabs you want to change. For example, Pigman is not considered a monster.

That's probably the most all-round way to do it.

If you only want the extra loot to drop when your character deals the killing blow to the monster, you can instead listen for the event "onhitother" on your character inst, which is called by GetAttacked() in the combat-component, since it gives you the target in its data (which you can check for whether it's dead), and the inst in the function you give it, will be your character. There's an example in deerclops.lua. It doesn't make use of the inst variable (your character), but it's there for you to use. If you find that the item still drops even when your character isn't dealing the killing blow, you can add an extra check for whether the inst.prefab has your character prefab's name.

Those are the two ways I can think of off the top of my head.

Link to comment
Share on other sites

Btw, in the second version, obviously you'd have to manually spawn the item (possibly with a random factor so it doesn't always drop), and "fling"/throw it, so it "jumps" a bit like the other loot. You can find the code to spawn a prefab (SpawnPrefab()) and "fling" an item in the lootdropper-component.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...