DarkM Posted April 30, 2025 Share Posted April 30, 2025 Hello, I want to make a mod that makes meat dry faster, but I don't know how to override a prefabs list file, like it is in meats.lua. I only saw examples of single prefab files, does anyone know a way to make the override in prefab lists files ? or send examples please? Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/ Share on other sites More sharing options...
Merkyrrie Posted April 30, 2025 Share Posted April 30, 2025 You would still need to do each prefab in the meats.lua file individually, as there is nothing really connecting them besides being constructed in the same file and being given the same functions. This can still be accomplished easily by creating a list of all the prefabs you want to change and then using a for loop to do the same thing to each of them. Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814609 Share on other sites More sharing options...
Baguettes Posted April 30, 2025 Share Posted April 30, 2025 Honestly, use a prefab post init. Overwriting stuff tends to end up horribly for other mods or even the vanilla game itself. --put meat prefabs in here. local meatList = { "meat", -- "", -- "", -- "", } for _, v in pairs(meatList) do AddPrefabPostInit(v, function(inst) if not GLOBAL.TheWorld.ismastersim then return end if v.components.dryable then v.components.dryable:SetDryTime(replace_with_time_in_seconds) end end) end 1 Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814615 Share on other sites More sharing options...
DarkM Posted May 1, 2025 Author Share Posted May 1, 2025 23 hours ago, Baguettes said: Honestly, use a prefab post init. Overwriting stuff tends to end up horribly for other mods or even the vanilla game itself. --put meat prefabs in here. local meatList = { "meat", -- "", -- "", -- "", } for _, v in pairs(meatList) do AddPrefabPostInit(v, function(inst) if not GLOBAL.TheWorld.ismastersim then return end if v.components.dryable then v.components.dryable:SetDryTime(replace_with_time_in_seconds) end end) end With the help of a friend, we modified the code a little, it's not giving an error, but the code also doesn't work, do you or anyone else have an idea why it's not working? GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end}) local meatlist = { "meat", "smallmeat", "fishmeat", "fishmeatsmall", "monstermeat", "batwing", "froglegs", "drumstick", "eel" } for _, v in pairs(meatlist) do AddPrefabPostInit(v, function(inst) if not GLOBAL.TheWorld.ismastersim then return end if v.components and v.components.dryable then v.components.dryable:SetDryTime(0.5*480) end end) end Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814751 Share on other sites More sharing options...
Baguettes Posted May 2, 2025 Share Posted May 2, 2025 Did you make the modmain environment entirely global? I'm not sure how I'd go about explaining this myself, sadly, but AddPrefabPostInit is a mod env. function and may... not work in the game's global env? Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814837 Share on other sites More sharing options...
Merkyrrie Posted May 2, 2025 Share Posted May 2, 2025 21 hours ago, DarkM said: With the help of a friend, we modified the code a little, it's not giving an error, but the code also doesn't work, do you or anyone else have an idea why it's not working? GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end}) local meatlist = { "meat", "smallmeat", "fishmeat", "fishmeatsmall", "monstermeat", "batwing", "froglegs", "drumstick", "eel" } for _, v in pairs(meatlist) do AddPrefabPostInit(v, function(inst) if not GLOBAL.TheWorld.ismastersim then return end if v.components and v.components.dryable then v.components.dryable:SetDryTime(0.5*480) end end) end I'm not sure the GLOBAL.TheWorld.ismastersim check is actually necessary in AddPrefabPostInit functions, as it seems to never run on the client anyway but its not messing anything up so doing it just in case is fine. Your actual problem here is 'v.components' because v in this case is the current item in the list in the for loop, which is just a string and not the prefab itself. The function being given to AddPrefabPostInit is setting the given prefab variable to 'inst' so use that instead. if inst.components and inst.components.dryable then inst.components.dryable:SetDryTime(0.5*480) end 1 Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814847 Share on other sites More sharing options...
Baguettes Posted May 3, 2025 Share Posted May 3, 2025 aw yikes! I was too sleepy to think of that twice. @Merkyrrie is right, v is merely the thing in the local table and represents nothing apart from a silly string, and inst in the postinit is the correct object to use. Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814907 Share on other sites More sharing options...
DarkM Posted May 4, 2025 Author Share Posted May 4, 2025 @Merkyrrie @Baguettes The mod is working perfectly, thanks for the help with the codes! it's already available on steam, if you want to take a look: (Better Drying Rack) https://steamcommunity.com/sharedfiles/filedetails/?id=3474811680 Link to comment https://forums.kleientertainment.com/forums/topic/165552-how-do-i-overwrite-a-list-of-prefabs/#findComment-1814964 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