Guest User

server_funcions.sqf

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