Advertisement
Guest User

Untitled

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