Advertisement
Guest User

savemanager.sqf

a guest
Oct 7th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 13.60 KB | None | 0 0
  1. if ( !(isNil "GRLIB_param_wipe_savegame_1") && !(isNil "GRLIB_param_wipe_savegame_2") ) then {
  2.     if ( GRLIB_param_wipe_savegame_1 == 1 && GRLIB_param_wipe_savegame_2 == 1 ) then {
  3.         profileNamespace setVariable [ GRLIB_save_key,nil ];
  4.         saveProfileNamespace;
  5.     };
  6. };
  7.  
  8. date_year = date select 0;
  9. date_month = date select 1;
  10. date_day = date select 2;
  11. blufor_sectors = [];
  12. GRLIB_all_fobs = [];
  13. buildings_to_save= [];
  14. combat_readiness = 0;
  15. saved_ammo_res = 0;
  16. stats_opfor_soldiers_killed = 0;
  17. stats_opfor_killed_by_players = 0;
  18. stats_blufor_soldiers_killed = 0;
  19. stats_player_deaths = 0;
  20. stats_opfor_vehicles_killed = 0;
  21. stats_opfor_vehicles_killed_by_players = 0;
  22. stats_blufor_vehicles_killed = 0;
  23. stats_blufor_soldiers_recruited = 0;
  24. stats_blufor_vehicles_built = 0;
  25. stats_civilians_killed = 0;
  26. stats_civilians_killed_by_players = 0;
  27. stats_sectors_liberated = 0;
  28. stats_playtime = 0;
  29. stats_spartan_respawns = 0;
  30. stats_secondary_objectives = 0;
  31. stats_hostile_battlegroups = 0;
  32. stats_ieds_detonated = 0; publicVariable "stats_ieds_detonated";
  33. stats_saves_performed = 0;
  34. stats_saves_loaded = 0;
  35. stats_reinforcements_called = 0;
  36. stats_prisonners_captured = 0;
  37. stats_blufor_teamkills = 0;
  38. stats_vehicles_recycled = 0;
  39. stats_ammo_spent = 0;
  40. stats_sectors_lost = 0;
  41. stats_fobs_built = 0;
  42. stats_fobs_lost = 0;
  43. stats_readiness_earned = 0;
  44. infantry_weight = 33;
  45. armor_weight = 33;
  46. air_weight = 33;
  47. GRLIB_vehicle_to_military_base_links = [];
  48. GRLIB_permissions = [];
  49. ai_groups = [];
  50. saved_intel_res = 0;
  51. GRLIB_player_scores = [];
  52.  
  53. no_kill_handler_classnames = [FOB_typename, TransportHeli_typename];
  54. _classnames_to_save = [FOB_typename, TransportHeli_typename];
  55. _classnames_to_save_blu = [];
  56. _building_classnames = [FOB_typename];
  57. {
  58.     no_kill_handler_classnames pushback (_x select 0);
  59.     _classnames_to_save pushback (_x select 0);
  60.     _building_classnames pushback (_x select 0);
  61. } foreach buildings;
  62.  
  63. {
  64.     _classnames_to_save_blu pushback (_x select 0);
  65. } foreach (static_vehicles + air_vehicles + heavy_vehicles + light_vehicles + support_vehicles);
  66.  
  67. _classnames_to_save = _classnames_to_save + _classnames_to_save_blu + all_hostile_classnames;
  68.  
  69. trigger_server_save = false;
  70. greuh_liberation_savegame = profileNamespace getVariable GRLIB_save_key;
  71.  
  72. if ( !isNil "greuh_liberation_savegame" ) then {
  73.  
  74.     blufor_sectors = greuh_liberation_savegame select 0;
  75.     GRLIB_all_fobs = greuh_liberation_savegame select 1;
  76.     buildings_to_save = greuh_liberation_savegame select 2;
  77.     time_of_day = greuh_liberation_savegame select 3;
  78.     combat_readiness = greuh_liberation_savegame select 4;
  79.     saved_ammo_res = greuh_liberation_savegame select 8;
  80.  
  81.     if ( "capture_13_1_2_26_25" in blufor_sectors ) then { // Patching Molos Airfield which was a town instead of a factory
  82.         blufor_sectors = blufor_sectors - [ "capture_13_1_2_26_25" ];
  83.         blufor_sectors = blufor_sectors + [ "factory666" ];
  84.     };
  85.  
  86.     if ( count greuh_liberation_savegame > 9 ) then {
  87.         _stats = greuh_liberation_savegame select 9;
  88.         stats_opfor_soldiers_killed = _stats select 0;
  89.         stats_opfor_killed_by_players = _stats select 1;
  90.         stats_blufor_soldiers_killed = _stats select 2;
  91.         stats_player_deaths = _stats select 3;
  92.         stats_opfor_vehicles_killed = _stats select 4;
  93.         stats_opfor_vehicles_killed_by_players = _stats select 5;
  94.         stats_blufor_vehicles_killed = _stats select 6;
  95.         stats_blufor_soldiers_recruited = _stats select 7;
  96.         stats_blufor_vehicles_built = _stats select 8;
  97.         stats_civilians_killed = _stats select 9;
  98.         stats_civilians_killed_by_players = _stats select 10;
  99.         stats_sectors_liberated = _stats select 11;
  100.         stats_playtime = _stats select 12;
  101.         stats_spartan_respawns = _stats select 13;
  102.         stats_secondary_objectives = _stats select 14;
  103.         stats_hostile_battlegroups = _stats select 15;
  104.         stats_ieds_detonated = _stats select 16; publicVariable "stats_ieds_detonated";
  105.         stats_saves_performed = _stats select 17;
  106.         stats_saves_loaded = _stats select 18;
  107.         stats_reinforcements_called = _stats select 19;
  108.         stats_prisonners_captured = _stats select 20;
  109.         stats_blufor_teamkills = _stats select 21;
  110.         stats_vehicles_recycled = _stats select 22;
  111.         stats_ammo_spent = _stats select 23;
  112.         stats_sectors_lost = _stats select 24;
  113.         stats_fobs_built = _stats select 25;
  114.         stats_fobs_lost = _stats select 26;
  115.         stats_readiness_earned = _stats select 27;
  116.     };
  117.  
  118.     if ( count greuh_liberation_savegame > 10 ) then {
  119.         _weights = greuh_liberation_savegame select 10;
  120.         infantry_weight = _weights select 0;
  121.         armor_weight = _weights select 1;
  122.         air_weight = _weights select 2;
  123.     };
  124.  
  125.     if ( count greuh_liberation_savegame > 11 ) then {
  126.         GRLIB_vehicle_to_military_base_links = greuh_liberation_savegame select 11;
  127.     };
  128.  
  129.     if ( count greuh_liberation_savegame > 12 ) then {
  130.         GRLIB_permissions = greuh_liberation_savegame select 12;
  131.     };
  132.  
  133.     if ( count greuh_liberation_savegame > 13 ) then {
  134.         ai_groups = greuh_liberation_savegame select 13;
  135.     };
  136.  
  137.     if ( count greuh_liberation_savegame > 14 ) then {
  138.         saved_intel_res = greuh_liberation_savegame select 14;
  139.     };
  140.  
  141.     if ( count greuh_liberation_savegame > 15 ) then {
  142.         GRLIB_player_scores = greuh_liberation_savegame select 15;
  143.     };
  144.  
  145.     setDate [ 2045, 6, 6, time_of_day, 0];
  146.  
  147.     _correct_fobs = [];
  148.     {
  149.         _next_fob = _x;
  150.         _keep_fob = true;
  151.         {
  152.             if ( _next_fob distance (markerpos _x) < 50 ) exitWith { _keep_fob = false };
  153.         } foreach sectors_allSectors;
  154.         if ( _keep_fob ) then { _correct_fobs pushback _next_fob };
  155.     } foreach GRLIB_all_fobs;
  156.     GRLIB_all_fobs = _correct_fobs;
  157.  
  158.     stats_saves_loaded = stats_saves_loaded + 1;
  159.  
  160.     {
  161.         _nextclass = _x select 0;
  162.  
  163.         // if ( _nextclass in _classnames_to_save ) then {
  164.  
  165.             _nextpos = _x select 1;
  166.             _nextdir = _x select 2;
  167.             _hascrew = false;
  168.             if ( count _x > 3 ) then {
  169.                 _hascrew = _x select 3;
  170.             };
  171.             _nextbuilding = _nextclass createVehicle _nextpos;
  172.             _nextbuilding setVectorUp [0,0,1];
  173.             _nextbuilding setPosATL _nextpos;
  174.             _nextbuilding setdir _nextdir;
  175.             _nextbuilding setdamage 0;
  176.  
  177.             if ( _nextclass in _building_classnames ) then {
  178.                 _nextbuilding setVariable [ "GRLIB_saved_pos", _nextpos, false ];
  179.             };
  180.  
  181.             if ( _hascrew ) then {
  182.                 [ _nextbuilding ] call F_forceBluforCrew;
  183.             };
  184.  
  185.             if ( !(_nextclass in no_kill_handler_classnames ) ) then {
  186.                 _nextbuilding addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
  187.             };
  188.  
  189.             if ( _nextclass in all_hostile_classnames ) then {
  190.                 _nextbuilding setVariable [ "GRLIB_captured", 1, true ];
  191.             };
  192.  
  193.             if ( _nextclass == FOB_typename ) then {
  194.                 _nextbuilding addEventHandler ["HandleDamage", { 0 }];
  195.             };
  196.         // };
  197.  
  198.     } foreach buildings_to_save;
  199.  
  200.     {
  201.         private [ "_nextgroup", "_grp" ];
  202.         _nextgroup = _x;
  203.         _grp = createGroup GRLIB_side_friendly;
  204.  
  205.         {
  206.             private [ "_nextunit", "_nextpos", "_nextdir", "_nextobj", "_thisunit"];
  207.             _nextunit = _x;
  208.             _nextpos = [(_nextunit select 1) select 0, (_nextunit select 1) select 1, ((_nextunit select 1) select 2) + 0.2];
  209.             _nextdir = _nextunit select 2;
  210.             _thisunit = (_nextunit select 0) createUnit [ _nextpos, _grp, 'this addMPEventHandler ["MPKilled", {_this spawn kill_manager}] '];
  211.             _nextobj = ((units _grp) select ((count (units _grp)) - 1));
  212.             _nextobj setPosATL _nextpos;
  213.             _nextobj setDir _nextdir;
  214.             if (count _nextunit > 3) then {
  215.                 _thisunit setVariable ["playerowner",(_nextunit select 3),true];
  216.             };
  217.         } foreach _nextgroup;
  218.     } foreach ai_groups;
  219. };
  220.  
  221. publicVariable "blufor_sectors";
  222. publicVariable "GRLIB_all_fobs";
  223.  
  224. if ( count GRLIB_vehicle_to_military_base_links == 0 ) then {
  225.     private [ "_assigned_bases", "_assigned_vehicles", "_nextbase", "_nextvehicle" ];
  226.     _assigned_bases = [];
  227.     _assigned_vehicles = [];
  228.  
  229.     while { count _assigned_bases < count sectors_military && count _assigned_vehicles < count elite_vehicles } do {
  230.         _nextbase =  ( [ sectors_military, { !(_x in _assigned_bases) } ] call BIS_fnc_conditionalSelect ) call BIS_fnc_selectRandom;
  231.         _nextvehicle =  ( [ elite_vehicles, { !(_x in _assigned_vehicles) } ] call BIS_fnc_conditionalSelect ) call BIS_fnc_selectRandom;
  232.         _assigned_bases pushback _nextbase;
  233.         _assigned_vehicles pushback _nextvehicle;
  234.         GRLIB_vehicle_to_military_base_links pushback [_nextvehicle, _nextbase];
  235.     };
  236. } else {
  237.     _classnames_to_check = GRLIB_vehicle_to_military_base_links;
  238.     {
  239.         if ( ! ( [ _x select 0 ] call F_checkClass ) ) then {
  240.             GRLIB_vehicle_to_military_base_links = GRLIB_vehicle_to_military_base_links - [_x];
  241.         };
  242.     } foreach _classnames_to_check;
  243. };
  244. publicVariable "GRLIB_vehicle_to_military_base_links";
  245. publicVariable "GRLIB_permissions";
  246. save_is_loaded = true; publicVariable "save_is_loaded";
  247.  
  248. while { true } do {
  249.     waitUntil {
  250.         sleep 0.3;
  251.         trigger_server_save || GRLIB_endgame == 1;
  252.     };
  253.  
  254.     if ( GRLIB_endgame == 1 ) then {
  255.         profileNamespace setVariable [ GRLIB_save_key, nil ];
  256.         saveProfileNamespace;
  257.         while { true } do { sleep 300; };
  258.     } else {
  259.  
  260.         trigger_server_save = false;
  261.         buildings_to_save = [];
  262.         ai_groups = [];
  263.  
  264.         _all_buildings = [];
  265.         {
  266.             _fobpos = _x;
  267.             _nextbuildings = _fobpos nearobjects (GRLIB_fob_range * 2) select {
  268.                 //((typeof _x) in _classnames_to_save ) &&
  269.                 (_x in allMissionObjects "all") &&
  270.                 ( alive _x) &&
  271.                 ( speed _x < 5 ) &&
  272.                 ( isNull attachedTo _x ) &&
  273.                 (((getpos _x) select 2) < 10 ) &&
  274.                 ( getObjectType _x >= 8 ) &&
  275.                 !( _x isKindOf "Man" )
  276.             };
  277.  
  278.             _all_buildings = _all_buildings + _nextbuildings;
  279.  
  280.             {
  281.                 _nextgroup = _x;
  282.                 if (  side _nextgroup == GRLIB_side_friendly ) then {
  283.  
  284.                         if ( { alive _x } count ( units _nextgroup ) > 0  ) then {
  285.                             if ( _fobpos distance (leader _nextgroup) < GRLIB_fob_range * 2 ) then {
  286.                                 if ( { isPlayer _x } count ( units _nextgroup ) == 0 ) then {
  287.                                     private [ "_grouparray" ];
  288.                                     _grouparray = [];
  289.                                     {
  290.                                         if ( alive _x && (vehicle _x == _x ) ) then {
  291.                                             _grouparray pushback [ typeof _x, getPosATL _x, getDir _x ];
  292.                                         };
  293.                                     } foreach (units _nextgroup);
  294.  
  295.                                     ai_groups pushback _grouparray;
  296.                                 } else {
  297.                                     if (isPlayer (leader _nextgroup)) then {
  298.                                         private [ "_grouparray","_leaderuid" ];
  299.                                         _grouparray = [];
  300.                                         _leaderuid = getPlayerUID (leader _nextgroup);
  301.                                         {
  302.                                             if ( alive _x && (vehicle _x == _x ) && !(isPlayer _x) ) then {
  303.                                                 _grouparray pushback [ typeof _x, getPosATL _x, getDir _x, _leaderuid ];
  304.                                                 _x setVariable ["playerowner",_leaderuid,true];
  305.                                             };
  306.                                         } foreach (units _nextgroup);
  307.  
  308.                                     };
  309.                                 };
  310.                             };
  311.                         };
  312.                 };
  313.             } foreach allGroups;
  314.         } foreach GRLIB_all_fobs;
  315.  
  316.         {
  317.             private _savedpos = [];
  318.  
  319.             /*if ( (typeof _x) in _building_classnames ) then {
  320.                 _savedpos = _x getVariable [ "GRLIB_saved_pos", [] ];
  321.                 if ( count _savedpos == 0 ) then {
  322.                     _x setVariable [ "GRLIB_saved_pos", getposATL _x, false ];
  323.                     _savedpos = getposATL _x;
  324.                 };
  325.             } else {
  326.                 _savedpos = getposATL _x;
  327.             };*/
  328.             _savedpos = getposATL _x;
  329.  
  330.             private _nextclass = typeof _x;
  331.             private _nextdir = getdir _x;
  332.             private _hascrew = false;
  333.             if ( _nextclass in _classnames_to_save_blu ) then {
  334.                 if ( ( { !isPlayer _x } count (crew _x) ) > 0 ) then {
  335.                     _hascrew = true;
  336.                 };
  337.             };
  338.             buildings_to_save pushback [ _nextclass,_savedpos,_nextdir,_hascrew ];
  339.         } foreach _all_buildings;
  340.  
  341.         time_of_day = date select 3;
  342.  
  343.         stats_saves_performed = stats_saves_performed + 1;
  344.  
  345.         private [ "_newscores", "_knownplayers", "_playerindex", "_nextplayer" ];
  346.         _knownplayers = [];
  347.         _newscores = [] + GRLIB_player_scores;
  348.         { _knownplayers pushback (_x select 0) } foreach GRLIB_player_scores;
  349.  
  350.         {
  351.             _nextplayer = _x;
  352.  
  353.             if ( score _nextplayer >= 20 ) then {
  354.                 _playerindex = _knownplayers find (getPlayerUID _nextplayer);
  355.                 if ( _playerindex >= 0 ) then {
  356.                     _newscores set [ _playerindex, [ getPlayerUID _x, score _x] ];
  357.                 } else {
  358.                     _newscores pushback [ getPlayerUID _x, score _x ];
  359.                 };
  360.             };
  361.         } foreach allPlayers;
  362.         GRLIB_player_scores = _newscores;
  363.  
  364.         _stats = [];
  365.         _stats pushback stats_opfor_soldiers_killed;
  366.         _stats pushback stats_opfor_killed_by_players;
  367.         _stats pushback stats_blufor_soldiers_killed;
  368.         _stats pushback stats_player_deaths;
  369.         _stats pushback stats_opfor_vehicles_killed;
  370.         _stats pushback stats_opfor_vehicles_killed_by_players;
  371.         _stats pushback stats_blufor_vehicles_killed;
  372.         _stats pushback stats_blufor_soldiers_recruited;
  373.         _stats pushback stats_blufor_vehicles_built;
  374.         _stats pushback stats_civilians_killed;
  375.         _stats pushback stats_civilians_killed_by_players;
  376.         _stats pushback stats_sectors_liberated;
  377.         _stats pushback stats_playtime;
  378.         _stats pushback stats_spartan_respawns;
  379.         _stats pushback stats_secondary_objectives;
  380.         _stats pushback stats_hostile_battlegroups;
  381.         _stats pushback stats_ieds_detonated;
  382.         _stats pushback stats_saves_performed;
  383.         _stats pushback stats_saves_loaded;
  384.         _stats pushback stats_reinforcements_called;
  385.         _stats pushback stats_prisonners_captured;
  386.         _stats pushback stats_blufor_teamkills;
  387.         _stats pushback stats_vehicles_recycled;
  388.         _stats pushback stats_ammo_spent;
  389.         _stats pushback stats_sectors_lost;
  390.         _stats pushback stats_fobs_built;
  391.         _stats pushback stats_fobs_lost;
  392.         _stats pushback stats_readiness_earned;
  393.  
  394.         greuh_liberation_savegame = [ blufor_sectors, GRLIB_all_fobs, buildings_to_save, time_of_day, round combat_readiness,0,0,0, round resources_ammo, _stats,
  395.         [ round infantry_weight, round armor_weight, round air_weight ], GRLIB_vehicle_to_military_base_links, GRLIB_permissions, ai_groups, resources_intel, GRLIB_player_scores ];
  396.  
  397.         profileNamespace setVariable [ GRLIB_save_key, greuh_liberation_savegame ];
  398.         saveProfileNamespace;
  399.  
  400.     };
  401. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement