Jump to content

Unlearning/Unknowning/Relocking/Hiding Recipes


Recommended Posts

After finially recoding all of the stuff I had modded up to this point I return with more questions; the drive that I had the mod stored on decided to **** the bed, naturally. This time it pertains to recipes and how that game stores what you know and don't.

I'll start off with my objective. Simply, I want to be able to hide/lock certain recipes based on certain conditions. For example, the shovel. The shovel recipe is auto known for all new characters but not unlocked. I would like it to not be known until I say otherwise.

In the builder componet I saw the KnowRecipe function but from what I could tell it doesn't have the ability to "unknow" a recipe. I tried to add to the functionality with an AddComponentPostInst and function hook with an extra perameter that returns false but no dice, I'll append that attempt below.  Second I saw the self.recipes table within Builder. At first I thought this is where all you're known recipes are considered the AddRecipe function appends them there, but when I tried printing out its data it came up blank. I test added something to that table to make sure I wasn't doing something wrong and I was doing things correctly.

I know about the CanBuild but as far as Im aware that doesn't hide things and I know this should be possible because going near/away from a science machine reveals/hides recipes you haven't made yet.

Edit: It took until now for me to think and realize that maybe I should acutally check the prototyper component and science machine prefab to see how it does that.

Here's the first attempt \/

--As this function doesn't reutrn the old KnowsRecipe, this pretty much contians the entire oringal function
AddComponentPostInit("builder", function(self)

	local BuildKnowRecipe_old = self.KnowsRecipe
	self.KnowsRecipe = function(recipe, ignore_tempbonus, forget)

		if forget == true then
			return false
		end

		if type(recipe) == "string" then
			recipe = GetValidRecipe(recipe)
		end

		if recipe == nil then
			return false
		end
		if self.freebuildmode then
			return true
		elseif recipe.builder_tag ~= nil and not self.inst:HasTag(recipe.builder_tag) then -- builder_tag cehck is require due to character swapping
			return false
		elseif self.station_recipes[recipe.name] or table.contains(self.recipes, recipe.name) then
			return true
		end

		--[[
		local has_tech = true
		for i, v in ipairs(TechTree.AVAILABLE_TECH) do
			if ignore_tempbonus then
				if recipe.level[v] > (self[string.lower(v).."_bonus"] or 0) then
					return false
				end
			else
				if recipe.level[v] > ((self[string.lower(v).."_bonus"] or 0) + (self[string.lower(v).."_tempbonus"] or 0)) then
					return false
				end
			end
		end
		]]--

		return true

	end
end)

 

I guess what I'm really asking here is does anyone know where I can find where recipes are stored and, if they are stored as a list, would it be practical to remove recipes from that list to make them unknown on a self level.

Thanks for the read lads.

 

Edited by MakeSureToKnock
  • Like 1
Link to comment
Share on other sites

7 hours ago, MakeSureToKnock said:

I'll start off with my objective. Simply, I want to be able to hide/lock certain recipes based on certain conditions. For example, the shovel. The shovel recipe is auto known for all new characters but not unlocked. I would like it to not be known until I say otherwise.

not exactly the best solution but an easy solution would be to change the existing recipe that only people with "insert tag" can acquire it, put it in the subroutine that gives it to every player characters and manually remove the tag to hide it.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You say that the Shovel recipe is known for all characters but it has to be prototyped first, but that's not correct, which I think is what's causing confusion for you. The game by default simply shows you all recipes you know, PLUS all recipes 1 level higher than your currently available tech. Since most characters start with 0 levels of SCIENCE and the Shovel is level 1 of SCIENCE, it will show up as a hint, but the player DOESN'T know the recipe. I actually play with the setting to show all recipes no matter what, so there's that too to consider.

