Jump to content

Making enemies drop some items on kill


dezgasting

Recommended Posts

I'm so close to adding all main mechanics to my character, the only thing I need to add but don't know how to do that, is how do I make enemies drop additional items (FYI that already exist in the game) after they're killed? Basically I want them to drop dubloons (2 on regular, 10 for bosses etc) (and oinks if Hamlet is enabled, if its possible. could also add another "money" item, maybe i'll even do but that doesn't matter rn) once slain. I can't even start figuring it out and I don't know on what mod's code to look on, nothing comes to mind. Pls help and thank you.

 

 

Oh, and while I'm at it, how do I remove all the downsides of moisture (sanity penalty and (maybe) slippery tools)? 

Link to comment
Share on other sites

Changing what loot drops from certain mobs/entities is a subjective matter, as the lootdropper-component can be set up in various ways. Some entities have random drops, some have weighted drops, some have static drops, some have state-based drops etc.. Look at the lootdropper-component. Read the code there. Go to the prefab you want to change, and see how it sets up its lootdropper-component.

An alternative route, is to instead simply listen to the event "killed" on your character, because anything you kill that has a combat component on will push this event, with its data parameter containing data.victim, so you can manually drop things using the entity's own lootdropper component like this. If you want to know more, study the lootdropper component and how it is used in the game code.

Make Mobs Drop Certain Extra Loot Only When My Character Kills Them

inst:ListenForEvent("killed", function(inst, data)
	local victim = data.victim
	if not victim then
		return
	end
	
	if not victim.components.lootdropper then
		victim:AddComponent("lootdropper")
	end

	local lootdropper = victim.components.lootdropper
	
	if lootdropper then
		local victimpos = victim:GetPosition()
		lootdropper:SpawnLootPrefab("SOME_ITEM_PREFAB_NAME", victimpos)
		lootdropper:SpawnLootPrefab("SOME_OTHER_ITEM_PREFAB_NAME", victimpos)
	end
end)

You can then expand the code to give different drops depending on the prefab name of the victim or the components they have or whatever you want. Now, this only works for victims with a combat component on it. Prey like rabbits and birds do not have a combat component, so you'll have to do something different for those. Let me know if you want that.

This post shows how you can remove slipperiness entirely from your character. Note that this approach ONLY works in DS and not DST.

Removing the sanity loss from rain is difficult, but if you want to remove all these wetness things anyway, why not just make your character entirely unwettable?

inst.component.moisture.maxMoistureRate = 0
inst.component.moisture.baseDryingRate = 100

The first line should do it, but in case you can get wet from other things, setting the base drying rate to a ridiculous amount will take care of it.

 

Link to comment
Share on other sites

On 17.09.2019 at 8:44 PM, Ultroman said:

Changing what loot drops from certain mobs/entities is a subjective matter, as the lootdropper-component can be set up in various ways. Some entities have random drops, some have weighted drops, some have static drops, some have state-based drops etc.. Look at the lootdropper-component. Read the code there. Go to the prefab you want to change, and see how it sets up its lootdropper-component.

An alternative route, is to instead simply listen to the event "killed" on your character, because anything you kill that has a combat component on will push this event, with its data parameter containing data.victim, so you can manually drop things using the entity's own lootdropper component like this. If you want to know more, study the lootdropper component and how it is used in the game code.

Make Mobs Drop Certain Extra Loot Only When My Character Kills Them


inst:ListenForEvent("killed", function(inst, data)
	local victim = data.victim
	if not victim then
		return
	end
	
	if not victim.components.lootdropper then
		victim:AddComponent("lootdropper")
	end

	local lootdropper = victim.components.lootdropper
	
	if lootdropper then
		local victimpos = victim:GetPosition()
		lootdropper:SpawnLootPrefab("SOME_ITEM_PREFAB_NAME", victimpos)
		lootdropper:SpawnLootPrefab("SOME_OTHER_ITEM_PREFAB_NAME", victimpos)
	end
end)

You can then expand the code to give different drops depending on the prefab name of the victim or the components they have or whatever you want. Now, this only works for victims with a combat component on it. Prey like rabbits and birds do not have a combat component, so you'll have to do something different for those. Let me know if you want that.

