Advertisement
Guest User

Server_functions.sqf

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