Coldchilli Posted April 18, 2021 Share Posted April 18, 2021 (edited) What I want to do: I want to add custom cooking recipe, lets say it use log as ingredient. But my character also has unique crockpot. Problem is AddIngredientValues make log able to add to any crockpot, which might disrupt other characters' cooking. I have reading a lot of cooking related code, I found this in scripts/cooking.lua local function IsCookingIngredient(prefabname) return ingredients[aliases[prefabname] or prefabname] ~= nil end I want to refers to AddIngredientValues here too, but it might be too long. then I found this in scripts/containers.lua (not container component) function params.cookpot.itemtestfn(container, item, slot) return cooking.IsCookingIngredient(item.prefab) and not container.inst:HasTag("burnt") end I also found this itemtestfn as local function in container component. I believe this itemtestfn restrict what can and cannot put into crockpot's container. But as you see, any prefab that added by AddIngredientValues, is added to ingredients table, thus will be able to put to any crockpots. What I planned to do and problem to solve: I want to bypass AddIngredientValues then add log directly as viable ingredient to place in my unique crockpot. So, I want to replace itemtestfn of container component of my unique crockpot prefab. I tried add this after AddComponent("container"). local cooking = require("cooking") removesetter(inst.components.container, "itemtestfn") -- remove read only inst.components.container.itemtestfn = function(self, ontainer, item, slot) print("Item Prefab : "..tostring(item.prefab)) print("Is cooking ingredient : "..tostring(cooking.IsCookingIngredient(item.prefab))) return (item.prefab == "log" or cooking.IsCookingIngredient(item.prefab)) and not self.inst:HasTag("burnt") end makereadonly(inst.components.container, "itemtestfn") --re apply read only At first I got "Cannot change read only property", so I add those removesetter and makereadonly to temporally disable read-only, yet it still not work (cannot put log in my unique crockpot) Other 2 things I tried are, in modmain.lua of my character mod, I added these in. First one is local cooking = require("cooking") AddPrefabPostInit("my_cookpot", function(inst) if inst.components.container then inst.components.container.CanTakeItemInSlot = CanTakeItemInSlot GLOBAL.removesetter(inst.components.container, "itemtestfn") -- remove read only inst.components.container.itemtestfn = function(self, ontainer, item, slot) print("Item Prefab : "..tostring(item.prefab)) print("Is cooking ingredient : "..tostring(cooking.IsCookingIngredient(item.prefab))) return (item.prefab == "log" or cooking.IsCookingIngredient(item.prefab)) and not self.inst:HasTag("burnt") end GLOBAL.makereadonly(inst.components.container, "itemtestfn") --reapply read only end end ) But it only print when normal ingredients is put in pot, not log.I tried copied CanTakeItemInSlot function, found that item is nil, then I used container's GetItemInSlot to check item in slot, print it and found that somehow it said item is in limbo. One last thing I tried. local cooking = require("cooking") AddComponentPostInit("container", function(self) local itemtestfn_old = self.itemtestfn if self.inst.prefab == "my_cookpot" then self.itemtestfn = function(self, ontainer, item, slot) print("Item Prefab : "..tostring(item.prefab)) print("Is cooking ingredient : "..tostring(cooking.IsCookingIngredient(item.prefab))) return (item.prefab == "log" or cooking.IsCookingIngredient(item.prefab)) and not self.inst:HasTag("burnt") end else self.itemtestfn = itemtestfn_old end end ) Not print, not working at all and even if I intentionally try to crash it with self.itemtestfn = nil then comment out everything else, it still work properly, but log cannot be added to my crockpot. Note: I tested all of these without cave (server). Edited April 18, 2021 by Coldchilli Link to comment Share on other sites More sharing options...
Coldchilli Posted April 25, 2021 Author Share Posted April 25, 2021 Update: I found that when player move item from their inventory to any container including crockpot, it goes like this. Inventory component's MoveItemFromAllOfSlot to Container component's CanTakeItemInSlot. But still print in overridden MoveItemFromAllOfSlot is not trigger when trying to put things that not added by AddIngredientValues, like log or rocks. Summarized question: I want to add unusual ingredient to my custom crockpot. But using AddIngredientValues will make it available to all crockpots. I were trying to find where the game block things that is not inside cooking's ingredients table from enter the crockpot. Link to comment Share on other sites More sharing options...
goobboy Posted June 25, 2022 Share Posted June 25, 2022 Up Link to comment 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