Zenarchist

DayZ CF Persistence Code Template

Apr 29th, 2026
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. // CPP FILE:
  2.  
  3. class CfgPatches
  4. {
  5.     class _YOUR_MOD_NAME_REPLACEME_
  6.     {
  7.         requiredAddons[] =
  8.         {
  9.             "DZ_Data",
  10.             "DZ_Scripts",
  11.             "JM_CF_Scripts"
  12.         };
  13.     };
  14. };
  15.  
  16. class CfgMods
  17. {
  18.     class _YOUR_MOD_NAME_REPLACEME_
  19.     {
  20.         storageVersion = 1; // CF storage
  21.     };
  22. };
  23.  
  24. // USE CF_Load/Save because this will NOT break server persistence if the mod is added/removed mid-wipe.
  25. // NOTE: storage[] must refer to this mod's CfgMods classname EXACTLY or this won't work.
  26. // Version control is handled in mod.cpp's storageVersion = X; value in CfgMods.
  27.  
  28. override void CF_OnStoreSave(CF_ModStorageMap storage)
  29. {
  30.     super.CF_OnStoreSave(storage);
  31.  
  32.     auto ctx = storage["_YOUR_MOD_NAME_REPLACEME_"];
  33.     if (!ctx) return;
  34.    
  35.     ctx.Write(_YOUR_VARIABLE_);
  36. }
  37.  
  38. override bool CF_OnStoreLoad(CF_ModStorageMap storage)
  39. {
  40.     if (!super.CF_OnStoreLoad(storage)) return false;
  41.  
  42.     auto ctx = storage["_YOUR_MOD_NAME_REPLACEME_"];
  43.     if (!ctx) return true;
  44.  
  45.     if (ctx.GetVersion() >= 1)
  46.     {
  47.         if (!ctx.Read(_YOUR_VARIABLE_)) return false;
  48.     }
  49.  
  50.     return true;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment