Skip to content

02 How persistence works

drzdo edited this page Oct 5, 2023 · 4 revisions

Basics

When in-game player requests saving the game

  • by typing in chat /save
  • or by typing in debug console call zdo_persist_save_fnc_saveAllAndShowMessage;

the scripts set some variables and wait for 5 seconds for them to synchronize.

Maybe, waiting is redundant but I didn't dig deeper.

Anyway, after ~5 seconds, the game is saved to your local computer (to profileNamespace).

You can check it out by typing

profileNamespace getVariable ["zdo_mission", ""];

The idea is to save as much as possible, so later in 3den editor the mission creator can do whatever they want with it to make the next mission.

What is saved? A lot of stuff:

private _savedData = [
    ["save_time", format (["%1-%2-%3-%4-%5-%6"] + systemTimeUTC)],
    ["player_info_tracker", [_pit] call zdo_persist_save_fnc_saveZdoVariables],
    ["kill_tracker", [_kt] call zdo_persist_save_fnc_saveZdoVariables],
    ["objects", _objects],
    ["mines", call zdo_persist_save_fnc_saveMines],
    ["map", call zdo_persist_save_fnc_copyMapMarkers],
    ["destroyed_terrain_objects", call zdo_persist_save_fnc_saveDestroyedTerrainObjects],
    ["units", call zdo_persist_save_fnc_saveUnits]
];
  • players' position, loadout, ACE medical
  • where last 100 kills were happening so the blood sprites can be placed there
  • all manually placed "static" objects like ACE trenches, ACE fortify buildings, Zeus placed things, static MG, custom buildings, etc.
  • all crates/containers with inventory in them
  • all active mines
  • all map markers
  • if fence/wall/tree/etc was destroyed by the tank/explosion/whatever - it will be saved as well
  • destroyed buildings
  • ACE rallypoint
  • all vehicles (position, fuel, damage, inventory)
  • all units (position, loadout, ACE medical, role in vehicles)

Inventory

Inventory of any player, vehicle and crate/box is persistent.

A player can have a backpack with a rifle with plenty of attachments. When the player puts the backpack to the crate - nothing changes, the backpack with all its items is in there.

But when the inventory is being saved, all nesting is removed. Basically, instead of having a tree

Backpack
    Rifle
        Scope
        Silencer

this is what is being saved:

backpack
rifle
scope
silencer

This is the easiest way to make things persistent. Saving and restoring the nested items is possible but tedious to implement.

Basically, if the player puts a backpack with a rifle with a scope in the container - after saving and loading the inventory will have four separate items.

Now, if a player wants to get his loadout back - they would need to repack everything manually: put scope on a rifle, put rifle to the backpack. This is tedious, therefore there is a way to make this container "an arsenal" (check out "Custom ACE Arsenal" wiki page).

Units in vehicles

When unit is in vehicle and gets loaded in 3den editor, the unit does not look placed correctly in the vehicle:

image

This is because there is no public function to place unit in the vehicle in 3den.

To fix this, each of those guys get custom init field. When mission starts, this custom init code places unit in the correct role/turret in a vehicle.