dezgasting Posted September 14, 2019 Share Posted September 14, 2019 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 More sharing options...
Ultroman Posted September 17, 2019 Share Posted September 17, 2019 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 More sharing options...
dezgasting Posted September 19, 2019 Author Share Posted September 19, 2019 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 More sharing options...
Ultroman Posted September 19, 2019 Share Posted September 19, 2019 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 More sharing options...
dezgasting Posted September 20, 2019 Author Share Posted September 20, 2019 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 More sharing options...
Ultroman Posted September 20, 2019 Share Posted September 20, 2019 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 Link to comment Share on other sites More sharing options...
dezgasting Posted September 27, 2019 Author Share Posted September 27, 2019 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 More sharing options...
Ultroman Posted September 28, 2019 Share Posted September 28, 2019 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 More sharing options...
dezgasting Posted September 28, 2019 Author Share Posted September 28, 2019 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 More sharing options...
Ultroman Posted September 29, 2019 Share Posted September 29, 2019 Did you change YOUR_CHARACTER_PREFAB_NAME to your character's prefab name? Just checking ^^ That really should work. Link to comment Share on other sites More sharing options...
dezgasting Posted September 29, 2019 Author Share Posted September 29, 2019 4 hours ago, Ultroman said: Did you change YOUR_CHARACTER_PREFAB_NAME to your character's prefab name? Just checking ^^ That really should work. Yep, I did. It's in caps, too. Link to comment Share on other sites More sharing options...
Ultroman Posted October 1, 2019 Share Posted October 1, 2019 It should not be in caps. Prefab names are all lower-case. The CAPS was to make sure you'd notice Link to comment Share on other sites More sharing options...
Recommended Posts
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.