ConstructibleObject Functions
A pretty comprehensive array of ConstructibleObject functions.
Highlights:
- Crafting event. Other mods have crafting events. This one includes the exact recipe used.
- Find every recipe for an item or ingredient.
- Recursively calculate what your ingredients can ultimately produce. Iron Ore -> Iron Ingot -> Iron Dagger.
- Check craftability (what you can actually craft right now with what's in your inventory), includes perk and condition checks.
- Calculate material costs, output values, profits and profit margins.
- Find the most profitable recipes.
- Built in token compatibility system for mods like CACO that represent items like flour via hidden inventory tokens.
Surface thus far:
Spoiler
;======================================================================================== ; ConstructibleObjects ================================================================== ;======================================================================================== ; Register your form for crafting mod events. ; Usage: ; _MGF_Util.RegisterForItemCrafted(Self) ; ; Event On_MGF_ItemCrafted(Form CreatedItem, Form Recipe, Int Quantity, Keyword BenchKeyword) ; Debug.Messagebox("Crafted: " + CreatedItem.GetName() + "\nRecipe: " + Recipe + "\nQuantity: " + Quantity + "\nBenchKeyword: " + akBenchKeyword) ; EndEvent ; akCreatedItem - The item created. ; akRecipe - The recipe used to create the item. ; Quantity - The number of items created. ; BenchKeyword - The workbench keyword (BNAM) associated with the recipe. ; Load game maintenance not required. Registrations persist through save/loads. ; Use UnregisterForItemCrafted below to stop events. Function RegisterForItemCrafted(Form akForm) Global Native ; Unregister for crafting events. Function UnregisterForItemCrafted(Form akForm) Global Native ; Whether or not this form is registered for crafting events. Bool Function IsRegisteredForItemCrafted(Form akForm) Global Native ; Some mods (CACO!) use a system of tokens to represent portions of ingredients. ; Use this function to register an inventory form with a corresponding token form, token count and ModName. ; When running relevant crafting functions (like GetCraftableRecipes()) the system will automatically swap out ; inventory facing items for the equivalent crafting tokens and their equivalent token count. ; Registrations are persistent until unregistered. ; MGF has built in support for CACO. See _MGF_InterfaceCaco. ; InvForm: The inventory facing form that the token represents. ; TokenForm: The actual crafting ingredient. ; TokenCount: How many tokens the inventory item is 'worth'. ; ModName: This is just so tokens can be tracked and grouped together and be Unregistered if necessary. ;/ Eg: RegisterTokenMapping(InvForm = PinchOfSalt, TokenForm = SaltToken, TokenCount = 1, ModName = "SomeMod.esp") RegisterTokenMapping(InvForm = SpoonOfSalt, TokenForm = SaltToken, TokenCount = 20, ModName = "SomeMod.esp") RegisterTokenMapping(InvForm = BagOfSalt, TokenForm = SaltToken, TokenCount = 100, ModName = "SomeMod.esp") /; Function RegisterTokenMapping(Form InvForm, Form TokenForm, Int TokenCount, String ModName) Global Native ; Removes all token mappings that were registered with ModName. Function UnregisterTokenMappings(String ModName) Global Native ; Is a registered inventory form for a token. Bool Function IsTokenIngredient(Form InvForm) Global Native ; Returns the equivalent token registered for InvForm. Returns None if not found. Form Function GetTokenFor(Form InvForm) Global Native ; Returns the number of tokens InvForm is 'worth'. Eg. CACO: BYOHFoodIngrFlourBarley05 = 5 tokens of flour. Int Function GetTokenCountFor(Form InvForm) Global Native ; Returns every portionIndex registered against Token, sorted ascending. Empty array if ; Token isn't a registered token. Use this to discover valid GetFormForToken quantities. ; From the example above in RegisterTokenMapping() this would return [1, 20, 100] Int[] Function GetRegisteredPortionsForToken(Form Token) Global Native ; Returns the ingredient form registered against Token at exactly Quantity portions, or ; None if no form is registered at that quantity. Exact match only. Use ; GetRegisteredPortionsForToken() to discover which quantities are valid. Form Function GetFormForToken(Form Token, Int Quantity = 1) Global Native ; Returns the gold value of Token's canonical (portionIndex == 1) ingredient, or -1 if ; Token isn't a registered token or has no atomic-unit entry. Returns -1 rather than 0 ; on a miss, since a real ingredient can legitimately be worth 0 gold. Int Function GetGoldValueForToken(Form Token) Global Native ; Batch-resolves InvForms through the token map. Each form that has a token registered ; gets swapped for its token form; anything unregistered passes through unchanged. ; Equivalent to calling GetTokenFor on every element, but in one native call. Form[] Function ResolveTokenForms(Form[] InvForms) Global Native ; For each form in InvForms, returns how many tokens akRef's current inventory represents ; for it: inventoryCount * portionIndex if the form is a registered token ingredient, or ; just the raw inventory count otherwise. Arrays are matched by index — result[i] corresponds ; to InvForms[i]. Returns an all-zero array if akRef is None. Int[] Function ResolveTokenCounts(ObjectReference akRef, Form[] InvForms) Global Native ; Register a global for the crafting query system to ignore. ; When checking crafting recipes for global conditions the system will consider these as passing. ; Registrations are persistent until unregistered. ; Eg: Globals designed to declutter the crafting menu will inadvertently narrow results (CACO_OptionDeclutterCookingMenu). Function RegisterIgnoredGlobal(GlobalVariable akGlobal, String asModName) Global Native ; Unregister a global. Function UnregisterIgnoredGlobals(String asModName) Global Native ; Returns the index of the first recipe in the list that creates akForm. Returns -1 if not found. ; Any recipe in the list that isn't a COBJ will be ignored. Int Function FindRecipeForItem(ConstructibleObject[] Recipes, Form akForm) Global Native ; Returns true if the recipe is a tempering recipe. ; This isn't just a workstation keyword check (though that's a fallback). Should be pretty accurate, even for mod added stuff. Bool Function IsTemperingRecipe(ConstructibleObject akRecipe) Global Native ; Returns an array of Recipes that create akForm. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Optional check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetRecipesForForm(Form akForm, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, \ Bool CheckGlobals = false) Global Native ; Returns the ingredients needed for a recipe as an array of forms ; This is a 1:1 map with GetRecipeQuantities() Form[] Function GetRecipeIngredients(ConstructibleObject akRecipe) Global Native ; Returns the quantity of items needed to create a recipe ; This is a 1:1 with GetRecipeIngredients() Int[] Function GetRecipeQuantities(ConstructibleObject akRecipe) Global Native ; Returns true if ObjRef has all the ingredients needed to create akRecipe Bool Function HasIngredientsForRecipe(ConstructibleObject akRecipe, ObjectReference ObjRef) Global Native ; Check the player can craft akRecipe. ; Automatically checks both player perks and global conditions. ; CheckIngredients: True = Player must have the ingredients. False = Don't care. Bool Function CanCraftRecipe(ConstructibleObject akRecipe, Bool CheckIngredients) Global Native ; Return a list of recipes the player can actually craft. ; akRecipes: The list of recipes to check. ; CheckIngredients: True = Player must have the ingredients. False = Don't care. ; CheckPerks: Optional check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function FilterCraftableRecipes(ConstructibleObject[] akRecipes, Bool CheckIngredients = false, \ Bool CheckPerks = true, Bool CheckGlobals = true) Global Native ; Returns all recipes that can be crafted with any of the listed ingredients. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Optional check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ; Recursive: False = Normal operation. True = Recursively include the results of what akIngredients can craft. Continue until no additional results are generated. ConstructibleObject[] Function GetCraftableRecipes(Form[] akIngredients, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, \ Bool CheckGlobals = false, Bool Recursive = false) Global Native ; Same as GetCraftableRecipes() but instead returns the forms that could be created with the ingredients. Form[] Function GetCraftableForms(Form[] akIngredients, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, Bool CheckGlobals = false, \ Bool Recursive = false) Global Native ; Similar to GetCraftableRecipes but also takes a count of the forms on hand to satisfy crafting conditions. ; Both input arrays must be a 1:1 map - Combine with function CountForms(). ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetCraftableRecipesWithCount(Form[] akIngredients, Int[] akCounts, Bool ExcludeTempering = true, \ Keyword[] WorkbenchFilter, Bool ReverseWorkbenchFilter = false, \ Bool CheckPerks = false, Bool CheckGlobals = false) Global Native ; Same as GetCraftableForms() but with form counts, like GetCraftableRecipesWithCount() Form[] Function GetCraftableFormsWithCount(Form[] akIngredients, Int[] akCounts, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, Bool CheckGlobals = false) Global Native ; Returns an array of recipes that result in an item matching at least one of akKeywords. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetRecipesByKeywords(Keyword[] akKeywords, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, Bool CheckGlobals = false) Global Native ; Returns an array of recipes that use akForm to create something. ; akKeywords: Only return created items that have at least one of these keywords. Empty array = No keyword filtering. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetRecipesUsingIngredient(Form akIngredient, Keyword[] akFilterKeywords, Bool ExcludeTempering = true, \ Keyword[] WorkbenchFilter, Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, \ Bool CheckGlobals = false) Global Native ; Returns an array of recipes that use a workstation with the BenchKw to be created. ; FilterKeywords - Returns only created items that have at least one matching keyword. Empty array = no filtering. ; ExcludeTempering: Exclude any tempering recipes from results. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetRecipesForWorkbench(Keyword akWorkbench, Keyword[] FilterKeywords, Bool ExcludeTempering = true, \ Bool CheckPerks = false, Bool CheckGlobals = false) Global Native ; Returns true if there's at least one recipe to create akForm. Automatically excluded tempering recipes. Bool Function IsCraftable(Form akForm) Global Native ; Return true if there's at least one recipe to temper akForm Bool Function IsTemperable(Form akForm) Global Native ; Return only forms that have at least one craftable recipe (excludes tempering recipes). ; ReverseFilter: False = Normal operation. True = Return only items that have no crafting recipe. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. Form[] Function FilterFormsWithRecipes(Form[] akForms, bool ReverseFilter = false, Bool ExcludeTempering = true, \ Keyword[] WorkbenchFilter, Bool ReverseWorkbenchFilter = false, Bool CheckPerks = false, \ Bool CheckGlobals = false) Global Native ; Returns the total gold value for all items to create the item (Not market value - speech skill/perks etc) Int Function GetRecipeMaterialCost(ConstructibleObject akRecipe) Global Native ; Returns all the perks needed to create akRecipe Perk[] Function GetRecipeRequiredPerks(ConstructibleObject akRecipe) Global Native ;/ A note on 'Float Accuracy = 100.0' parameter in the next few functions. Accuracy is intended as a simple skill based system. 100% Accuracy: Profit = 100g → Returns exactly 100g 75% Accuracy: Profit = 100g → Returns 87-113g (±12.5% variance) 50% Accuracy: Profit = 100g → Returns 75-125g (±25% variance) 25% Accuracy: Profit = 100g → Returns 62-138g (±37.5% variance) 0% Accuracy: Profit = 100g → Returns 50-150g (±50% variance) - complete guess! /; ; Return the total gold value of the items created by a recipe. Accuracy: See above Int Function GetRecipeOutputValue(ConstructibleObject akRecipe, Float Accuracy = 100.0) Global Native ; Returns the gold difference of the total output value of the recipe minus the total cost of the ingredients. Accuracy: See above Int Function GetRecipeProfit(ConstructibleObject akRecipe, Float Accuracy = 100.0) Global Native ; Returns the % profit made between the cost of the ingredients versus the output value of the recipe. Accuracy: See above Float Function GetRecipeProfitMargin(ConstructibleObject akRecipe, Float Accuracy = 100.0) Global Native ; Returns an array of recipes with the most profits to be made. ; Count: How many recipes to return. ; CheckIngredients: Player must have the ingredients for recipe to be returned. ; SortBy: 0 - Sort by profit margin (% profit). 1 - Sort by absolute profit. Element 0 being the best and element n being the least profitable. ; FilterKeywords: Return only recipes that result in an item with at least one of these keywords. Empty array = no filtering. ; Accuracy: See note above. ; ExcludeTempering: Exclude any tempering recipes from results. ; WorkbenchFilter: Return only recipes crafted with these workbench keywords. Empty array = no workbench filtering. ; ReverseWorkbenchFilter: False = Normal operation. True: Return only recipes that don't use any of the listed workbench keywords. ; CheckPerks: Check player has the perks to craft the recipe. ; CheckGlobals: Check any global conditions are satisfied. ConstructibleObject[] Function GetMostProfitableRecipes(Int Count, Bool CheckIngredients, Int SortBy, Keyword[] FilterKeywords, \ Float Accuracy, Bool ExcludeTempering = true, Keyword[] WorkbenchFilter, \ Bool ReverseWorkbenchFilter = false, Bool CheckPerks = true, \ Bool CheckGlobals = true) Global Native
Edited by Monoman1
0
0 Comments
Recommended Comments
There are no comments to display.