This post shows how you can remove slipperiness entirely from your character. Note that this approach ONLY works in DS and not DST.

Thanks yet again, mah dude. 

Quote

Removing the sanity loss from rain is difficult, but if you want to remove all these wetness things anyway, why not just make your character entirely unwettable?


inst.component.moisture.maxMoistureRate = 0
inst.component.moisture.baseDryingRate = 100

The first line should do it, but in case you can get wet from other things, setting the base drying rate to a ridiculous amount will take care of it.

The reason why I don't make him completely unwettable is because he gets bonuses when reaching certain moisture levels (really just stat bonuses), which I already implemented. I just needed to remove the sanity penalty. 

 

Btw character still loses sanity when holding a wet tools/weapon/whatever. How do I remove this?

Link to comment
Share on other sites

6 hours ago, htv1lla1n said:

Btw character still loses sanity when holding a wet tools/weapon/whatever. How do I remove this?

Yes. That's because the equipped items are calculated in another place. Extend the function GetEquippedMoistureRate(slot) on your character's inventory component, and change it to just return 0.

Link to comment
Share on other sites

17 hours ago, Ultroman said:

Yes. That's because the equipped items are calculated in another place. Extend the function GetEquippedMoistureRate(slot) on your character's inventory component, and change it to just return 0.

in english for dummies, please

because i, sir, am a dummy

Link to comment
Share on other sites

On 20.09.2019 at 11:28 PM, Ultroman said:

In your character's Lua file, at the bottom of the master_postinit function, put this in:


inst.components.inventory.GetEquippedMoistureRate = function(self, slot, ...)
	return 0
end

 

It's probably different in Shipwrecked, because it doesn't seem to work for me. Character still loses sanity when holding a wet tool. 

Link to comment
Share on other sites

You're right. It's because of this piece of code in the ReCalc function:

for k,v in pairs (self.inst.components.inventory.equipslots) do
	if v.components.equippable then
		empty_slots = empty_slots - 1
		total_dapperness = total_dapperness + v.components.equippable:GetDapperness(self.inst)
	end		
end

That one is a bit more difficult to get at, because you literally have to edit every single equippable item to get it to work. You can do something drastic like this, but it'll make it so whenever Klei updates this function, your character might break. Put this in your modmain.lua

AddComponentPostInit("equippable", function(comp)
	local oldGetDapperness = comp.GetDapperness
	comp.GetDapperness = function(self, owner, ...)
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" then
		    local dapperness = self.dapperness
		    
		    if self.dapperfn then
		        dapperness = self.dapperfn(self.inst, owner)
		    end
			return dapperness
		else
			return oldGetDapperness(self, owner, ...)
		end
	end)
end)

 

Link to comment
Share on other sites

1 hour ago, Ultroman said:

You're right. It's because of this piece of code in the ReCalc function:


for k,v in pairs (self.inst.components.inventory.equipslots) do
	if v.components.equippable then
		empty_slots = empty_slots - 1
		total_dapperness = total_dapperness + v.components.equippable:GetDapperness(self.inst)
	end		
end

That one is a bit more difficult to get at, because you literally have to edit every single equippable item to get it to work. You can do something drastic like this, but it'll make it so whenever Klei updates this function, your character might break. Put this in your modmain.lua


AddComponentPostInit("equippable", function(comp)
	local oldGetDapperness = comp.GetDapperness
	comp.GetDapperness = function(self, owner, ...)
		if owner.prefab == "YOUR_CHARACTER_PREFAB_NAME" then
		    local dapperness = self.dapperness
		    
		    if self.dapperfn then
		        dapperness = self.dapperfn(self.inst, owner)
		    end
			return dapperness
		else
			return oldGetDapperness(self, owner, ...)
		end
	end)
end)

 

Didn't expect this to get real complicated.
Anyways, even that doesn't seem to work, nothing changes.

Even then I don't like putting in something that has a high chance to break, feel like I should drop the idea of removing sanity penalty from wet tools altogether.
Not like it's a big deal tho -- that's just a neat addition after all. 

Thanks for trying to help, you're making my dreams come true <3

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...