Zen's Sleeping Mod - ZenarchistCode/ZenModPack GitHub Wiki
This mod adds an immersive sleeping fatigue stat to the game.
It is a total re-write of my original sleeping mod and is a far superior version, compatible with 1.28 and beyond.
Click here to watch a silly short trailer explaining the mod features: https://youtu.be/gWgUmdO1BZY
This new "sleep" stat works very similarly to the hunger and thirst stats.
Over time the player will slowly get tired, indicated by the moon icon stat. Eventually they will need to use the Lie Down emote to sleep. (Doing so requires no item in hands, a hotkey can be bound under vanilla Gestures keys).
If they ignore their basic human need to sleep for too long they eventually risk negative effects such as audible yawning giving away their position, occasional visual hallucinations, reduced immunity to sickness and even random unconsciousness if they get extremely tired.
The quality of a player's sleep is affected by whether they are sleeping at night time, near fires or other sources of warmth, inside buildings or tents, or on top of the custom included sleeping bag items which spawn in the world.
By "quality" of sleep I mean:
- There's a limit to how much their fatigue stat can be recovered based on their condition
- Some conditions make them eligible to receive immunity boosts or even health gain
- The speed they recover their fatigue stat is faster if their sleeping conditions are warm & cosy
Server admins have full control over the config of the mod, so the experience may vary from server to server and some of the features or items mentioned here might not be present if the admin doesn't want them to be.
I've spent a lot of time making this mod and followed the template of vanilla systems as closely as I possibly could based on my current modding skill level of 2+ years experience to ensure it is robust to future vanilla changes and also increases the chances of it being compatible with other mods.
It should be compatible with the vast majority of mods on the workshop, but might won't work well with other complex mods which affect player stats (like the Syberia Project for example, who have their own sleeping mod anyway).
A lot of thought has gone into the mechanics and I spent several weeks building the mod and bugtesting, although as a solo dev I'm sure bugs are still present and I'll do my best to fix any which are reported.
Install this mod like any other mod (there are many guides out there) - copy it into your server folder and add it to your server mods list. It must be run on both server and client. Make sure to copy the .bikey into your server keys.
Also don't forget to copy over the types.xml from inside the "extras" folder into your server types if you want to add the custom items to your loot table (optional). You can either import my types.xml separately (here's a guide: https://www.youtube.com/watch?v=PAAEhdiQ_vE) - OR just carefully merge my types with the vanilla types ensuring you don't break the XML structure in the process.
The Sleeping Bag items come as a single item which includes a "packed" and "deployed" state (much like vanilla tents). The types.xml data you specify is for the "packed" version spawns and the "deployed" version's lifetime. When the bag spawns it spawns as packed, so the spawn config tells the game where to create them. The packed version's item lifetime can be overwriten in the JSON config. This allows the "packed" version to despawn faster, while the deployed version can stay persistent. With the default config deployed bags have a persistence of 1 week if left untouched, while packed bags have a persistence of 4 hours if untouched.
The mod will automatically generate a default server config file in your server's profiles folder (under "profiles/Zenarchist/ZenSleepConfig.json"). If you're not experienced with JSON editing make sure to use this website to double-check the validity of your changes or you run the risk of the server reverting all of your changes to the default values: https://jsonlint.com/
There will be a YouTube video on my channel explaining how the mod works: https://www.youtube.com/@Zenarchist
You DO NOT need to wipe your server to add or remove this mod (according to my limited testing). But make sure to back up your server files before adding or wiping just to be safe, as there may be edge cases I didn't experience where database corruption can occur.
This mod requires Community Framework to function (https://steamcommunity.com/workshop/filedetails/?id=1559212036)
There is an optional persistence-related PBO file in the "ZenSleep/extras/defines" mod folder (for advanced server admins/modders only) - a readme file is included in that folder to explain what it does.
Obviously the original sleeping mod included in Medical Attention is a huge inspiration for this mod: https://steamcommunity.com/sharedfiles/filedetails/?id=2293429999
I learned a lot about the technique for adding custom stats to the game from the Syberia Project authors: https://steamcommunity.com/workshop/filedetails/?id=2569522069
I've learned a ton from DayZ modding communities, particularly the Enfusion Modders Discord (https://discord.com/invite/enfusion-modders-452035973786632194) and studying the work of the Expansion Project team (https://steamcommunity.com/workshop/filedetails/?id=2572331007).
My DayZ modding buddy SpaceCat (https://steamcommunity.com/id/spacecatboy/myworkshopfiles/?appid=221100) has taught me some important debug tricks and best practices which has no doubt led to improved stability/crash-proofness for this mod and my other recent mods.
You can repack this mod if you like, and do anything else you want with it for that matter. Just keep in mind my future updates won't be applied so make sure to check back for new versions if you notice any bugs. The source code is on my GitHub at www.zenarchist.io
All my mods are free and open source, but it takes an enormous amount of time to put some of these mods together. If I've helped you out, please consider helping me buy my next coffee! I don't expect it, but I very much appreciate it.
https://buymeacoffee.com/zenarchist
Enjoy!
The config below is copied straight out of the mod code and edited to be a little bit more readable. When you modify the JSON file all you really need to know is: a "float" is a decimal number (eg. 1.23), an "int" is a whole number (eg. 70), a "bool" is a true/false value (eg. 1 or 0), and a "string" is just text.
If you put a whole number where a float should be it will break the file, so pay attention when editing the file to ensure you add a decimal if you need to even if it's only a zero. And always place a comma (,) after a each list item EXCEPT on the final line where it is not required and will break the JSON file if you include it.
If you make a mistake (eg. putting an "int" where a "float" should be or missing a comma) then the mod will override your config with the default values when the server restarts, so always make a backup before editing.
Or ideally if you are not experienced with JSON files then simply use JSON Lint to copy & paste your changes into their checker and it will validate your JSON files and inform you of any mistakes and where the mistake is located so you can fix it before you start the server up and lose all your changes.
The text below might be hard to read here on GitHub so just click the little button below and to the right to copy it to your clipboard and then paste it into your preferred text editor if you can't read it easily here:
GeneralConfig
{
float SecondsAsleepUntilFullRestApprox = 600.0; // How long it takes from zero energy to full rest (WITHOUT any of the below gain multipliers applied)
float FreshSpawnFatiguePercent = 70; // % of fatigue a fresh spawn begins with (100% = full rested)
float MaxFatiguePercentToAllowSleeping = 70; // Maximum % of fatigue to allow sleep (70%+ = full white, 16%+ = white with gap, 6%+ = yellow, 0.02%+ = red, < 0.02% = red flashing)
int FatigueLevelToNegativeImpactImmunity = 2; // 0 = full white, 1 = white with a gap, 2 = yellow, 3 = red, 4 = red flashing
bool DisplaySleepMessages = true; // Turn on/off the text messages which get sent to players.
int PackedBagLifetime = 14400; // Overrides a freshly spawned bag's lifetime
}
GainConfig
{
float GlobalGainMultiplier = 1.0; // Speeds up/slows down all fatigue gainers
float GainNightMultiplier = 1.5; // These multipliers DO NOT stack (ie. at night AND inside = 2x gain, not 2.25x gain. The 1 is subtracted. Max multiplier if all conds are met is 2.5x)
float GainBedObjectUsed = 1.3; // 30% sleep speed boost
float GainInsideMultiplier = 1.1; // 10% sleep speed boost
float GainFromHeatBuffMultiplier = 1.1; // There are 3 stages of heat buffer, 1 = 33% of this value, 2 = 50% of this value, 3 = 100% of this value.
float MaxRestGain_Illness = 16; // 16% (yellow) max rest
float MaxRestGain_Temp_DarkBlueFlashing = 0; // Don't allow sleep
float MaxRestGain_Temp_DarkBlue = 0; // Don't allow sleep
float MaxRestGain_Temp_LightBlue = 70; // 70% (white with gap)
float MaxRestGain_Temp_Yellow = 70; // 70% (white with gap) max rest
float MaxRestGain_Temp_Red = 0; // Don't allow sleep
float MaxRestGain_Temp_RedFlashing = 0; // Don't allow sleep
float MaxRestGain_FoodWater_Yellow = 16; // 16% (yellow) Max rest possible with yellow food or water
float MaxRestGain_FoodWater_Red = 6; // 6% (red) Max rest possible with red food or water
float MaxRestGain_FoodWater_RedFlashing = 0; // 0% Max rest possible with red flashing food or water
float MaxRestGain_Wet = 16; // 16% (yellow) Max rest possible when wet
float MaxRestGain_Time_Daylight = 70; // 70% (white with gap) Max rest possible during daytime
float MaxRestGain_Time_Night = 100; // 100% (full white) Max rest possible at night time
float PercentGainedUponUncon = 1; // 1% (approx) Fatigue stat regained if player falls uncon while red or red flashing
float BedHeatBuffMaxGain = 10; // 10 = heatbuff stage 1, 30 = stage 3.
float BedHealthMaxGain = 100; // Maximum recoverable health when sleeping in a bed/sleeping bag (set to zero to disable)
float BedHealthGainPerSec = 0.25; // Health gain per second while sleeping in bed
float MinSecsAsleepInBedToTriggerImmunityBoost = 120; // Minimum seconds player needs to sleep to receive 5 minute immunity boost (set to zero to disable)
float MinSecsAsleepToTriggerHealthRecovery = 120; // Minimum seconds player needs to sleep to begin regaining health (if enabled)
}
DrainConfig
{
float GlobalDrainMultiplier = 1.0; // Speeds up/slows down all fatigue drainers
float DrainHeavyItemMultiplier = 1.0; // How much faster/slower to drain while carrying heavy item (eg. barrel)
float DrainWalkingMultiplier = 1.0; // Walking speed drain multiplier
float DrainJoggingMultiplier = 1.0; // Jogging speed drain (ie. normal W with no CTRL or shift pressed)
float DrainSprintingMultiplier = 1.0; // Full-sprint drain
float DrainWeightMultiplier = 1.0; // How much player weight affects drain (as a % of the stamina bar - the lower the stamina bar, the higher this multiplier is applied)
float DrainNightMultiplier = 1.5; // How much faster fatigue drains when the world is night time
float HealthLossPerSecRedFlashing = 0; // No health damage for zero fatigue left by default.
}
ModifiersConfig
{
ModifierDeactivatedPercent.Set("EpinephrineMdfr", -1); // 1% drain on energy
ModifierDeactivatedPercent.Set("MorphineMdfr", -1); // 1% drain on energy
ModifierDeactivatedPercent.Set("PainKillersMdfr", -0.5); // 0.5% drain on energy
ModifierDeactivatedPercent.Set("ContaminationStage3Mdfr", -100); // 100% drain on energy
ModifierDeactivatedPercent.Set("ZenSleep_Anesthetic", -100); // 100% drain on energy
ModifierActivatedPercent.Set("SodaCan_ColorBase", 1); // 1% gain on energy
ModifierActivatedPercent.Set("ZenSleep_Amphetamine", 100); // 100% gain on energy
ModifierPausesSeconds.Set("EpinephrineMdfr", 300); // Epi pauses sleep drain for 5 minutes
ModifierPausesSeconds.Set("ZenSleep_Amphetamine", 900); // Speed pauses sleep drain for 15 minutes
}
ServerEffectsConfig
{
float MinimumSecsBetweenYawnRedFlashing = 30; // Min seconds between triggering a yawn when red flashing fatigue
float MaximumSecsBetweenYawnRedFlashing = 300; // Max seconds between triggering a yawn when red flashing fatigue
float MinimumSecsBetweenYawnRed = 180; // Min seconds between triggering a yawn when red fatigue
float MaximumSecsBetweenYawnRed = 300; // Max seconds between triggering a yawn when red fatigue
float MinimumSecsBetweenSnore = 10; // Minimum seconds between triggering a snore sleep sound
float MaximumSecsBetweenSnore = 20; // Maximum seconds between triggering a snore sleep sound
float MinimumSecsBetweenUnconRedFlashing = 180; // Minimum seconds between possibly falling uncon when red flashing fatigue (affected by chance below)
float MaximumSecsBetweenUnconRedFlashing = 360; // Maximum seconds between possibly falling uncon when red flashing fatigue (affected by chance below)
float MinimumSecsBetweenUnconRed = 600; // Minimum seconds between possibly falling uncon when red fatigue (affected by chance below)
float MaximumSecsBetweenUnconRed = 900; // Maximum seconds between possibly falling uncon when red fatigue (affected by chance below)
float MaximumSecsBuzzedByCombat = 900; // Maximum seconds damage reduces your ability to sleep (ie. 90% total health damage = 90% of this value, does not pause fatigue drain and resets on logout)
float ChanceToSnoreSleeping = 90; // 90% chance to play snore sound when sleeping
float ChanceToYawnRedFlashing = 90; // 90% chance to yawn when red flashing fatigue
float ChanceToYawnRed = 25; // 25% chance to yawn when red fatigue
float ChanceToHallucinateRedFlashing = 100; // 100% chance to trigger hallucination visual effect when yawning while red flashing fatigue
float ChanceToHallucinateRed = 75; // 75% chance to trigger hallucination visual effect when yawning while red fatigue
float ChanceToUnconRedFlashing = 50; // 50% to fall uncon chance every ~3-6 minutes (based on above settings)
float ChanceToUnconRed = 1; // 1% chance every ~10-15 minutes (based on above settings)
bool CanUnconWhileDriving = true; // Turn on/off the ability to fall asleep while driving (based on above settings)
bool CanUnconWhileSwimming = false; // Turn on/off the ability to fall asleep while swimming
}
ClientEffectsConfig
{
float AmountToBlurWhenRedFlashing = 2; // Amount to blur the screen when red flashing fatigue (2% = very subtle)
float AmountToBlurWhenRed = 1; // Amount to blur the screen when red flashing fatigue (1% = extremely subtle)
float AmountToVignetteWhenRedFlashing = 50; // Amount to apply blackened corners of screen when red flashing fatigue (takes ~5 minutes at red flashing to reach this value)
float AmountToVignetteWhenRed = 25; // Amount to apply blackened corners of screen when red fatigue (takes ~5 minutes at red to reach this value)
float DelaySecsUntilAudioAttenuation = 60; // How long to wait after lying down to sleep before engaging sleep attenuation (set to zero to disable)
bool AllowInventoryWhileSleeping = true; // Allow player to access their inventory while sleeping (can't drop or use any items in hands)
bool AllowClosedEyesEffectSleeping = true; // Enables the "closing eyes" effect
bool AllowHallucinationEffectRedFlashing = true; // Enables the chroma hallucination effect when yawning while red flashing
bool AllowHallucinationEffectRed = true; // Enables the chroma hallucination effect when yawning while red fatigue
int CharacterMovementSpeedRedFlashing = 1; // Applies a character movement limitation when red flashing fatigue (0 = no effect, 1 = eInjuryHandlerLevels.WORN, 2 = DAMAGED, 3 = RUINED)
int CharacterMovementSpeedRed = 0; // Applies movement speed limitation when red fatigue (if above zero)
ref array<string> BedObjects; // List of bed objects the player can sleep on and receive benefits (heat buff/health gain/increased rest speed etc)
{
BedObjects.Insert("MediumTent");
BedObjects.Insert("LargeTent");
BedObjects.Insert("ZenSleepingBag_Base");
BedObjects.Insert("ZenSleepingBagStatic_Base");
}
}