You are viewing a potentially older version of this package. View all versions.
liekos47-SleepCall-1.0.3 icon

SleepCall

One player in bed skips the night - after a countdown everyone sees, and only once nobody is fighting or travelling.

Date uploaded a week ago
Version 1.0.3
Download link liekos47-SleepCall-1.0.3.zip
Downloads 85
Dependency string liekos47-SleepCall-1.0.3

This mod requires the following mods to function

denikson-BepInExPack_Valheim-5.4.2333 icon
denikson-BepInExPack_Valheim

BepInEx pack for Valheim. Preconfigured with the correct entry point for mods and preferred defaults for the community.

Preferred version: 5.4.2333

README

SleepCall

One player in bed is enough to skip the night - but nobody gets a black screen without warning.

In vanilla Valheim every player must be in bed before the night can pass. Mods that relax that to "one player" have a side effect: the moment someone lies down, everyone else fades to black - mid-fight, mid-voyage, mid-anything. SleepCall keeps the one-player rule and fixes the surprise.

Inspired by NowYouSleep by Hex_Viking, which lets the night pass when one player is sleeping. SleepCall is written from scratch and adds the warning, the countdown and the wait for players who are busy.

What happens

  1. A player lies down. Everyone sees "Astrid went to bed. The night will pass in 60 seconds." in the centre of the screen and in the top-left feed, with a note that fighting or travelling delays it.
  2. The centre banner repeats every 10 seconds with the time left ("Astrid is in bed - the night passes in 40 seconds"), and reminders at 30 and 10 seconds also go to the feed.
  3. With 5 seconds left, the server checks every player who is still up:
    • fighting - took damage in the last 15 s, or an alerted monster is within 40 m
    • travelling - moving faster than 3 m/s on average (running, sailing, riding)
  4. If anyone is, everyone sees "Waiting to sleep: Bjorn is in combat, Sigrid is travelling", repeated every 15 s until they are clear. After 5 minutes it gives up and skips anyway, with a final warning.
  5. The last 5 seconds are counted down in the centre of the screen: "Sleeping in 5", 4, 3, 2, 1, "Sleeping now". This always comes straight before the fade, also after a wait. If someone starts fighting or travelling during it, it goes back to waiting.
  6. The night passes exactly as in vanilla (same fade, same morning, same rested buff).

If everyone goes to bed, the night skips immediately, as it always has. If the sleeper gets up during the countdown, it is cancelled and everyone is told.

Missed a message? The top-left ones are kept in the Compendium's message log.

Install

Server only. Copy SleepCall.dll into BepInEx/plugins on the dedicated server and restart it. Clients need nothing. Remove any other "one player sleeps" mod first - two mods answering the same question will fight.

Config

BepInEx/config/liekos47.sleepcall.cfg, created on first start. The file is checked every 30 seconds and re-read when it has changed, so settings apply without a restart.

Setting Default Meaning
CountdownSeconds 60 warning time before the night passes
ReminderSeconds 30,10,5 when reminders are also posted to the feed; values at or below FinalCountdownSeconds are skipped
BannerIntervalSeconds 10 how often the centre banner repeats; 0 = start and reminders only
FinalCountdownSeconds 5 count the last seconds one by one ("Sleeping in 5" ... "Sleeping now"); 0 = off
TopLeftFeed true also post start, reminders, waiting and outcome to the top-left feed
ChatAnnounce false experimental: also shout the start and outcome in chat
WaitForCombat true hold while anyone is fighting
RecentDamageSeconds 15 "fighting" if health dropped this recently
AlertedMonsterRange 40 "fighting" if an alerted monster is this close
WaitForTravel true hold while anyone is travelling
TravelSpeed 3 "travelling" above this m/s (walk ~2, run ~7, sail 4-8)
MaxWaitSeconds 300 give up waiting after this long; 0 = never
WaitReminderSeconds 15 how often the waiting message repeats
DebugLog false log every message sent, not just the decisions

ChatAnnounce is off because a client checks the platform identity of whoever sent a chat line before showing it, and a line sent by the server has no such identity. It may simply not appear. It is harmless to try.

Server log

SleepCall writes a few lines per night to BepInEx/LogOutput.log, whatever DebugLog is set to:

