Advertisement
Guest User

Untitled

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