Advertisement
Guest User

server_functions.sqf

a guest
Oct 31st, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.25 KB | None | 0 0
  1.  
  2. /* PVS/PVC - Skaronator */
  3. server_sendToClient = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_sendToClient.sqf";
  4. #include "\z\addons\dayz_server\bankzones\bankinit.sqf"
  5.  
  6. //onPlayerConnected {[_uid,_name] call server_onPlayerConnect;};
  7. onPlayerDisconnected {[_uid,_name] call server_onPlayerDisconnect;};
  8.  
  9. server_updateNearbyObjects = {
  10. private["_pos"];
  11. _pos = _this select 0;
  12. {
  13. [_x, "gear"] call server_updateObject;
  14. } count nearestObjects [_pos, dayz_updateObjects, 10];
  15. };
  16.  
  17. server_handleZedSpawn = {
  18. private["_zed"];
  19. _zed = _this select 0;
  20. _zed enableSimulation false;
  21. };
  22.  
  23. zombie_findOwner = {
  24. private["_unit"];
  25. _unit = _this select 0;
  26. #ifdef DZE_SERVER_DEBUG
  27. diag_log ("CLEANUP: DELETE UNCONTROLLED ZOMBIE: " + (typeOf _unit) + " OF: " + str(_unit) );
  28. #endif
  29. deleteVehicle _unit;
  30. };
  31.  
  32. vehicle_handleInteract = {
  33. private["_object"];
  34. _object = _this select 0;
  35. needUpdate_objects = needUpdate_objects - [_object];
  36. [_object, "all"] call server_updateObject;
  37. };
  38.  
  39. array_reduceSizeReverse = {
  40. private["_array","_count","_num","_newarray","_startnum","_index"];
  41. _array = _this select 0;
  42. _newarray = [];
  43. _count = _this select 1;
  44. _num = count _array;
  45. if (_num > _count) then {
  46. _startnum = _num - 1;
  47. _index = _count - 1;
  48. for "_i" from 0 to _index do {
  49. _newarray set [(_index-_i),_array select (_startnum - _i)];
  50. };
  51. _array = _newarray;
  52. };
  53. _array
  54. };
  55.  
  56. array_reduceSize = {
  57. private ["_array1","_array","_count","_num"];
  58. _array1 = _this select 0;
  59. _array = _array1 - ["Hatchet_Swing","Machete_Swing","Fishing_Swing","sledge_swing","crowbar_swing","CSGAS"];
  60. _count = _this select 1;
  61. _num = count _array;
  62. if (_num > _count) then {
  63. _array resize _count;
  64. };
  65. _array
  66. };
  67.  
  68. object_handleServerKilled = {
  69. private["_unit","_objectID","_objectUID","_killer"];
  70. _unit = _this select 0;
  71. _killer = _this select 1;
  72.  
  73. _objectID = _unit getVariable ["ObjectID","0"];
  74. _objectUID = _unit getVariable ["ObjectUID","0"];
  75.  
  76. [_objectID,_objectUID,_killer] call server_deleteObj;
  77.  
  78. _unit removeAllMPEventHandlers "MPKilled";
  79. _unit removeAllEventHandlers "Killed";
  80. _unit removeAllEventHandlers "HandleDamage";
  81. _unit removeAllEventHandlers "GetIn";
  82. _unit removeAllEventHandlers "GetOut";
  83. };
  84.  
  85. check_publishobject = {
  86. private["_allowed","_object","_playername"];
  87.  
  88. _object = _this select 0;
  89. _playername = _this select 1;
  90. _allowed = false;
  91.  
  92. if ((typeOf _object) in dayz_allowedObjects) then {
  93. //diag_log format ["DEBUG: Object: %1 published by %2 is Safe",_object, _playername];
  94. _allowed = true;
  95. };
  96. _allowed
  97. };
  98.  
  99. //event Handlers
  100. eh_localCleanup = {
  101. private ["_object"];
  102. _object = _this select 0;
  103. _object addEventHandler ["local", {
  104. if(_this select 1) then {
  105. private["_type","_unit"];
  106. _unit = _this select 0;
  107. _type = typeOf _unit;
  108. _myGroupUnit = group _unit;
  109. _unit removeAllMPEventHandlers "mpkilled";
  110. _unit removeAllMPEventHandlers "mphit";
  111. _unit removeAllMPEventHandlers "mprespawn";
  112. _unit removeAllEventHandlers "FiredNear";
  113. _unit removeAllEventHandlers "HandleDamage";
  114. _unit removeAllEventHandlers "Killed";
  115. _unit removeAllEventHandlers "Fired";
  116. _unit removeAllEventHandlers "GetOut";
  117. _unit removeAllEventHandlers "GetIn";
  118. _unit removeAllEventHandlers "Local";
  119. clearVehicleInit _unit;
  120. deleteVehicle _unit;
  121. if ((count (units _myGroupUnit) == 0) && (_myGroupUnit != grpNull)) then {
  122. deleteGroup _myGroupUnit;
  123. };
  124. //_unit = nil;
  125. // diag_log ("CLEANUP: DELETED A " + str(_type) );
  126. };
  127. }];
  128. };
  129.  
  130. server_hiveWrite = {
  131. private["_data"];
  132. _data = "HiveExt" callExtension _this;
  133. };
  134.  
  135. server_hiveReadWrite = {
  136. private["_key","_resultArray","_data"];
  137. _key = _this;
  138. _data = "HiveExt" callExtension _key;
  139. _resultArray = call compile format ["%1",_data];
  140. _resultArray
  141. };
  142.  
  143. server_hiveReadWriteLarge = {
  144. private["_key","_resultArray","_data"];
  145. _key = _this;
  146. _data = "HiveExt" callExtension _key;
  147. _resultArray = call compile _data;
  148. _resultArray
  149. };
  150.  
  151. server_checkIfTowed = {
  152. private ["_vehicle","_player","_attached"];
  153. if (DZE_HeliLift) then {
  154. _vehicle = _this select 0;
  155. _player = _this select 2;
  156. _attached = _vehicle getVariable["attached",false];
  157. if (typeName _attached == "OBJECT") then {
  158. _player action ["eject", _vehicle];
  159. detach _vehicle;
  160. _vehicle setVariable["attached",false,true];
  161. _attached setVariable["hasAttached",false,true];
  162. };
  163. };
  164. };
  165. /* Not used, why is this here?
  166. server_characterSync = {
  167. private ["_characterID","_playerPos","_playerGear","_playerBackp","_medical","_currentState","_currentModel","_key"];
  168. _characterID = _this select 0;
  169. _playerPos = _this select 1;
  170. _playerGear = _this select 2;
  171. _playerBackp = _this select 3;
  172. _medical = _this select 4;
  173. _currentState = _this select 5;
  174. _currentModel = _this select 6;
  175.  
  176. _key = format["CHILD:201:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:",_characterID,_playerPos,_playerGear,_playerBackp,_medical,false,false,0,0,0,0,_currentState,0,0,_currentModel,0];
  177. _key call server_hiveWrite;
  178. };
  179. */
  180.  
  181. if(isnil "dayz_MapArea") then {
  182. dayz_MapArea = 10000;
  183. };
  184. if(isnil "DynamicVehicleArea") then {
  185. DynamicVehicleArea = dayz_MapArea / 2;
  186. };
  187.  
  188. // Get all buildings && roads only once TODO: set variables to nil after done if nessicary
  189. MarkerPosition = getMarkerPos "center";
  190. RoadList = MarkerPosition nearRoads DynamicVehicleArea;
  191.  
  192. // Very taxing !!! but only on first startup
  193. BuildingList = [];
  194. {
  195. if (DZE_MissionLootTable) then {
  196. if (isClass (missionConfigFile >> "CfgBuildingLoot" >> (typeOf _x))) then
  197. {
  198. BuildingList set [count BuildingList,_x];
  199. };
  200. } else {
  201. if (isClass (configFile >> "CfgBuildingLoot" >> (typeOf _x))) then
  202. {
  203. BuildingList set [count BuildingList,_x];
  204. };
  205. };
  206.  
  207.  
  208. } count (MarkerPosition nearObjects ["building",DynamicVehicleArea]);
  209.  
  210. spawn_vehicles = {
  211. private ["_random","_lastIndex","_weights","_index","_vehicle","_velimit","_qty","_isAir","_isShip","_position","_dir","_istoomany","_veh","_objPosition","_marker","_iClass","_itemTypes","_cntWeights","_itemType","_num","_allCfgLoots"];
  212.  
  213. if (!isDedicated) exitWith { }; //Be sure the run this
  214.  
  215. while {count AllowedVehiclesList > 0} do {
  216. // BIS_fnc_selectRandom replaced because the index may be needed to remove the element
  217. _index = floor random count AllowedVehiclesList;
  218. _random = AllowedVehiclesList select _index;
  219.  
  220. _vehicle = _random select 0;
  221. _velimit = _random select 1;
  222.  
  223. _qty = {_x == _vehicle} count serverVehicleCounter;
  224.  
  225. // If under limit allow to proceed
  226. if (_qty <= _velimit) exitWith {};
  227.  
  228. // vehicle limit reached, remove vehicle from list
  229. // since elements cannot be removed from an array, overwrite it with the last element && cut the last element of (as long as order is not important)
  230. _lastIndex = (count AllowedVehiclesList) - 1;
  231. if (_lastIndex != _index) then {
  232. AllowedVehiclesList set [_index, AllowedVehiclesList select _lastIndex];
  233. };
  234. AllowedVehiclesList resize _lastIndex;
  235. };
  236.  
  237. if (count AllowedVehiclesList == 0) then {
  238. diag_log("DEBUG: unable to find suitable vehicle to spawn");
  239. } else {
  240.  
  241. // add vehicle to counter for next pass
  242. serverVehicleCounter set [count serverVehicleCounter,_vehicle];
  243.  
  244. // Find Vehicle Type to better control spawns
  245. _isAir = _vehicle isKindOf "Air";
  246. _isShip = _vehicle isKindOf "Ship";
  247.  
  248. if(_isShip || _isAir) then {
  249. if(_isShip) then {
  250. // Spawn anywhere on coast on water
  251. waitUntil{!isNil "BIS_fnc_findSafePos"};
  252. _position = [MarkerPosition,0,DynamicVehicleArea,10,1,2000,1] call BIS_fnc_findSafePos;
  253. //diag_log("DEBUG: spawning boat near coast " + str(_position));
  254. } else {
  255. // Spawn air anywhere that is flat
  256. waitUntil{!isNil "BIS_fnc_findSafePos"};
  257. _position = [MarkerPosition,0,DynamicVehicleArea,10,0,2000,0] call BIS_fnc_findSafePos;
  258. //diag_log("DEBUG: spawning air anywhere flat " + str(_position));
  259. };
  260.  
  261.  
  262. } else {
  263. // Spawn around buildings && 50% near roads
  264. if((random 1) > 0.5) then {
  265.  
  266. waitUntil{!isNil "BIS_fnc_selectRandom"};
  267. _position = RoadList call BIS_fnc_selectRandom;
  268.  
  269. _position = _position modelToWorld [0,0,0];
  270.  
  271. waitUntil{!isNil "BIS_fnc_findSafePos"};
  272. _position = [_position,0,10,10,0,2000,0] call BIS_fnc_findSafePos;
  273.  
  274. //diag_log("DEBUG: spawning near road " + str(_position));
  275.  
  276. } else {
  277.  
  278. waitUntil{!isNil "BIS_fnc_selectRandom"};
  279. _position = BuildingList call BIS_fnc_selectRandom;
  280.  
  281. _position = _position modelToWorld [0,0,0];
  282.  
  283. waitUntil{!isNil "BIS_fnc_findSafePos"};
  284. _position = [_position,0,40,5,0,2000,0] call BIS_fnc_findSafePos;
  285.  
  286. //diag_log("DEBUG: spawning around buildings " + str(_position));
  287.  
  288. };
  289. };
  290. // only proceed if two params otherwise BIS_fnc_findSafePos failed && may spawn in air
  291. if ((count _position) == 2) then {
  292.  
  293. _dir = round(random 180);
  294.  
  295. _istoomany = _position nearObjects ["AllVehicles",50];
  296. if((count _istoomany) > 0) exitWith { diag_log("DEBUG: Too many vehicles at " + str(_position)); };
  297.  
  298. //place vehicle
  299. _veh = createVehicle [_vehicle, _position, [], 0, "CAN_COLLIDE"];
  300. _veh setdir _dir;
  301. _veh setpos _position;
  302.  
  303. if(DZEdebug) then {
  304. _marker = createMarker [str(_position) , _position];
  305. _marker setMarkerShape "ICON";
  306. _marker setMarkerType "DOT";
  307. _marker setMarkerText _vehicle;
  308. };
  309.  
  310. // Get position with ground
  311. _objPosition = getPosATL _veh;
  312.  
  313. clearWeaponCargoGlobal _veh;
  314. clearMagazineCargoGlobal _veh;
  315. // _veh setVehicleAmmo DZE_vehicleAmmo;
  316.  
  317. // Add 0-3 loots to vehicle using random cfgloots
  318. _num = floor(random 4);
  319. _allCfgLoots = ["trash","civilian","food","generic","medical","military","policeman","hunter","worker","clothes","militaryclothes","specialclothes","trash"];
  320.  
  321. for "_x" from 1 to _num do {
  322. _iClass = _allCfgLoots call BIS_fnc_selectRandom;
  323.  
  324. _itemTypes = [];
  325. if (DZE_MissionLootTable) then{
  326. {
  327. _itemTypes set[count _itemTypes, _x select 0]
  328. } count getArray(missionConfigFile >> "cfgLoot" >> _iClass);
  329. }
  330. else {
  331. {
  332. _itemTypes set[count _itemTypes, _x select 0]
  333. } count getArray(configFile >> "cfgLoot" >> _iClass);
  334. };
  335.  
  336. _index = dayz_CLBase find _iClass;
  337. _weights = dayz_CLChances select _index;
  338. _cntWeights = count _weights;
  339.  
  340. _index = floor(random _cntWeights);
  341. _index = _weights select _index;
  342. _itemType = _itemTypes select _index;
  343. _veh addMagazineCargoGlobal [_itemType,1];
  344. //diag_log("DEBUG: spawed loot inside vehicle " + str(_itemType));
  345. };
  346.  
  347. [_veh,[_dir,_objPosition],_vehicle,true,"0"] call server_publishVeh;
  348. };
  349. };
  350. };
  351.  
  352. spawn_ammosupply = {
  353. private ["_position","_veh","_istoomany","_marker","_spawnveh","_WreckList"];
  354. if (isDedicated) then {
  355. _WreckList = ["Supply_Crate_DZE"];
  356. waitUntil{!isNil "BIS_fnc_selectRandom"};
  357. _position = RoadList call BIS_fnc_selectRandom;
  358. _position = _position modelToWorld [0,0,0];
  359. waitUntil{!isNil "BIS_fnc_findSafePos"};
  360. _position = [_position,5,20,5,0,2000,0] call BIS_fnc_findSafePos;
  361. if ((count _position) == 2) then {
  362.  
  363. _istoomany = _position nearObjects ["All",5];
  364.  
  365. if((count _istoomany) > 0) exitWith { diag_log("DEBUG VEIN: Too many at " + str(_position)); };
  366.  
  367. _spawnveh = _WreckList call BIS_fnc_selectRandom;
  368.  
  369. if(DZEdebug) then {
  370. _marker = createMarker [str(_position) , _position];
  371. _marker setMarkerShape "ICON";
  372. _marker setMarkerType "DOT";
  373. _marker setMarkerText str(_spawnveh);
  374. };
  375.  
  376. _veh = createVehicle [_spawnveh,_position, [], 0, "CAN_COLLIDE"];
  377. _veh enableSimulation false;
  378. _veh setDir round(random 360);
  379. _veh setpos _position;
  380. _veh setVariable ["ObjectID","1",true];
  381. };
  382. };
  383. };
  384.  
  385. DZE_LocalRoadBlocks = [];
  386.  
  387. spawn_roadblocks = {
  388. private ["_position","_veh","_istoomany","_marker","_spawnveh","_WreckList"];
  389. _WreckList = ["SKODAWreck","HMMWVWreck","UralWreck","datsun01Wreck","hiluxWreck","datsun02Wreck","UAZWreck","Land_Misc_Garb_Heap_EP1","Fort_Barricade_EP1","Rubbish2"];
  390.  
  391. waitUntil{!isNil "BIS_fnc_selectRandom"};
  392. if (isDedicated) then {
  393.  
  394. _position = RoadList call BIS_fnc_selectRandom;
  395.  
  396. _position = _position modelToWorld [0,0,0];
  397.  
  398. waitUntil{!isNil "BIS_fnc_findSafePos"};
  399. _position = [_position,0,10,5,0,2000,0] call BIS_fnc_findSafePos;
  400.  
  401. if ((count _position) == 2) then {
  402. // Get position with ground
  403.  
  404. _istoomany = _position nearObjects ["All",5];
  405.  
  406. if((count _istoomany) > 0) exitWith { diag_log("DEBUG: Too many at " + str(_position)); };
  407.  
  408. waitUntil{!isNil "BIS_fnc_selectRandom"};
  409. _spawnveh = _WreckList call BIS_fnc_selectRandom;
  410.  
  411. if(DZEdebug) then {
  412. _marker = createMarker [str(_position) , _position];
  413. _marker setMarkerShape "ICON";
  414. _marker setMarkerType "DOT";
  415. _marker setMarkerText str(_spawnveh);
  416. };
  417.  
  418. _veh = createVehicle [_spawnveh,_position, [], 0, "CAN_COLLIDE"];
  419. _veh enableSimulation false;
  420.  
  421. _veh setDir round(random 360); // Randomize placement a bit
  422. _veh setpos _position;
  423.  
  424. _veh setVariable ["ObjectID","1",true];
  425. };
  426.  
  427. };
  428.  
  429. };
  430.  
  431. spawn_mineveins = {
  432. private ["_position","_veh","_istoomany","_marker","_spawnveh","_positions"];
  433.  
  434. if (isDedicated) then {
  435.  
  436. _position = [getMarkerPos "center",0,(HeliCrashArea*0.75),10,0,2000,0] call BIS_fnc_findSafePos;
  437.  
  438. if ((count _position) == 2) then {
  439.  
  440. _positions = selectBestPlaces [_position, 500, "(1 + forest) * (1 + hills) * (1 - houses) * (1 - sea)", 10, 5];
  441.  
  442. _position = (_positions call BIS_fnc_selectRandom) select 0;
  443.  
  444. // Get position with ground
  445. _istoomany = _position nearObjects ["All",10];
  446.  
  447. if((count _istoomany) > 0) exitWith { diag_log("DEBUG VEIN: Too many objects at " + str(_position)); };
  448.  
  449. if(isOnRoad _position) exitWith { diag_log("DEBUG VEIN: on road " + str(_position)); };
  450.  
  451. _spawnveh = ["Iron_Vein_DZE","Iron_Vein_DZE","Iron_Vein_DZE","Iron_Vein_DZE","Iron_Vein_DZE","Silver_Vein_DZE","Silver_Vein_DZE","Silver_Vein_DZE","Gold_Vein_DZE","Gold_Vein_DZE"] call BIS_fnc_selectRandom;
  452.  
  453. if(DZEdebug) then {
  454. _marker = createMarker [str(_position) , _position];
  455. _marker setMarkerShape "ICON";
  456. _marker setMarkerType "DOT";
  457. _marker setMarkerText str(_spawnveh);
  458. };
  459.  
  460. //diag_log("DEBUG: Spawning a crashed " + _spawnveh + " with " + _spawnloot + " at " + str(_position));
  461. _veh = createVehicle [_spawnveh,_position, [], 0, "CAN_COLLIDE"];
  462. _veh enableSimulation false;
  463.  
  464. // Randomize placement a bit
  465. _veh setDir round(random 360);
  466. _veh setpos _position;
  467.  
  468. _veh setVariable ["ObjectID","1",true];
  469.  
  470.  
  471. };
  472. };
  473. };
  474.  
  475. if(isnil "DynamicVehicleDamageLow") then {
  476. DynamicVehicleDamageLow = 0;
  477. };
  478. if(isnil "DynamicVehicleDamageHigh") then {
  479. DynamicVehicleDamageHigh = 65;
  480. };
  481.  
  482. if(isnil "DynamicVehicleFuelLow") then {
  483. DynamicVehicleFuelLow = 10;
  484. };
  485. if(isnil "DynamicVehicleFuelHigh") then {
  486. DynamicVehicleFuelHigh = 80;
  487. };
  488.  
  489. if(isnil "DZE_DiagFpsSlow") then {
  490. DZE_DiagFpsSlow = false;
  491. };
  492. if(isnil "DZE_DiagFpsFast") then {
  493. DZE_DiagFpsFast = false;
  494. };
  495. if(isnil "DZE_DiagVerbose") then {
  496. DZE_DiagVerbose = false;
  497. };
  498.  
  499. dze_diag_fps = {
  500. if(DZE_DiagVerbose) then {
  501. diag_log format["DEBUG FPS : %1 OBJECTS: %2 : PLAYERS: %3", diag_fps,(count (allMissionObjects "")),(playersNumber west)];
  502. } else {
  503. diag_log format["DEBUG FPS : %1", diag_fps];
  504. };
  505. };
  506.  
  507. // Damage generator function
  508. generate_new_damage = {
  509. private ["_damage"];
  510. _damage = ((random(DynamicVehicleDamageHigh-DynamicVehicleDamageLow))+DynamicVehicleDamageLow) / 100;
  511. _damage;
  512. };
  513.  
  514. // Damage generator fuction
  515. generate_exp_damage = {
  516. private ["_damage"];
  517. _damage = ((random(DynamicVehicleDamageHigh-DynamicVehicleDamageLow))+DynamicVehicleDamageLow) / 100;
  518.  
  519. // limit this to 85% since vehicle would blow up otherwise.
  520. //if(_damage >= 0.85) then {
  521. // _damage = 0.85;
  522. //};
  523. _damage;
  524. };
  525.  
  526. server_getDiff = {
  527. private["_variable","_object","_vNew","_vOld","_result"];
  528. _variable = _this select 0;
  529. _object = _this select 1;
  530. _vNew = _object getVariable[_variable,0];
  531. _vOld = _object getVariable[(_variable + "_CHK"),_vNew];
  532. _result = 0;
  533. if (_vNew < _vOld) then {
  534. //JIP issues
  535. _vNew = _vNew + _vOld;
  536. _object getVariable[(_variable + "_CHK"),_vNew];
  537. } else {
  538. _result = _vNew - _vOld;
  539. _object setVariable[(_variable + "_CHK"),_vNew];
  540. };
  541. _result
  542. };
  543.  
  544. server_getDiff2 = {
  545. private["_variable","_object","_vNew","_vOld","_result"];
  546. _variable = _this select 0;
  547. _object = _this select 1;
  548. _vNew = _object getVariable[_variable,0];
  549. _vOld = _object getVariable[(_variable + "_CHK"),_vNew];
  550. _result = _vNew - _vOld;
  551. _object setVariable[(_variable + "_CHK"),_vNew];
  552. _result
  553. };
  554.  
  555. dayz_objectUID = {
  556. private["_position","_dir","_key","_object"];
  557. _object = _this;
  558. _position = getPosATL _object;
  559. _dir = direction _object;
  560. _key = [_dir,_position] call dayz_objectUID2;
  561. _key
  562. };
  563.  
  564. dayz_objectUID2 = {
  565. private["_position","_dir","_key"];
  566. _dir = _this select 0;
  567. _key = "";
  568. _position = _this select 1;
  569. {
  570. _x = _x * 10;
  571. if ( _x < 0 ) then { _x = _x * -10 };
  572. _key = _key + str(round(_x));
  573. } count _position;
  574. _key = _key + str(round(_dir));
  575. _key
  576. };
  577.  
  578. dayz_objectUID3 = {
  579. private["_position","_dir","_key"];
  580. _dir = _this select 0;
  581. _key = "";
  582. _position = _this select 1;
  583. {
  584. _x = _x * 10;
  585. if ( _x < 0 ) then { _x = _x * -10 };
  586. _key = _key + str(round(_x));
  587. } count _position;
  588. _key = _key + str(round(_dir + time));
  589. _key
  590. };
  591.  
  592. dayz_recordLogin = {
  593. private["_key"];
  594. _key = format["CHILD:103:%1:%2:%3:",_this select 0,_this select 1,_this select 2];
  595. _key call server_hiveWrite;
  596. };
  597.  
  598. dayz_perform_purge = {
  599. if(!isNull(_this)) then {
  600. _group = group _this;
  601. _this removeAllMPEventHandlers "mpkilled";
  602. _this removeAllMPEventHandlers "mphit";
  603. _this removeAllMPEventHandlers "mprespawn";
  604. _this removeAllEventHandlers "FiredNear";
  605. _this removeAllEventHandlers "HandleDamage";
  606. _this removeAllEventHandlers "Killed";
  607. _this removeAllEventHandlers "Fired";
  608. _this removeAllEventHandlers "GetOut";
  609. _this removeAllEventHandlers "GetIn";
  610. _this removeAllEventHandlers "Local";
  611. clearVehicleInit _this;
  612. deleteVehicle _this;
  613. if ((count (units _group) == 0) && (_group != grpNull)) then {
  614. deleteGroup _group;
  615. };
  616. };
  617. };
  618.  
  619. dayz_perform_purge_player = {
  620.  
  621. private ["_countr","_backpack","_backpackType","_backpackWpn","_backpackMag","_objWpnTypes","_objWpnQty","_location","_dir","_holder","_weapons","_magazines"];
  622. diag_log ("Purging player: " + str(_this));
  623.  
  624. if(!isNull(_this)) then {
  625.  
  626. _location = getPosATL _this;
  627. _dir = getDir _this;
  628.  
  629. _holder = createVehicle ["GraveDZE", _location, [], 0, "CAN_COLLIDE"];
  630. _holder setDir _dir;
  631. _holder setPosATL _location;
  632.  
  633. _holder enableSimulation false;
  634.  
  635. _weapons = weapons _this;
  636. _magazines = magazines _this;
  637.  
  638. // find backpack
  639. if(!(isNull unitBackpack _this)) then {
  640. _backpack = unitBackpack _this;
  641. _backpackType = typeOf _backpack;
  642. _backpackWpn = getWeaponCargo _backpack;
  643. _backpackMag = getMagazineCargo _backpack;
  644.  
  645. _holder addBackpackCargoGlobal [_backpackType,1];
  646.  
  647. // add items from backpack
  648. _objWpnTypes = _backpackWpn select 0;
  649. _objWpnQty = _backpackWpn select 1;
  650. _countr = 0;
  651. {
  652. _holder addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  653. _countr = _countr + 1;
  654. } count _objWpnTypes;
  655.  
  656. // add backpack magazine items
  657. _objWpnTypes = _backpackMag select 0;
  658. _objWpnQty = _backpackMag select 1;
  659. _countr = 0;
  660. {
  661. _holder addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  662. _countr = _countr + 1;
  663. } count _objWpnTypes;
  664. };
  665. };
  666.  
  667. // add weapons
  668. {
  669. _holder addWeaponCargoGlobal [_x, 1];
  670. } count _weapons;
  671.  
  672. // add mags
  673. {
  674. _holder addMagazineCargoGlobal [_x, 1];
  675. } count _magazines;
  676. _group = group _this;
  677. _this removeAllMPEventHandlers "mpkilled";
  678. _this removeAllMPEventHandlers "mphit";
  679. _this removeAllMPEventHandlers "mprespawn";
  680. _this removeAllEventHandlers "FiredNear";
  681. _this removeAllEventHandlers "HandleDamage";
  682. _this removeAllEventHandlers "Killed";
  683. _this removeAllEventHandlers "Fired";
  684. _this removeAllEventHandlers "GetOut";
  685. _this removeAllEventHandlers "GetIn";
  686. _this removeAllEventHandlers "Local";
  687. clearVehicleInit _this;
  688. deleteVehicle _this;
  689. if ((count (units _group) == 0) && (_group != grpNull)) then {
  690. deleteGroup _group;
  691. };
  692. // _this = nil;
  693. };
  694.  
  695.  
  696. dayz_removePlayerOnDisconnect = {
  697. if(!isNull(_this)) then {
  698. _group = group _this;
  699. _this removeAllMPEventHandlers "mphit";
  700. deleteVehicle _this;
  701. deleteGroup (group _this);
  702. };
  703. };
  704.  
  705. server_timeSync = {
  706. //Send request
  707. private ["_hour","_minute","_date","_key","_result","_outcome"];
  708. _key = "CHILD:307:";
  709. _result = _key call server_hiveReadWrite;
  710. _outcome = _result select 0;
  711. if(_outcome == "PASS") then {
  712. _date = _result select 1;
  713.  
  714. if(dayz_fullMoonNights) then {
  715. _hour = _date select 3;
  716. _minute = _date select 4;
  717. //Force full moon nights
  718. _date = [2013,8,3,_hour,_minute];
  719. };
  720.  
  721. setDate _date;
  722. PVDZE_plr_SetDate = _date;
  723. publicVariable "PVDZE_plr_SetDate";
  724. diag_log ("TIME SYNC: Local Time set to " + str(_date));
  725. };
  726. };
  727.  
  728. // must spawn these
  729. server_spawncleanDead = {
  730. private ["_deathTime","_delQtyZ","_delQtyP","_qty","_allDead"];
  731. _allDead = allDead;
  732. _delQtyZ = 0;
  733. _delQtyP = 0;
  734. {
  735. if (local _x) then {
  736. if (_x isKindOf "zZombie_Base") then
  737. {
  738. _x call dayz_perform_purge;
  739. sleep 0.05;
  740. _delQtyZ = _delQtyZ + 1;
  741. } else {
  742. if (_x isKindOf "CAManBase") then {
  743. _deathTime = _x getVariable ["processedDeath", diag_tickTime];
  744. if (diag_tickTime - _deathTime > 1800) then {
  745. _x call dayz_perform_purge_player;
  746. sleep 0.025;
  747. _delQtyP = _delQtyP + 1;
  748. };
  749. };
  750. };
  751. };
  752. sleep 0.025;
  753. } count _allDead;
  754. if (_delQtyZ > 0 || _delQtyP > 0) then {
  755. _qty = count _allDead;
  756. diag_log (format["CLEANUP: Deleted %1 players && %2 zombies out of %3 dead",_delQtyP,_delQtyZ,_qty]);
  757. };
  758. };
  759. server_cleanupGroups = {
  760. if (DZE_DYN_AntiStuck3rd > 3) then { DZE_DYN_GroupCleanup = nil; DZE_DYN_AntiStuck3rd = 0; };
  761. if(!isNil "DZE_DYN_GroupCleanup") exitWith { DZE_DYN_AntiStuck3rd = DZE_DYN_AntiStuck3rd + 1;};
  762. DZE_DYN_GroupCleanup = true;
  763. {
  764. if ((count (units _x) == 0) && (_x != grpNull)) then {
  765. deleteGroup _x;
  766. };
  767. sleep 0.001;
  768. } count allGroups;
  769. DZE_DYN_GroupCleanup = nil;
  770. };
  771.  
  772. server_checkHackers = {
  773. if (DZE_DYN_AntiStuck2nd > 3) then { DZE_DYN_HackerCheck = nil; DZE_DYN_AntiStuck2nd = 0; };
  774. if(!isNil "DZE_DYN_HackerCheck") exitWith { DZE_DYN_AntiStuck2nd = DZE_DYN_AntiStuck2nd + 1;};
  775. DZE_DYN_HackerCheck = true;
  776. {
  777. if (!((isNil "_x") || {(isNull _x)})) then {
  778. if(vehicle _x != _x && !(vehicle _x in PVDZE_serverObjectMonitor) && (isPlayer _x) && !((typeOf vehicle _x) in DZE_safeVehicle)) then {
  779. diag_log ("CLEANUP: KILLING A HACKER " + (name _x) + " " + str(_x) + " IN " + (typeOf vehicle _x));
  780. (vehicle _x) setDamage 1;
  781. _x setDamage 1;
  782. sleep 0.25;
  783. };
  784. };
  785. sleep 0.001;
  786. } count allUnits;
  787. DZE_DYN_HackerCheck = nil;
  788. };
  789.  
  790. server_spawnCleanFire = {
  791. private ["_delQtyFP","_qty","_delQtyNull","_missionFires"];
  792. _missionFires = allMissionObjects "Land_Fire_DZ";
  793. _delQtyFP = 0;
  794. {
  795. if (local _x) then {
  796. deleteVehicle _x;
  797. sleep 0.025;
  798. _delQtyFP = _delQtyFP + 1;
  799. };
  800. sleep 0.001;
  801. } count _missionFires;
  802. if (_delQtyFP > 0) then {
  803. _qty = count _missionFires;
  804. diag_log (format["CLEANUP: Deleted %1 fireplaces out of %2",_delQtyNull,_qty]);
  805. };
  806. };
  807. server_spawnCleanLoot = {
  808. private ["_created","_delQty","_nearby","_age","_keep","_qty","_missionObjs","_dateNow"];
  809. if (DZE_DYN_AntiStuck > 3) then { DZE_DYN_cleanLoot = nil; DZE_DYN_AntiStuck = 0; };
  810. if(!isNil "DZE_DYN_cleanLoot") exitWith { DZE_DYN_AntiStuck = DZE_DYN_AntiStuck + 1;};
  811. DZE_DYN_cleanLoot = true;
  812.  
  813. _missionObjs = allMissionObjects "ReammoBox";
  814. _delQty = 0;
  815. _dateNow = (DateToNumber date);
  816. {
  817. if (!isNull _x) then {
  818. _keep = _x getVariable["permaLoot", false];
  819. if (!_keep) then {
  820. _created = _x getVariable["created", -0.1];
  821. if (_created == -0.1) then{
  822. _x setVariable["created", _dateNow, false];
  823. _created = _dateNow;
  824. }
  825. else {
  826. _age = (_dateNow - _created) * 525948;
  827. if (_age > 20) then{
  828. _nearby = { (isPlayer _x) && (alive _x) } count(_x nearEntities[["CAManBase", "AllVehicles"], 130]);
  829. if (_nearby == 0) then{
  830. deleteVehicle _x;
  831. sleep 0.025;
  832. _delQty = _delQty + 1;
  833. };
  834. };
  835. };
  836. };
  837. };
  838. sleep 0.001;
  839. } count _missionObjs;
  840. if (_delQty > 0) then {
  841. _qty = count _missionObjs;
  842. diag_log (format["CLEANUP: Deleted %1 Loot Piles out of %2",_delQty,_qty]);
  843. };
  844. DZE_DYN_cleanLoot = nil;
  845. };
  846.  
  847. server_spawnCleanAnimals = {
  848. private ["_pos","_delQtyAnimal","_qty","_missonAnimals","_nearby"];
  849. _missonAnimals = entities "CAAnimalBase";
  850. _delQtyAnimal = 0;
  851. {
  852. if (local _x) then {
  853. _x call dayz_perform_purge;
  854. sleep 0.05;
  855. _delQtyAnimal = _delQtyAnimal + 1;
  856. } else {
  857. if (!alive _x) then {
  858. _pos = getPosATL _x;
  859. if (count _pos > 0) then {
  860. _nearby = {(isPlayer _x) && (alive _x)} count (_pos nearEntities [["CAManBase","AllVehicles"], 130]);
  861. if (_nearby==0) then {
  862. _x call dayz_perform_purge;
  863. sleep 0.05;
  864. _delQtyAnimal = _delQtyAnimal + 1;
  865. };
  866. };
  867. };
  868. };
  869. sleep 0.001;
  870. } count _missonAnimals;
  871. if (_delQtyAnimal > 0) then {
  872. _qty = count _missonAnimals;
  873. diag_log (format["CLEANUP: Deleted %1 Animals out of %2",_delQtyAnimal,_qty]);
  874. };
  875. };
  876.  
  877. server_logUnlockLockEvent = {
  878. private["_player", "_obj", "_objectID", "_objectUID", "_statusText", "_status"];
  879. _player = _this select 0;
  880. _obj = _this select 1;
  881. _status = _this select 2;
  882. if (!isNull(_obj)) then {
  883. _objectID = _obj getVariable["ObjectID", "0"];
  884. _objectUID = _obj getVariable["ObjectUID", "0"];
  885. _statusText = "UNLOCKED";
  886. if (_status) then {
  887. [_obj, "gear"] call server_updateObject;
  888. _statusText = "LOCKED";
  889. };
  890. diag_log format["SAFE %5: ID:%1 UID:%2 BY %3(%4)", _objectID, _objectUID, (name _player), (getPlayerUID _player), _statusText];
  891. };
  892. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement