Jump to content

[Request] Hunger while sleeping


Recommended Posts

I don't remember exactly where it is, but I know that this is set on the sleeping-aids and not the character. Look in bedroll_straw.lua, bedroll_furry.lua, tent.lua and/or siestahut.lua. They have different values. I don't think this kind of change lends itself well for a character mod.

Not saying you can't find a workaround, though. Something about listening for a sleep-event, and when that triggers, unregister from it, set a hungerbeforesleep variable on the player, and then listen for a wakeup event. When the wakeup-event triggers you could subtract a specific amount from hungerbeforesleep, and set the hunger for your player to the result, then unregister from the wakeup-event and listen for the next sleep-event.

Link to comment
Share on other sites

This should work -

It essentially rewrites the sleep function on the sleeping bags, etc.

So that if the character name is your CHARNAME

then the sleep function restores a number of calories after the sleep.

You should be able to place it in the modmain.lua, of your mod.

Spoiler

 

-- BEDROLL || 33 Sanity || 0 Health || -75 Hunger

function newsleepbag(inst)

   local oldonsleep = inst.components.sleepingbag.onsleep

    inst.components.sleepingbag.onsleep = function(inst, sleeper)
      oldonsleep(inst, sleeper)
        if sleeper.prefab == "CHARNAME" then
        sleeper:DoTaskInTime(1.3, function()
            sleeper.components.hunger:DoDelta(30, false, true)

-- Restores 30 calories after the Bedroll's normal function removes 75

        end)
        end
    end
end

-- FURROLL || 33 Sanity || 30 Health || -75 Hunger 

function newsleepfur(inst)

   local oldonsleep = inst.components.sleepingbag.onsleep

    inst.components.sleepingbag.onsleep = function(inst, sleeper)
      oldonsleep(inst, sleeper)
        if sleeper.prefab == "CHARNAME" then
        sleeper:DoTaskInTime(1.3, function()
            sleeper.components.hunger:DoDelta(30, false, true)

-- Restores 30 calories after the Fur roll's normal function removes 75
        end)
        end
    end
end

-- TENT || 50 Sanity || 60 Health || -75 Hunger

function newsleeptent(inst)

   local oldonsleep = inst.components.sleepingbag.onsleep

    inst.components.sleepingbag.onsleep = function(inst, sleeper)
      oldonsleep(inst, sleeper)
        if sleeper.prefab == "CHARNAME" then
        sleeper:DoTaskInTime(1.3, function()
            sleeper.components.hunger:DoDelta(30, false, true)
  -- Restores 30 calories after the Tent's normal function removes 75
        end)
        end
    end
end

-- LEANTO || 50 Sanity || 60 Health || -25 Hunger

function newsleepseiesta(inst)

   local oldonsleep = inst.components.sleepingbag.onsleep

    inst.components.sleepingbag.onsleep = function(inst, sleeper)
      oldonsleep(inst, sleeper)
        if sleeper.prefab == "CHARNAME" then
        sleeper:DoTaskInTime(1.3, function()
            sleeper.components.hunger:DoDelta(10, false, true)
  -- Restores 10 calories after the Tent's normal function removes 25
        end)
        end
    end
end

--adds the newsleep function to bedroll_straw, bedroll_furry, and tent
AddPrefabPostInit("bedroll_straw", newsleepbag)
AddPrefabPostInit("bedroll_furry", newsleepfur)
AddPrefabPostInit("tent", newsleeptent)
AddPrefabPostInit("siestahut", newsleepsiesta)


 

 

Link to comment
Share on other sites

Sorry for answering that late, but thanks for your answers! Gonna give it a try asap.

Ok so, I've tried and there is a problem. Even if the character doesn't sleep the hunger is still restored. Right-clicking on a tent during the day will restore 30 hunger freely, for exemple.

Link to comment
Share on other sites

You need to check out the original functions in bedroll_straw.lua, bedroll_furry.lua, tent.lua and siestahut.lua. I believe they have some sort of check for daytime. You must employ this as well around your hunger-change. I'm not sure you need this for bedrolls, though. Bedrolls and tent/siestahut work differently.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...