Jump to content

Recommended Posts

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?

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.

 

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
  • Like 1
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

 

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

 

  • Like 1

@Merkyrrie @Baguettes The mod is working perfectly, thanks for the help with the codes! :wilson_love:
it's already available on steam, if you want to take a look: (Better Drying Rack) https://steamcommunity.com/sharedfiles/filedetails/?id=3474811680

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...