[Info   : SleepCall] countdown started: Astrid in bed, 3 awake (Bjorn, Sigrid and Leif), 60s
[Info   : SleepCall] waiting: Bjorn is in combat
[Info   : SleepCall] skipping: countdown done after 61s, nobody fighting or travelling
[Info   : SleepCall] cancelled: nobody in bed any more
[Info   : SleepCall] everyone in bed (2 of 2), skipping at once

Note the space in [Info : SleepCall]: BepInEx right-aligns source names to 10 characters. Search with : *SleepCall], not :SleepCall].

How it works

Vanilla's own sleep loop (Game.UpdateSleeping) asks one question every frame during the afternoon and night: EverybodyIsTryingToSleep(). On yes it calls EnvMan.SkipToMorning and tells every client to fade. SleepCall replaces the answer to that question with its countdown and checks, and leaves everything after it to vanilla. It reads the same synchronised player data the server already has (bed state, position, health) and looks at nearby monster data for the alert flag, so it works on a dedicated server with no client-side component. Messages use the same ShowMessage route as vanilla's own broadcast messages.

Known limits

  • "Taking damage" is any health drop, so environmental damage (freezing, poison, burning) also counts as fighting.
  • "In combat" means an alerted monster is within range, even if it is not attacking.
  • Travel speed is sampled once a second and smoothed, so a portal jump reads as a short burst, not sustained travel.

Building

dotnet build SleepCall.csproj -c Release

Compiles against the game and BepInEx assemblies in refs\ (see Environment.props). Output: bin\Release\SleepCall.dll, plus a Thunderstore-style package in pkg\. hooks.txt lists every game member the mod uses, for checking against a new game version with HookCheck.

Built against Valheim l-1.0.16 with BepInExPack 5.4.2333.

Reloading the code without a restart

Only the settings reload by themselves. To swap the DLL on a running server while developing, use ScriptEngine: install it in BepInEx/plugins and put SleepCall.dll in BepInEx/scripts instead of plugins (never both). SleepCall removes its patch and timer when unloaded, so it can be loaded again cleanly. A reload forgets a countdown in progress; it starts again if someone is still in bed.

CHANGELOG

1.0.3

  • The last seconds are counted down one by one in the centre of the screen: "Sleeping in 5", 4, 3, 2, 1, then "Sleeping now" (FinalCountdownSeconds, 5; 0 = off). Before, the last message was "The night passes in 5 seconds" and then the screen went black.
  • The final count also runs after a wait for fighting or travelling ends, so the fade never follows straight on from "Waiting to sleep". If someone starts fighting or travelling during the count, it goes back to waiting.
  • Reminders at or below FinalCountdownSeconds are skipped; the final count covers them.
  • Fixed: a countdown left unfinished when the night ended on its own, or when the mod was disabled in the config, could carry on from where it stopped the next time someone lay down.
  • The config file is only re-read when it has changed, and the log says when it was.
  • Less work per frame during a countdown (no list or reminder parsing allocations).

1.0.2

  • The centre-screen countdown banner repeats every 10 s with the time left and who is in bed (BannerIntervalSeconds). Centre messages fade after about 4 s, so a single banner at the start was easy to miss entirely.
  • The countdown start, reminders, waiting reasons and outcome also go to the top-left feed (TopLeftFeed, on), which stays longer, queues rather than replacing, and is kept in the Compendium's message log.
  • Optional chat shout for the start and outcome (ChatAnnounce, off, experimental and untested: clients may drop chat from a server-made sender).
  • The first "waiting" message of a night is always logged, not only with DebugLog.
  • Built against Valheim l-1.0.16.

1.0.1

  • Always log countdown start, who is awake, the skip decision and cancellations (a few lines per night).
  • Re-read the config file every 30 s, so settings including DebugLog apply without a restart.

1.0.0

  • One player in bed skips the night after an announced countdown (default 60 s) with reminders.
  • After the countdown, waits while any awake player is fighting (recent damage or an alerted monster nearby) or travelling (sustained speed), naming who and why, then skips. Gives up after a configurable limit.
  • Everyone in bed still skips immediately; a sleeper getting up cancels with a message.
  • Server-side only. Built against Valheim l-1.0.14.