Schulliya Posted June 26, 2022 Share Posted June 26, 2022 Hi. I want to change Chester's items to morph into fridge Chester. I don't understand exactly how does AddPrefabPostInit works. I know it can add new things to the prefab, but how can I modify something that's already there? Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/141223-replace-function-in-prefab/ Share on other sites More sharing options...
Bumber64 Posted June 27, 2022 Share Posted June 27, 2022 (edited) You mean modifying the function CanMorph? If you don't want to replace the entire prefabs/chester.lua, then you'll have to use upvalue hacking. You can reach CanMorph through inst.MorphChester. Rezecib's upvalue hacker is here. Put that in your mod's scripts/tools, then you can do: local UpvalueHacker = require("tools/upvaluehacker") local function yourCanMorphFunction(inst) --your modified version of CanMorph end AddPrefabPostInit("chester", function(inst) if inst.MorphChester then --this is set to nil in DoMorph UpvalueHacker.SetUpvalue(inst.MorphChester, yourCanMorphFunction, "CanMorph") end end) You can name your custom function "CanMorph" instead of "yourCanMorphFunction". I just named it that for clarity. Edited June 27, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/141223-replace-function-in-prefab/#findComment-1579966 Share on other sites More sharing options...
Schulliya Posted June 27, 2022 Author Share Posted June 27, 2022 16 hours ago, Bumber64 said: You mean modifying the function CanMorph? If you don't want to replace the entire prefabs/chester.lua, then you'll have to use upvalue hacking. You can reach CanMorph through inst.MorphChester. Rezecib's upvalue hacker is here. Put that in your mod's scripts/tools, then you can do: local UpvalueHacker = require("tools/upvaluehacker") local function yourCanMorphFunction(inst) --your modified version of CanMorph end AddPrefabPostInit("chester", function(inst) if inst.MorphChester then --this is set to nil in DoMorph UpvalueHacker.SetUpvalue(inst.MorphChester, yourCanMorphFunction, "CanMorph") end end) You can name your custom function "CanMorph" instead of "yourCanMorphFunction". I just named it that for clarity. thank you! Link to comment https://forums.kleientertainment.com/forums/topic/141223-replace-function-in-prefab/#findComment-1580073 Share on other sites More sharing options...
GrowthMindset Posted June 27, 2022 Share Posted June 27, 2022 (edited) 19 hours ago, Bumber64 said: You mean modifying the function CanMorph? If you don't want to replace the entire prefabs/chester.lua, then you'll have to use upvalue hacking. You can reach CanMorph through inst.MorphChester. Rezecib's upvalue hacker is here. Put that in your mod's scripts/tools, then you can do: local UpvalueHacker = require("tools/upvaluehacker") local function yourCanMorphFunction(inst) --your modified version of CanMorph end AddPrefabPostInit("chester", function(inst) if inst.MorphChester then --this is set to nil in DoMorph UpvalueHacker.SetUpvalue(inst.MorphChester, yourCanMorphFunction, "CanMorph") end end) You can name your custom function "CanMorph" instead of "yourCanMorphFunction". I just named it that for clarity. This made my game stuck at "Launching server..." and lagged my PC so much Repeated it 3 times... Removing this code form from my mod gets it back to normal... Any ideas? The logs file went up to 1+ GB. No kidding. I really wanna make upvalue hacker work. Even though I'm not sure how exactly I can modify local functions with it in prefab files (without replacing them) Edited June 27, 2022 by GrowthMindset Link to comment https://forums.kleientertainment.com/forums/topic/141223-replace-function-in-prefab/#findComment-1580098 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