What you're looking for isn't handled by components, it's handled by the widget that shows and hints recipes, which you can find in widgets/redux/craftingmenu_hud.lua, more specifically the RebuildRecipes() function. I've had to mess with this one a lot, since I like to make less conventional recipes sometimes. You'll see that it calls the global function ShouldHintRecipe(), you can find this one in widgets/widgetutil.lua, it's what handles the hint behavior I mentioned.

About the Shovel, what exactly are you trying to do? Do you only want to change only the Shovel by keeping it at level 1 SCIENCE but not show the hint, only show when it can be prototyped? Do you want the game to not show hints for any recipe in general? I ask because there would be many ways to go about your problem depending on what you need. I'd be willing to write you some code as usual and explain how it works, so you can learn from it and change what you need, but I need to know what your goal is exactly.

  • Like 1
  • Thanks 1
  • Shopcat 1
Link to comment
Share on other sites

What I mean is, for example, when you approch a science machine tech that were previously not "known", as in they didn't even show up in the crafting menu, now appear. As you mentioned this has to do with the science level and showing one level above. What I want is effectivly make the entire crafting menu blank. No recipes show until conditions for each recipe I want to handle are met. After those conditions are met the recipe will then always show, regardless if you're standing next to a science machine or not, until the conditions are wiped or otherwise.

The science bonus, and realated, var in the builder component handles that for everything that isn't tech level 0 or 1, campfire and shovels respectively. I'm assuming things like shovels/chest/boards/ropes are tech level 1 as you can see them but cannot build/research them without a science machine while campfires/pickaxes/torches are tech level 0 because you can.

Currenly I have this in my character prefab master_postinit

	inst.components.builder.science_bonus = -666
	inst.components.builder.magic_bonus = -666
	inst.components.builder.ancient_bonus = -666
	--Does the acid wave thing
	inst.components.builder.shadow_bonus = -666

Which, like aformentioned, will work for 80% of what I want. Also the shadow_bonus doing That™ during evening and night is something else entirely unrelated.

Will fiddle around with the RebuildRecipes and ShouldHintRecipes today as see were I go. 

Thanks again for the timely responses!

  • Like 1
Link to comment
Share on other sites

 Alright so I've conceptualized a method but there are some things is requires that I don't know how to do. Specfically, hooking widgets and addpostinit for widgets. I saw in the widgetutli file that there is a sort of AddWidgetPostInit, as least thats what the comment suggested, but I'm not entirly sure how to go about using it and then hooking widgets seems to be different in a way I can't seem to figure out. Hooking the RebuildRecipe function would allow me to just add an extra check for character tag then run was I desire ending with the meta.can_build = false and meta.build_state = "hide" vars, which I believe is what overall allows the showing of recipes or not. 

If anything here seems wrong, I wouldn't know at the time of typing this.

Cheers lads.

====================================

*Three hours later*

I've got something that works:

AddClassPostConstruct("widgets/redux/craftingmenu_hud", function(self)	

	local rebuildrecipe_old = self.RebuildRecipes
	self.RebuildRecipes = function()
	
		local AllRecipes = GLOBAL.AllRecipes
	
		if self.owner:HasTag("characterYEE") then
				for k, recipe in pairs(AllRecipes) do	
					
					if self.valid_recipes[recipe.name] == nil then
						self.valid_recipes[recipe.name] = {recipe = recipe, meta = {}}
					end

					
					local meta = self.valid_recipes[recipe.name].meta
					
					meta.can_build = false
					meta.build_state = "hide"
				
				end
		else
			return rebuildrecipe_old()
		end
	end
end)

This locks and hides all the recipes in the game save for two expections. One, the crafting bar thing on the side of the screen(the pinbar?), which I imagine is seperate from the crafting HUD, and two, the "everything" tab in the crafting HUD.

Never mind with the first instance. The pinbar stuff will stay but I'm going to try and make it so it starts blank instead of with stuff.

I'll do a new post rather than editing this one if I find something else.

Edited by MakeSureToKnock
I don't want to make a new post
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...