Jump to content

Help with a character ability


Recommended Posts

Hi! I'm developing a character mod, the character is like an engineer, so I want him to be able to build every structure, without needing a science machine or an alchemy engine. Something like the wickerbottom ability. How do I do this? ;-;

Link to comment
Share on other sites

Hello Mr. Rowlet, welcome to the forums, you can do something like this:

inst.components.builder:UnlockRecipe("prefab") --prefab being the name of the item, such as "researchlab"

 

For doing multiple things like you want, I'd suggest making a table of the things you want to be able to craft and make a for loop to unlock each one, like so;

local structures = {"researchlab", "researchlab2", "chest", "firesuppresor", "icebox"}
for i=1, #structures do
	inst.components.builder:UnlockRecipe(structures[i])
end

 

Edited by Aquaterion
Link to comment
Share on other sites

4 minutes ago, Guij2 said:

Thank you! And... where exactly do I put this? It's my first mod, I'm still a bit confused with the script...

in your character's master_postinit function.

Also here's a version where it would check first if you have the recipe or not

local structures = {"researchlab", "researchlab2", "chest", "firesuppresor", "icebox"}
for i=1, #structures do
	if inst.components.builder:KnowsRecipe(structures[i]) then
		inst.components.builder:UnlockRecipe(structures[i])
	end
end

 

Edited by Aquaterion
Link to comment
Share on other sites

Hey, it actually didn't work :c I still need the science machine/alchemy engine to build all of them.

Edit: Oops, my bad, I didn't see the version with multiple things to unlock

Edited by Guij2
Link to comment
Share on other sites

43 minutes ago, Aquaterion said:

Hello Mr. Rowlet, welcome to the forums, you can do something like this:


inst.components.builder:UnlockRecipe("prefab") --prefab being the name of the item, such as "researchlab"

 

For doing multiple things like you want, I'd suggest making a table of the things you want to be able to craft and make a for loop to unlock each one, like so;


local structures = {"researchlab", "researchlab2", "chest", "firesuppresor", "icebox"}
for i=1, #structures do
	inst.components.builder:UnlockRecipe(structures[i])
end

 

That won't work for items added by mods or future recipes added by Klei. Even if you wanted to do it that way you could instead do inst.components.builder:GiveAllRecipes(). <- Nevermind that makes everything free.

I would do this instead, in your master_postinit:

	inst.components.builder.science_bonus = 100
	inst.components.builder.magic_bonus = 100
	inst.components.builder.ancient_bonus = 100
	inst.components.builder.shadow_bonus = 100

For reference, Wickerbottom has a science_bonus of 1, but setting all of them to 100 just unlocks it all since it checks for <= for recipe tiers.

Edited by DrSmugleaf
Link to comment
Share on other sites

2 minutes ago, DrSmugleaf said:

That won't work for items added by mods or future recipes added by Klei. Even if you wanted to do it that way you could instead do inst.components.builder:GiveAllRecipes().

I would do this instead, in your master_postinit:


	inst.components.builder.science_bonus = 100
	inst.components.builder.magic_bonus = 100
	inst.components.builder.ancient_bonus = 100
	inst.components.builder.shadow_bonus = 100

 

He only wanted STRUCTURES tho, not every item I think..

Link to comment
Share on other sites

13 minutes ago, Aquaterion said:

He only wanted STRUCTURES tho, not every item I think..

So much for my reading comprehension.

 

Edit: Here's for every structure without the sanity boost or manually inputting each:

	for k,v in pairs(AllRecipes) do
		if not inst.components.builder:KnowsRecipe(k) and AllRecipes[k].tab == RECIPETABS.TOWN then
			local recipe = GetValidRecipe(k)
			if recipe ~= nil and not recipe.nounlock then
				inst.components.builder:AddRecipe(k)
				inst.components.builder.inst:PushEvent("unlockrecipe", {recipe = k})
			end
		end
	end

 

Edited by DrSmugleaf
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...