BodyBags 2.0

Description
BodyBags replaces the player's corpse with a body bag after a configurable delay.
The dead player's inventory is virtualized into a JSON file, then restored into the body bag when the player uses the F action.
Virtualized body bags stay saved through server restarts until they are restored or deleted.

The mod was designed to avoid the usual desync issues and items dropping on the ground from clothing or backpacks after a restart.

How it works
- The player dies.
- After the configured delay, the corpse is replaced with an RA_BodyBag.
- The player's gear is saved to a JSON file.
- When the body bag is opened with the F action, the content is rebuilt in its original state.
- The JSON file is automatically deleted when the content is restored.
- If the body bag naturally disappears when its lifetime reaches 0, the JSON file is also automatically deleted.

Important
- You do not need to add the body bag to any types.xml.
- The RA_BodyBag is created by script when death happens.
- Content persistence is handled through JSON files in the server profile folder.
- The config.json file is created automatically, and any missing new settings are added without overwriting values already set by the server owner.
- BodyBags works on its own and does not require any other mod as a mandatory dependency.
- All integrations with other mods are optional.

Load order
- If you use BodyBags with Ninjins PvE/PvP, VanillaPlusPlusMap, Dogtags, DayZ Expansion Vehicles, or MuchCarKey, BodyBags should be loaded after those mods.
- In short: compatible mods first, then BodyBags.

Folders used in the server profile
- $profile:BodyBags/config
- $profile:BodyBags/data
- $profile:BodyBags/data_AI
- $profile:BodyBags/logs

Notes
- data stores player body bags.
- data_AI stores Expansion AI body bags.
- logs is only created if EnableLogs = 1.

Configuration file
On first launch, the mod automatically creates:
$profile:BodyBags/config/config.json

Default configuration:
{
    "EnableLogs": 0,
    "BodyBagMaxLifetime": 3600,
    "BodyBagPlayerCleanupTime": 180,
    "BodyBagOwnerOnlyAccess": 1,
    "TakeBodyBags": 0,
    "AutoDeleteFreshSpawnBodyBags": 0,
    "TimeMinSurvivalAfterFreshSpawn": 1800,
    "TimeToDeleteBodyBagAfterFreshSpawn": 900,
    "EnableVanillaPlusPlusMapDeadPosition": 0,
    "EnableAI_Expansion": 0,
    "BodyBagAIMaxLifetime": 1800,
    "BodyBagAICleanupTime": 10,
    "EnableNinjins_PVE_PVP": 0,
    "PVE": {
        "BodyBagOwnerOnlyAccess": 1,
        "BodyBagMaxLifetime": 3600,
        "BodyBagPlayerCleanupTime": 180,
        "TakeBodyBags": 0,
        "AutoDeleteFreshSpawnBodyBags": 0,
        "TimeMinSurvivalAfterFreshSpawn": 1800,
        "TimeToDeleteBodyBagAfterFreshSpawn": 900
    },
    "PVP": {
        "BodyBagOwnerOnlyAccess": 0,
        "BodyBagMaxLifetime": 3600,
        "BodyBagPlayerCleanupTime": 180,
        "TakeBodyBags": 0,
        "AutoDeleteFreshSpawnBodyBags": 0,
        "TimeMinSurvivalAfterFreshSpawn": 1800,
        "TimeToDeleteBodyBagAfterFreshSpawn": 900
    },
    "RAID": {
        "BodyBagOwnerOnlyAccess": 0,
        "BodyBagMaxLifetime": 3600,
        "BodyBagPlayerCleanupTime": 180,
        "TakeBodyBags": 0,
        "AutoDeleteFreshSpawnBodyBags": 0,
        "TimeMinSurvivalAfterFreshSpawn": 1800,
        "TimeToDeleteBodyBagAfterFreshSpawn": 900
    }
}

Parameter description

EnableLogs
WARNING WARNING WARNING
These are debug logs.
Only enable them if you want to debug the mod
or if you need to send the logs for support.
WARNING WARNING WARNING
- Type: 0 or 1
- Default: 0
- 0 = logs disabled
- 1 = logs enabled
- When enabled, the mod automatically creates $profile:BodyBags/logs and writes debug logs into it.

BodyBagMaxLifetime
- Type: integer in seconds
- Default: 3600
- Defines the maximum lifetime of a player body bag before it disappears naturally.

BodyBagPlayerCleanupTime
- Type: integer in seconds
- Default: 180
- Defines the delay between the player's death and the corpse being turned into a body bag.
- If the value is set to 0, the mod falls back to the original value: 180.

BodyBagOwnerOnlyAccess
- Type: 0 or 1
- Default: 1
- 1 = only the owner of the body bag can recover its content
- 0 = all players can loot a player body bag
- This setting applies to player body bags, not to Expansion AI loot rules.

TakeBodyBags
- Type: 0, 1, or 2
- Default: 0
- 0 = normal behavior, the body bag can be taken in hands and stored in inventory if its size allows it
- 1 = the body bag can be taken in hands, but cannot be stored in inventory or cargo
- 2 = the body bag cannot be taken in hands and cannot be stored in inventory or cargo

AutoDeleteFreshSpawnBodyBags
- Type: 0 or 1
- Default: 0
- 0 = no forced fresh-spawn delete timer
- 1 = if the player died before the TimeMinSurvivalAfterFreshSpawn threshold, the body bag gets a forced server-side delete timer
- This forced timer does not rely on the normal DayZ item lifetime behavior

TimeMinSurvivalAfterFreshSpawn
- Type: integer in seconds
- Default: 1800
- Defines the minimum survival time after spawn before a player is no longer treated as a fresh spawn
- If the player survived at least this long, the body bag goes back to its normal lifetime behavior

TimeToDeleteBodyBagAfterFreshSpawn
- Type: integer in seconds
- Default: 900
- Defines the forced delete delay for a fresh-spawn body bag
- If AutoDeleteFreshSpawnBodyBags = 1 and the player died before the configured survival threshold, this timer automatically deletes the body bag and its JSON file

EnableVanillaPlusPlusMapDeadPosition
- Type: 0 or 1
- Default: 0
- 0 = no V++ map integration
- 1 = the mod sends the player's death position to the V++ map cache to display a death marker
- This option is optional
- BodyBags has no required compile dependency on VanillaPlusPlusMap
- If V++ is not installed, BodyBags still works normally

EnableAI_Expansion
- Type: 0 or 1
- Default: 0
- 0 = no Expansion AI handling by BodyBags
- 1 = enables Expansion AI compatibility and AI body bags
- This option is optional
- BodyBags has no required compile dependency on DayZ Expansion AI

BodyBagAIMaxLifetime
- Type: integer in seconds
- Default: 1800
- Defines the maximum lifetime of an Expansion AI body bag.

BodyBagAICleanupTime
- Type: integer in seconds
- Default: 10
- Defines the delay between an Expansion AI death and the corpse being turned into a body bag.
- If the value is set to 0, the mod falls back to the original value: 10.

EnableNinjins_PVE_PVP
- Type: 0 or 1
- Default: 0
- 0 = global player settings are used
- 1 = for players, the PVE, PVP, or RAID blocks replace the global player settings
- When this option is enabled, the global player settings are no longer used for player body bags
- The mapping used by BodyBags is:
  SafeZone -> PVE
  Raid -> RAID
- If no zone profile can be resolved, BodyBags falls back to PVP behavior

PVE / PVP / RAID profiles
When EnableNinjins_PVE_PVP = 1, each PVE, PVP, and RAID block can define:
- BodyBagOwnerOnlyAccess
- BodyBagMaxLifetime
- BodyBagPlayerCleanupTime
- TakeBodyBags
- AutoDeleteFreshSpawnBodyBags
- TimeMinSurvivalAfterFreshSpawn
- TimeToDeleteBodyBagAfterFreshSpawn

Player body bag ownership
- A player body bag stores the dead player's identifier.
- If BodyBagOwnerOnlyAccess = 1, only that player can use the F action to restore the content.
- If BodyBagOwnerOnlyAccess = 0, the player body bag becomes lootable by everyone.
- If Ninjins is enabled, this can also be overridden by the PVE, PVP, or RAID profile based on the player's zone when they died.

