Jump to content

[Help Request] Custom Character Resource in recipes

Recommended Posts

Hey all,

I've got a custom character resource (filth) for a goblin character I'm working on. I've got the resource ticking away, interactable, with the same sort of interfaces available to health and sanity (I think).

I am currently trying to add some character-specific recipes which use this resource in the same way that a reviver uses a chunk of current health.

  • I have added my FILTH value to CHARACTER_INGREDIENTS
  • I have added recipes to modmain in the structure of:
		Ingredient("cutreeds", 1), 
		Ingredient("flint", 1), 
	nil, nil, nil, nil, "TakTheGoblin",



The issue APPEARS to be that I don't know how to inform the game about my new resource as an ingredient. 

I have started looking at the code around recipe & builder, but I'm rapidly leaving my depth (given that not too long ago I didn't know lua, I feel OK about this).

I have tried to inject my own logic into some of recipe & builder's work by adding the following to my modmain trying to make anywhere I can see the game evaluate character ingredients also evaluate mine... but it's not working, and I'm stuck.  For reference:

local recipeclass = G.Ingredient--require "recipe"
local old_IsCharacterIngredient = recipeclass.IsCharacterIngredient
recipeclass.IsCharacterIngredient = function (ingredienttype)
	local oici = old_IsCharacterIngredient(ingredienttype)

	return oici 

local builder = require "components/builder"
local old_RemoveIngredients = builder.RemoveIngredients
builder.RemoveIngredients = function(ingredients, recname)
	local ori = old_RemoveIngredients(ingredients, recname)
	local recipe = G.AllRecipes[recname]
    if recipe then
        for k,v in pairs(recipe.character_ingredients) do
        	print("INJECT: evaluating an ingredient with type "..tostring(v.type))
            if v.type == CHARACTER_INGREDIENT.FILTH then
            	print("INJECT: found filth to remove ingredient")
        	elseif v.type == CHARACTER_INGREDIENT.MAX_FILTH then
        		 local b = nil --intentionally blank, dnt want anything modifying maxfilth

    return ori

local old_HasCharacterIngredient = builder.HasCharacterIngredient
builder.HasCharacterInrgedient = function(ingredient)
 	local ohci = old_HasCharacterIngredient(ingredient)
 	print("INJECT: HasCharIngredient")
 	if ingredient.type == CHARACTER_INGREDIENT.FILTH then
 		print("INJECT: found filth in ingredient")
        if self.inst.components.filth ~= nil then
            --round up filth to match UI display
            local current = math.ceil(self.inst.components.filth:GetFilth())
            return current >= ingredient.amount, current
    elseif ingredient.type == CHARACTER_INGREDIENT.MAX_FILTH then
        if self.inst.components.filth ~= nil then
            local penalty = self.inst.components.filth:GetPenaltyPercent()
            return penalty + ingredient.amount <= TUNING.MAXIMUM_SANITY_PENALTY, 1 - penalty


So a few questions:

  1. Can someone please explain to me how saving a function from a class and returning it works? Am I doing it right? I feel like I should be able to somehow access members of the function as if it were a table, but I cant figure out how to do so (for example in the code above, how can I access AllRecipes as the Builder class knows it during runtime? It always appears to be empty when this code runs?)
  2. Is there a 'checklist' of things to do to add a custom CHARACTER_INGREDIENT to the game such that it is recognized in the recipe tab/chooser and build processes? What am I missing?

Thanks in advance,


Mr Boosch

Edited by mrboosch
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

  • Create New...