Advertisement
Guest User

server_monitor.sqf ArmA 2 OA OverPoch Vehicle Save Issue

a guest
Dec 23rd, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.41 KB | None | 0 0
  1. private ["_nul","_result","_pos","_wsDone","_dir","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_hitPoints","_fuel","_damage","_key","_vehLimit","_hiveResponse","_objectCount","_codeCount","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0","_bQty","_vQty","_BuildingQueue","_objectQueue","_superkey","_shutdown","_res","_hiveLoaded"];
  2.  
  3. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  4. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  5.  
  6. _hiveLoaded = false;
  7.  
  8. waitUntil{initialized}; //means all the functions are now defined
  9.  
  10. diag_log "HIVE: Starting";
  11.  
  12. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  13.  
  14. // Custom Configs
  15. if(isnil "MaxVehicleLimit") then {
  16. MaxVehicleLimit = 50;
  17. };
  18.  
  19. if(isnil "MaxDynamicDebris") then {
  20. MaxDynamicDebris = 100;
  21. };
  22. if(isnil "MaxAmmoBoxes") then {
  23. MaxAmmoBoxes = 3;
  24. };
  25. if(isnil "MaxMineVeins") then {
  26. MaxMineVeins = 50;
  27. };
  28. // Custon Configs End
  29.  
  30. if (isServer && isNil "sm_done") then {
  31.  
  32. serverVehicleCounter = [];
  33. _hiveResponse = [];
  34.  
  35. for "_i" from 1 to 5 do {
  36. diag_log "HIVE: trying to get objects";
  37. _key = format["CHILD:302:%1:", dayZ_instance];
  38. _hiveResponse = _key call server_hiveReadWrite;
  39. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")})) then {
  40. if ((_hiveResponse select 1) == "Instance already initialized") then {
  41. _superkey = profileNamespace getVariable "SUPERKEY";
  42. _shutdown = format["CHILD:400:%1:", _superkey];
  43. _res = _shutdown call server_hiveReadWrite;
  44. diag_log ("HIVE: attempt to kill.. HiveExt response:"+str(_res));
  45. } else {
  46. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  47.  
  48. };
  49. _hiveResponse = ["",0];
  50. }
  51. else {
  52. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  53. _i = 99; // break
  54. };
  55. };
  56.  
  57. _BuildingQueue = [];
  58. _objectQueue = [];
  59.  
  60. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  61.  
  62. // save superkey
  63. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  64.  
  65. _hiveLoaded = true;
  66.  
  67. diag_log ("HIVE: Commence Object Streaming...");
  68. _key = format["CHILD:302:%1:", dayZ_instance];
  69. _objectCount = _hiveResponse select 1;
  70. _bQty = 0;
  71. _vQty = 0;
  72. for "_i" from 1 to _objectCount do {
  73. _hiveResponse = _key call server_hiveReadWriteLarge;
  74. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  75. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  76. _BuildingQueue set [_bQty,_hiveResponse];
  77. _bQty = _bQty + 1;
  78. } else {
  79. _objectQueue set [_vQty,_hiveResponse];
  80. _vQty = _vQty + 1;
  81. };
  82. };
  83. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  84. };
  85.  
  86. // # NOW SPAWN OBJECTS #
  87. _totalvehicles = 0;
  88. PVDZE_EvacChopperFields = [];
  89. {
  90. _idKey = _x select 1;
  91. _type = _x select 2;
  92. _ownerID = _x select 3;
  93.  
  94. _worldspace = _x select 4;
  95. _intentory = _x select 5;
  96. _hitPoints = _x select 6;
  97. _fuel = _x select 7;
  98. _damage = _x select 8;
  99.  
  100. _dir = 0;
  101. _pos = [0,0,0];
  102. _wsDone = false;
  103. if (count _worldspace >= 2) then
  104. {
  105. //CUSTOM VECTOR
  106. if ((typeName (_worldspace select 0)) == "STRING") then {
  107. _worldspace set [0, call compile (_worldspace select 0)];
  108. _worldspace set [1, call compile (_worldspace select 1)];
  109. };
  110.  
  111. //END
  112. _dir = _worldspace select 0;
  113. if (count (_worldspace select 1) == 3) then {
  114. _pos = _worldspace select 1;
  115. _wsDone = true;
  116. }
  117. };
  118.  
  119. if (!_wsDone) then {
  120. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  121. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  122. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  123. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  124. };
  125. //CUSTOM VECTOR START
  126. _vector = [[0,0,0],[0,0,0]];
  127. _vecExists = false;
  128. _ownerPUID = "0";
  129. if (count _worldspace >= 3) then{
  130. if(count _worldspace == 3) then{
  131. if(typename (_worldspace select 2) == "STRING")then{
  132. _ownerPUID = _worldspace select 2;
  133. }else{
  134. if(typename (_worldspace select 2) == "ARRAY")then{
  135. _vector = _worldspace select 2;
  136. if(count _vector == 2)then{
  137. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  138. _vecExists = true;
  139. };
  140. };
  141. };
  142. };
  143.  
  144. }else{
  145. //Was not 3 elements, so check if 4 or more
  146. if(count _worldspace == 4) then{
  147. if(typename (_worldspace select 3) == "STRING")then{
  148. _ownerPUID = _worldspace select 3;
  149. }else{
  150. if(typename (_worldspace select 2) == "STRING")then{
  151. _ownerPUID = _worldspace select 2;
  152. };
  153. };
  154.  
  155.  
  156. if(typename (_worldspace select 2) == "ARRAY")then{
  157. _vector = _worldspace select 2;
  158. if(count _vector == 2)then{
  159. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  160. _vecExists = true;
  161. };
  162. };
  163. }else{
  164. if(typename (_worldspace select 3) == "ARRAY")then{
  165. _vector = _worldspace select 3;
  166. if(count _vector == 2)then{
  167. if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  168. _vecExists = true;
  169. };
  170. };
  171. };
  172. };
  173.  
  174. }else{
  175. //More than 3 or 4 elements found
  176. //Might add a search for the vector, ownerPUID will equal 0
  177. };
  178. };
  179. };
  180.  
  181. // diag_log format["Server_monitor: [ObjectID = %1] [ClassID = %2] [_ownerPUID = %3]", _idKey, _type, _ownerPUID];
  182.  
  183. //CUSTOM VECTOR END
  184. if (_damage < 1) then {
  185. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  186.  
  187. //Create it
  188. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  189.  
  190. /*Door Management Start*/
  191. if (typeOf (_object) in DZE_DoorsLocked) then {
  192. _object setVariable ["doorfriends", _intentory, true];
  193. };
  194. /*Door Management End*/
  195.  
  196. _object setVariable ["lastUpdate",time];
  197. _object setVariable ["ObjectID", _idKey, true];
  198.  
  199. /*Plot Management Start*/
  200. if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then {
  201. _object setVariable ["plotfriends", _intentory, true];
  202. };
  203. /*Plot Management End*/
  204.  
  205. _lockable = 0;
  206. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  207. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  208. };
  209.  
  210. // fix for leading zero issues on safe codes after restart
  211. if (_lockable == 4) then {
  212. _codeCount = (count (toArray _ownerID));
  213. if(_codeCount == 3) then {
  214. _ownerID = format["0%1", _ownerID];
  215. };
  216. if(_codeCount == 2) then {
  217. _ownerID = format["00%1", _ownerID];
  218. };
  219. if(_codeCount == 1) then {
  220. _ownerID = format["000%1", _ownerID];
  221. };
  222. };
  223.  
  224. if (_lockable == 3) then {
  225. _codeCount = (count (toArray _ownerID));
  226. if(_codeCount == 2) then {
  227. _ownerID = format["0%1", _ownerID];
  228. };
  229. if(_codeCount == 1) then {
  230. _ownerID = format["00%1", _ownerID];
  231. };
  232. };
  233.  
  234. _object setVariable ["CharacterID", _ownerID, true];
  235.  
  236. clearWeaponCargoGlobal _object;
  237. clearMagazineCargoGlobal _object;
  238. // _object setVehicleAmmo DZE_vehicleAmmo;
  239.  
  240. _object setdir _dir;
  241. //CUSTOM VECTOR
  242. if(_vecExists)then{
  243. _object setVectorDirAndUp _vector;
  244. };
  245.  
  246. _object setposATL _pos;
  247. _object setDamage _damage;
  248.  
  249. if ((typeOf _object) == "HeliHRescue") then {
  250. PVDZE_EvacChopperFields set [count PVDZE_EvacChopperFields, _object];
  251. };
  252.  
  253. if ((typeOf _object) in dayz_allowedObjects) then {
  254. if (DZE_GodModeBase) then {
  255. _object addEventHandler ["HandleDamage", {false}];
  256. } else {
  257. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  258. };
  259. // Test disabling simulation server side on buildables only.
  260. _object enableSimulation false;
  261. // used for inplace upgrades && lock/unlock of safe
  262. _object setVariable ["OEMPos", _pos, true];
  263.  
  264. };
  265.  
  266. //if (count _intentory > 0) then { commented for Plot Management edit below.
  267. //if ((count _intentory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ")) then { commented for Plot Management&Door Management edit below.
  268. if ((count _intentory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ") && !(typeOf( _object) in DZE_DoorsLocked)) then {
  269. /*COINS*/
  270. if( count (_intentory) > 3)then{
  271. _object setVariable ["bankMoney", _intentory select 3, true];
  272. }else{
  273. _object setVariable ["bankMoney", 0, true];
  274. };
  275. /*COINS*/
  276. if (_type in DZE_LockedStorage) then {
  277. // Fill variables with loot
  278. _object setVariable ["WeaponCargo", (_intentory select 0),true];
  279. _object setVariable ["MagazineCargo", (_intentory select 1),true];
  280. _object setVariable ["BackpackCargo", (_intentory select 2),true];
  281. } else {
  282.  
  283. //Add weapons
  284. _objWpnTypes = (_intentory select 0) select 0;
  285. _objWpnQty = (_intentory select 0) select 1;
  286. _countr = 0;
  287. {
  288. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  289. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  290. };
  291. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  292. if (_isOK) then {
  293. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  294. };
  295. _countr = _countr + 1;
  296. } count _objWpnTypes;
  297.  
  298. //Add Magazines
  299. _objWpnTypes = (_intentory select 1) select 0;
  300. _objWpnQty = (_intentory select 1) select 1;
  301. _countr = 0;
  302. {
  303. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  304. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  305. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  306. if (_isOK) then {
  307. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  308. };
  309. _countr = _countr + 1;
  310. } count _objWpnTypes;
  311.  
  312. //Add Backpacks
  313. _objWpnTypes = (_intentory select 2) select 0;
  314. _objWpnQty = (_intentory select 2) select 1;
  315. _countr = 0;
  316. {
  317. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  318. if (_isOK) then {
  319. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  320. };
  321. _countr = _countr + 1;
  322. } count _objWpnTypes;
  323. };
  324. };
  325.  
  326. if (_object isKindOf "AllVehicles") then {
  327. private ["_colour","_colour2","_clrinit","_clrinit2"]; //Custom Line For Paint Vehicle
  328. {
  329. _selection = _x select 0;
  330. _dam = _x select 1;
  331. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  332. [_object,_selection,_dam] call object_setFixServer;
  333. } count _hitpoints;
  334. //Custom Vehicle Paint Start--------------------------------------------------------------------------------------------
  335. if(count _worldspace >= 4) then{
  336. if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then {
  337. _colour = _worldspace select 2;
  338. _colour2 = _worldspace select 3;
  339.  
  340. if (_colour != "0") then {
  341. _object setVariable ["Colour",_colour,true];
  342. _clrinit = format ["#(argb,8,8,3)color(%1)",_colour];
  343. _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  344. };
  345. if (_colour2 != "0") then {
  346. _object setVariable ["Colour2",_colour2,true];
  347. _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  348. _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  349. };
  350. };
  351. };
  352. //Custom Vehicle Paint End----------------------------------------------------------------------------------------------
  353. _object setFuel _fuel;
  354.  
  355. if (!((typeOf _object) in dayz_allowedObjects)) then {
  356.  
  357. //_object setvelocity [0,0,1];
  358. _object call fnc_veh_ResetEH;
  359.  
  360. if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  361. _object setvehiclelock "locked";
  362. _object setVariable ["R3F_LOG_disabled",true,true];
  363. };
  364.  
  365. _totalvehicles = _totalvehicles + 1;
  366.  
  367. // total each vehicle
  368. serverVehicleCounter set [count serverVehicleCounter,_type];
  369. };
  370. };
  371.  
  372. //Monitor the object
  373. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  374. };
  375. } count (_BuildingQueue + _objectQueue);
  376. // # END SPAWN OBJECTS #
  377.  
  378. // preload server traders menu data into cache
  379. if !(DZE_ConfigTrader) then {
  380. {
  381. // get tids
  382. _traderData = call compile format["menu_%1;",_x];
  383. if(!isNil "_traderData") then {
  384. {
  385. _traderid = _x select 1;
  386.  
  387. _retrader = [];
  388.  
  389. _key = format["CHILD:399:%1:",_traderid];
  390. _data = "HiveEXT" callExtension _key;
  391.  
  392. //diag_log "HIVE: Request sent";
  393.  
  394. //Process result
  395. _result = call compile format ["%1",_data];
  396. _status = _result select 0;
  397.  
  398. if (_status == "ObjectStreamStart") then {
  399. _val = _result select 1;
  400. //Stream Objects
  401. //diag_log ("HIVE: Commence Menu Streaming...");
  402. call compile format["ServerTcache_%1 = [];",_traderid];
  403. for "_i" from 1 to _val do {
  404. _data = "HiveEXT" callExtension _key;
  405. _result = call compile format ["%1",_data];
  406. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  407. _retrader set [count _retrader,_result];
  408. };
  409. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  410. };
  411.  
  412. } forEach (_traderData select 0);
  413. };
  414. } forEach serverTraders;
  415. };
  416.  
  417. if (_hiveLoaded) then {
  418. // spawn_vehicles
  419. _vehLimit = MaxVehicleLimit - _totalvehicles;
  420. if(_vehLimit > 0) then {
  421. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  422. for "_x" from 1 to _vehLimit do {
  423. [] spawn spawn_vehicles;
  424. };
  425. } else {
  426. diag_log "HIVE: Vehicle Spawn limit reached!";
  427. };
  428. };
  429.  
  430. // spawn_roadblocks
  431. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  432. for "_x" from 1 to MaxDynamicDebris do {
  433. [] spawn spawn_roadblocks;
  434. };
  435. // spawn_ammosupply at server start 1% of roadblocks
  436. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  437. for "_x" from 1 to MaxAmmoBoxes do {
  438. [] spawn spawn_ammosupply;
  439. };
  440. // call spawning mining veins
  441. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  442. for "_x" from 1 to MaxMineVeins do {
  443. [] spawn spawn_mineveins;
  444. };
  445.  
  446. if(isnil "dayz_MapArea") then {
  447. dayz_MapArea = 10000;
  448. };
  449. if(isnil "HeliCrashArea") then {
  450. HeliCrashArea = dayz_MapArea / 2;
  451. };
  452. if(isnil "OldHeliCrash") then {
  453. OldHeliCrash = false;
  454. };
  455.  
  456. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  457. if(OldHeliCrash) then {
  458. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  459. };
  460. if (isDedicated) then {
  461. // Epoch Events
  462. _id = [] spawn server_spawnEvents;
  463. // server cleanup
  464. [] spawn {
  465. private ["_id"];
  466. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  467. waitUntil {!isNil "server_spawnCleanAnimals"};
  468. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  469. };
  470.  
  471. // spawn debug box
  472. _debugMarkerPosition = getMarkerPos "respawn_west";
  473. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  474. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  475. _vehicle_0 setPos _debugMarkerPosition;
  476. _vehicle_0 setVariable ["ObjectID","1",true];
  477.  
  478. // max number of spawn markers
  479. if(isnil "spawnMarkerCount") then {
  480. spawnMarkerCount = 10;
  481. };
  482. actualSpawnMarkerCount = 0;
  483. // count valid spawn marker positions
  484. for "_i" from 0 to spawnMarkerCount do {
  485. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  486. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  487. } else {
  488. // exit since we did not find any further markers
  489. _i = spawnMarkerCount + 99;
  490. };
  491.  
  492. };
  493. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  494.  
  495. endLoadingScreen;
  496. };
  497.  
  498. //AI System Executions
  499. call compile preprocessFileLineNumbers "\z\addons\dayz_server\DZAI\init\dzai_initserver.sqf";
  500. [] ExecVM "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  501. allowConnection = true;
  502. sm_done = true;
  503. publicVariable "sm_done";
  504. };
  505. if (isServer && (isNil "EvacServerPreload")) then {
  506. publicVariable "PVDZE_EvacChopperFields";
  507.  
  508. ON_fnc_evacChopperFieldsUpdate = {
  509. private ["_action","_targetField"];
  510. _action = _this select 0;
  511. _targetField = _this select 1;
  512.  
  513. if (_action == "add") then {
  514. PVDZE_EvacChopperFields = PVDZE_EvacChopperFields + [_targetField];
  515. };
  516.  
  517. if (_action == "rem") then {
  518. PVDZE_EvacChopperFields = PVDZE_EvacChopperFields - [_targetField];
  519. };
  520.  
  521. publicVariable "PVDZE_EvacChopperFields";
  522. };
  523.  
  524. "PVDZE_EvacChopperFieldsUpdate" addPublicVariableEventHandler {(_this select 1) spawn ON_fnc_evacChopperFieldsUpdate};
  525.  
  526. EvacServerPreload = true;
  527. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement