Jump to content

Recommended Posts

Hi, I'd like to add new things to my character's diet.

My character is a horrific demon beast monster & I want him to be able to eat rabbits, birds, moles, bees, logs, rocks & some more items that aren't edible.

Does someone how I can do this? Also, is there way when my character eats on of these I give him different state for eating them? I prefer to do a new food state which has more crunch sound to it, thanks for your time have a good day/night :)!

Edited by SuperDavid

This is from Woodie's prefab file, you can likely adapt it to yourself.

local BEAVER_DIET =
{
    FOODTYPE.WOOD,
    FOODTYPE.ROUGHAGE,
}

local function RightClickPicker(inst, target)
    if target ~= nil and target ~= inst then
        for i, v in ipairs(BEAVER_DIET) do
            if target:HasTag("edible_"..v) then
                return inst.components.playeractionpicker:SortActionList({ ACTIONS.EAT }, target, nil)
            end
        end
        return (target:HasTag("HAMMER_workable") and
                inst.components.playeractionpicker:SortActionList({ ACTIONS.HAMMER }, target, nil))
            or (target:HasTag("DIG_workable") and
                target:HasTag("sign") and
                inst.components.playeractionpicker:SortActionList({ ACTIONS.DIG }, target, nil))
            or nil
    end
end

inst.components.eater:SetDiet(BEAVER_DIET, BEAVER_DIET)

From Log's prefab file:

    inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.WOOD
    inst.components.edible.woodiness = 10
    inst.components.edible.healthvalue = 0
    inst.components.edible.hungervalue = 0

1.make a custom foodtype, you can do

    FOODTYPE.CRUNCHY = "CRUNCHY"
    
2.add edible component to your perferred prefab

    inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.CRUNCHY
    inst.components.edible.healthvalue = TUNING.HEALING_HUGE
    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE
    inst.components.edible.sanityvalue = TUNING.SANITY_HUGE

3.then in master_postinit

    local eater=inst.components.eater
        table.insert(eater.preferseating, FOODTYPE.CRUNCHY)
        table.insert(eater.caneat, FOODTYPE.CRUNCHY)
        inst:AddTag(FOODTYPE.CRUNCHY.."_eater")
    end
    
following are for crunchy sound

4.override the onenter function for "eat" state in SGwilson

    sgwilson=require("stategraphs/SGwilson")
    
    sgwilson.states["eat"].onenter = function(inst, foodinfo)
        inst.components.locomotor:Stop()

        local feed = foodinfo and foodinfo.feed
        if feed ~= nil then
            inst.components.locomotor:Clear()
            inst:ClearBufferedAction()
            inst.sg.statemem.feed = foodinfo.feed
            inst.sg.statemem.feeder = foodinfo.feeder
            inst.sg:AddStateTag("pausepredict")
            if inst.components.playercontroller ~= nil then
                inst.components.playercontroller:RemotePausePrediction()
            end
        elseif inst:GetBufferedAction() then
            feed = inst:GetBufferedAction().invobject
        end

        if feed == nil or
            feed.components.edible == nil or
            feed.components.edible.foodtype ~= FOODTYPE.GEARS then
            -- changes begin here
            if feed.components.edible.foodtype == FOODTYPE.CRUNCHY then
                --your custom sound file
                inst.SoundEmitter:PlaySound("dontstarve/wilson/crunchyeat", "eating")
            else
                inst.SoundEmitter:PlaySound("dontstarve/wilson/eat", "eating")
            end
            -- and ends here
        end

        if inst.components.inventory:IsHeavyLifting() and
            not inst.components.rider:IsRiding() then
            inst.AnimState:PlayAnimation("heavy_eat")
        else
            inst.AnimState:PlayAnimation("eat_pre")
            inst.AnimState:PushAnimation("eat", false)
        end

        inst.components.hunger:Pause()
    end

5.override the handler for ACTION.EAT in SGwilson
    
    sgwilson.actionhandlers[ACTION.EAT].deststate=function(inst, action)
        if inst.sg:HasStateTag("busy") then
            return
        end
        local obj = action.target or action.invobject
        if obj == nil or obj.components.edible == nil then
            return
        elseif not inst.components.eater:PrefersToEat(obj) then
            inst:PushEvent("wonteatfood", { food = obj })
            return
        end
        return (inst:HasTag("beaver") and "beavereat")
            or (obj.components.edible.foodtype == FOODTYPE.MEAT or
            -- changes in this line
                obj.components.edible.foodtype == FOODTYPE.CRUNCHY and "eat")
            or "quickeat"
    end),
    
code above are just conceptual demonstrate, not tested or modified for mod.

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...