Advertisement
Guest User

server_functions.sqf

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