Jump to content

Recommended Posts

I'm creating a custom character who has unique crafting recipes that use diamonds. Is it possible to add a low-chance diamond drop to boulders that already exist in a game? Moon rocks, to be more specific.

I wasn't able to find a single tutorial on that matter. 

Long story short, i want moon rocks to drop my custom gem. Is that possible to implement? 

local LT = GLOBAL.LootTables

AddPrefabPostInit("rock_moon", function(inst)
	table.insert(LT["rock_moon"], {"diamond", 0.5})
end)

AddPrefabPostInit("rock_moon_shell", function(inst)
	table.insert(LT["rock_moon_shell"], {"diamond", 0.5})
end)

Where "diamond" is your diamond prefab and 0.5 is 50% drop chance.

Edited by Bumber64
58 minutes ago, Bumber64 said:

local LT = GLOBAL.LootTables

AddPrefabPostInit("rock_moon", function(inst)
	table.insert(LT["rock_moon"], {"diamond", 0.5})
end)

AddPrefabPostInit("rock_moon_shell", function(inst)
	table.insert(LT["rock_moon_shell"], {"diamond", 0.5})
end)

Where "diamond" is your diamond prefab and 0.5 is 50% drop chance.

Oh, it's actually not that complicated. Thank you so much, i think i'll be able to figure out the rest!

On 4/2/2022 at 12:44 AM, Bumber64 said:

local LT = GLOBAL.LootTables

AddPrefabPostInit("rock_moon", function(inst)
	table.insert(LT["rock_moon"], {"diamond", 0.5})
end)

AddPrefabPostInit("rock_moon_shell", function(inst)
	table.insert(LT["rock_moon_shell"], {"diamond", 0.5})
end)

Where "diamond" is your diamond prefab and 0.5 is 50% drop chance.

I'm working on adding coffee to my mod, and while I figure out how to add new bushes, could I recycle this for berry bushes & coffee? So I would replace rock_moon with the berry bush prefab, and diamond with the Coffee Bean prefab?

19 hours ago, ScrewdriverLad said:

I'm working on adding coffee to my mod, and while I figure out how to add new bushes, could I recycle this for berry bushes & coffee? So I would replace rock_moon with the berry bush prefab, and diamond with the Coffee Bean prefab?

Sure.

16 hours ago, ScrewdriverLad said:

And how would I then publish the mod? would I include the Berry bush prefab in the mod's folder, or should I do something else?

If you're reusing Klei's berry bush, you don't need to include the prefab. However, there's some additional work to be done since berry bushes use the "pickable" component instead of a loot table.

Something like this should work:

AddPrefabPostInit("berrybush", function(inst)
	inst.components.pickable.use_lootdropper_for_product = true
	inst.components.lootdropper:SetLoot({"berries"})
	inst.components.lootdropper:AddChanceLoot("coffee_bean", 0.5)
end)

AddPrefabPostInit("berrybush2", function(inst)
	inst.components.pickable.use_lootdropper_for_product = true
	inst.components.lootdropper:SetLoot({"berries"})
	inst.components.lootdropper:AddChanceLoot("coffee_bean", 0.5)
end)

AddPrefabPostInit("berrybush_juicy", function(inst)
	inst.components.pickable.use_lootdropper_for_product = true
	inst.components.lootdropper:SetLoot({"berries_juicy", "berries_juicy", "berries_juicy"})
	inst.components.lootdropper:AddChanceLoot("coffee_bean", 0.5)
end)

This will drop the standard berries for each berry bush, as well as add a 50% chance to drop a "coffee_bean". There's more that could be done to protect loot added by other mods, but this is fine for a temporary solution.

Edited by Bumber64

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
×
  • Create New...