InfectedDash Posted October 7, 2017 Share Posted October 7, 2017 (edited) Hey, I really enjoy playing Don't Starve Together but I just can't seem to find a modded character that I like. So, I've decided to create one, with absolutely no coding knowledge (what could go wrong?). Unsurprisingly, I failed. So I've came here to ask for help: Is it possible to give a character 25% chance to receive double items when harvesting (twigs, farms, grass, flowers, things like that)? If so, how? Oh and, I forgot to mention. Since I have no coding experience, I'm editing the code of Devon the Hunter for DST (if that changes anything). Edited October 7, 2017 by InfectedDash Link to comment Share on other sites More sharing options...
ptr Posted October 7, 2017 Share Posted October 7, 2017 (edited) local G = GLOBAL --your character prefab local CHARACTER = "wilson" local CHANCE = 0.25 AddPrefabPostInitAny(function(prefab) if not G.TheWorld.ismastersim or not prefab.components.pickable then return end local oldpick=prefab.components.pickable.onpickedfn prefab.components.pickable.onpickedfn=function(inst, picker, loot) if loot and picker.prefab==CHARACTER and math.random()<CHANCE then local newloot=G.SpawnPrefab(loot.prefab) if newloot then if newloot.components.inventoryitem then newloot.components.inventoryitem:InheritMoisture(G.TheWorld.state.wetness, G.TheWorld.state.iswet) end if loot.components.stackable and loot.components.stackable.stacksize>1 then newloot.components.stackable:SetStackSize(math.random(loot.components.stackable.stacksize)) end picker.components.inventory:GiveItem(newloot, nil, inst:GetPosition()) end end if oldpick then oldpick(inst, picker, loot) end end end) AddComponentPostInit("crop",function(cmp,prefab) if not G.TheWorld.ismastersim then return end local OldHarvest=cmp.Harvest cmp.Harvest=function(self, harvester) local pos=self.inst:GetPosition() local _,product=OldHarvest(self, harvester) if product and harvester and harvester.prefab==CHARACTER and math.random()<CHANCE then local newproduct=G.SpawnPrefab(product.prefab) if newproduct then if newproduct.components.inventoryitem then newproduct.components.inventoryitem:InheritMoisture(G.TheWorld.state.wetness, G.TheWorld.state.iswet) end harvester.components.inventory:GiveItem(newproduct, nil, pos) end end return true, product end end) place the code into modmain Edited October 7, 2017 by ptr Link to comment Share on other sites More sharing options...
InfectedDash Posted October 7, 2017 Author Share Posted October 7, 2017 Thank you SO MUCH! Worked wonderfully! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now