Expansion AI body bags
- Expansion AI integration is optional.
- If EnableAI_Expansion = 1, Expansion AI can also turn into body bags.
- AI JSON files are stored in $profile:BodyBags/data_AI.
- AI body bag lootability follows the CanBeLooted setting already defined in Expansion AI.
- If an Expansion AI is configured as not lootable, its body bag should also be not lootable.

Fresh-spawn body bag deletion
- If AutoDeleteFreshSpawnBodyBags = 0, the body bag always uses its normal lifetime, regardless of how long the player survived.
- If AutoDeleteFreshSpawnBodyBags = 1:
  - if the player survived less than TimeMinSurvivalAfterFreshSpawn, the body bag gets a forced delete timer of TimeToDeleteBodyBagAfterFreshSpawn
  - if the player survived at least TimeMinSurvivalAfterFreshSpawn, the body bag uses its normal lifetime
- The fresh-spawn timer is a scripted server-side hard delete
- It does not depend on vanilla item lifetime behavior or nearby players
- It also keeps working after a server restart or player relog
- With Ninjins enabled, this logic also follows the player's PVE, PVP, or RAID profile.

Logs
- Logs are disabled by default.
- If EnableLogs = 1, logs are written to:
  $profile:BodyBags/logs
- If EnableLogs = 0, the mod does not create the logs folder.

JSON data
Each virtualized body bag creates a JSON file in:
- $profile:BodyBags/data for players
- $profile:BodyBags/data_AI for Expansion AI

The JSON includes:
- the date
- the time
- the dead player's SteamID or Player ID when available
- the dead player's name
- the full virtualized content of the body bag

VanillaPlusPlusMap compatibility
V++ integration is optional.
When EnableVanillaPlusPlusMapDeadPosition = 1:
- the dead player receives their death position
- the mod writes a V++ compatible marker using the icon:
  BodyBags\data\skull_64x64.paa

The goal is to make BodyBags compatible with V++ without forcing V++ as a dependency.
- If you use VanillaPlusPlusMap, load BodyBags after VanillaPlusPlusMap.

Dogtags / Expansion Vehicles / MuchCarKey compatibility
- BodyBags includes optional compatibility for Dogtags, DayZ Expansion vehicle keys, and MuchCarKey.
- To make sure these integrations work correctly, load BodyBags after those mods.

Example of adding modded slots to the BodyBag
If you want to add modded slots to the body bag, do it through a separate override mod loaded after BodyBags.
Do not directly edit the mod's config.cpp if you want to keep a clean base for future updates.

Override example:

class CfgPatches
{
    class MyBodyBagSlotsOverride
    {
        units[] = {};
        weapons[] = {};
        requiredVersion = 0.1;
        requiredAddons[] = {"RearmedServer_Gear_BodyBag"};
    };
};

class CfgVehicles
{
    class RA_BodyBag_Base;
    class RA_BodyBag_Base: RA_BodyBag_Base
    {
        itemSize[] = {3,3};
        attachments[] =
        {
            "Shoulder",
            "Melee",
            "Vest",
            "Body",
            "Hips",
            "Legs",
            "Back",
            "Headgear",
            "Mask",
            "Eyewear",
            "Gloves",
            "Feet",
            "Armband",
            "ModdedSlot",
            "ModdedSlot",
            "ModdedSlot",
            "ModdedSlot",
            "ModdedSlot"
        };
    };
};

Override notes
- Replace the modded slots with the ones actually used on your server.
- The slot must exist in the other loaded mods, otherwise it will not do anything.
- Load your override after BodyBags.

Summary
- No need to add the body bag to types.xml
- The mod creates and manages its body bags by script
- Configuration is handled through the server profile
- Body bag data is saved as JSON
- Virtualized body bags are preserved through server restarts
- Player and AI body bags are separated in data and data_AI
- Body bag pickup behavior can be configured through TakeBodyBags
- Fresh-spawn body bags can be deleted automatically through a forced server-side timer
- V++ integration is optional
- Expansion AI integration is optional
- Ninjins PVE/PVP integration is optional
- The mod works without any mandatory dependency
- If you use Ninjins, V++, Dogtags, Expansion Vehicles, or MuchCarKey, load BodyBags after them
