DrunkProtos Posted June 1, 2025 Share Posted June 1, 2025 (edited) I am writing this post, because how frustrating it was to figure this out, and how easy it was actually to do. These code snippets were basically made by Wonderlarr, I just edited them for ease of use. This tutorial assumes you have already made a working component for your custom stat. modmain.lua: GLOBAL.CHARACTER_INGREDIENT["CUSTOM"] = "custom" local _IsCharacterIngredient = GLOBAL.IsCharacterIngredient GLOBAL.IsCharacterIngredient = function(ingredienttype) if ingredienttype and ingredienttype == "custom" then return true else return _IsCharacterIngredient(ingredienttype) end end AddClassPostConstruct("components/builder_replica", function(self) local _HasCharacterIngredient = self.HasCharacterIngredient self.HasCharacterIngredient = function(self, ingredient) if self.inst.components.builder ~= nil then return self.inst.components.builder:HasCharacterIngredient(ingredient) elseif ingredient.type == CHARACTER_INGREDIENT.CUSTOM then local custom = self.inst.replica.custom if custom ~= nil then local current = custom:GetCurrent() -- make sure this is a function that returns the current value of your custom stat return current >= ingredient.amount, current end end return _HasCharacterIngredient(self, ingredient) end end) AddClassPostConstruct("components/builder", function(self) -- RemoveIngredients local _RemoveIngredients = self.RemoveIngredients self.RemoveIngredients = function(self, ingredients, recname) local recipe = GLOBAL.AllRecipes[recname] if recipe then for k,v in pairs(recipe.character_ingredients) do if v.type == CHARACTER_INGREDIENT.CUSTOM then self.inst.components.custom:DoDelta(-v.amount) end end end return _RemoveIngredients(self, ingredients, recname) end -- HasCharacterIngredient local _HasCharacterIngredient = self.HasCharacterIngredient self.HasCharacterIngredient = function(self, ingredient) if ingredient.type == CHARACTER_INGREDIENT.custom and self.inst.components.custom ~= nil then local current = self.inst.components.custom.current -- make sure this is an existing property of your stat that holds the current value return current >= ingredient.amount, current end return _HasCharacterIngredient(self, ingredient) end end) So you basically change every "custom" with the name of your custom stat, and it should work. Edited June 1, 2025 by DrunkProtos Link to comment https://forums.kleientertainment.com/forums/topic/166083-tutorial-using-custom-stat-as-a-crafting-ingredient/ 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