Sign in to follow this  
NeddoFreddo

Custom fridge structure

Recommended Posts

NeddoFreddo    1058

heyo,

I've added a custom fridge structure, and all is good except for one thing. I'd like it to only accept meats and vegetables, also not accept a specific custom prefab which happens to be meat.

Thanks if you can help!

Edited by NeddoFreddo
tanks - thanks

Share this post


Link to post
Share on other sites
Joachim    351

Inside your custom container prefab constructor function, you need to call:

inst.components.container:WidgetSetup("custom_container", data)

This is the code from the icebox for data:

--------------------------------------------------------------------------
--[[ icebox ]]
--------------------------------------------------------------------------

local data =
{
    widget =
    {
        slotpos = {},
        animbank = "ui_chest_3x3",
        animbuild = "ui_chest_3x3",
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}

for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(data.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end

data.itemtestfn = function(container, item, slot)
    if item:HasTag("icebox_valid") then
        return true
    end

    --Perishable
    if not (item:HasTag("fresh") or item:HasTag("stale") or item:HasTag("spoiled")) then
        return false
    end

    --Edible
    for k, v in pairs(FOODTYPE) do
        if item:HasTag("edible_"..v) then
            return true
        end
    end

    return false
end

If you want it to only accept meats and vegetables, except for one custom prefab, then you mold itemtestfn into this:

data.itemtestfn = function(container, item, slot)
    return item.components.edible and (item.components.edible.foodtype == FOODTYPE.MEAT or item.components.edible.foodtype == FOODTYPE.VEGGIE) and not item.prefab == "banned_custom_meat_prefab"
end

 

Edited by Joachim

Share this post


Link to post
Share on other sites

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
Sign in to follow this