Guest User

server_functions

a guest
May 30th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.63 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. DeadPlayerPlotObjects = [];
  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. server_changePlotsOwner = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_changePlotsOwner.sqf";
  40.  
  41. //XsG Edit for Mission system
  42. fnc_hTime = compile preprocessFile "\z\addons\dayz_server\Missions\misc\fnc_hTime.sqf"; //Random integer selector for mission wait time
  43. /* PVS/PVC - Skaronator */
  44. server_sendToClient = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_sendToClient.sqf";
  45.  
  46. //onPlayerConnected {[_uid,_name] call server_onPlayerConnect;};
  47. onPlayerDisconnected {[_uid,_name] call server_onPlayerDisconnect;};
  48.  
  49. server_updateNearbyObjects = {
  50. private["_pos"];
  51. _pos = _this select 0;
  52. {
  53. [_x, "gear"] call server_updateObject;
  54. } forEach nearestObjects [_pos, dayz_updateObjects, 10];
  55. };
  56.  
  57. server_handleZedSpawn = {
  58. private["_zed"];
  59. _zed = _this select 0;
  60. _zed enableSimulation false;
  61. };
  62.  
  63. zombie_findOwner = {
  64. private["_unit"];
  65. _unit = _this select 0;
  66. #ifdef DZE_SERVER_DEBUG
  67. diag_log ("CLEANUP: DELETE UNCONTROLLED ZOMBIE: " + (typeOf _unit) + " OF: " + str(_unit) );
  68. #endif
  69. deleteVehicle _unit;
  70. };
  71.  
  72. vehicle_handleInteract = {
  73. private["_object"];
  74. _object = _this select 0;
  75. needUpdate_objects = needUpdate_objects - [_object];
  76. [_object, "all"] call server_updateObject;
  77. };
  78.  
  79. array_reduceSizeReverse = {
  80. private["_array","_count","_num","_newarray","_startnum","_index"];
  81. _array = _this select 0;
  82. _newarray = [];
  83. _count = _this select 1;
  84. _num = count _array;
  85. if (_num > _count) then {
  86. _startnum = _num - 1;
  87. _index = _count - 1;
  88. for "_i" from 0 to _index do {
  89. _newarray set [(_index-_i),_array select (_startnum - _i)];
  90. };
  91. _array = _newarray;
  92. };
  93. _array
  94. };
  95.  
  96. array_reduceSize = {
  97. private ["_array1","_array","_count","_num"];
  98. _array1 = _this select 0;
  99. _array = _array1 - ["Hatchet_Swing","Machete_Swing","Fishing_Swing","sledge_swing","crowbar_swing","CSGAS"];
  100. _count = _this select 1;
  101. _num = count _array;
  102. if (_num > _count) then {
  103. _array resize _count;
  104. };
  105. _array
  106. };
  107.  
  108. object_handleServerKilled = {
  109. private["_unit","_objectID","_objectUID","_killer"];
  110. _unit = _this select 0;
  111. _killer = _this select 1;
  112.  
  113. _objectID = _unit getVariable ["ObjectID","0"];
  114. _objectUID = _unit getVariable ["ObjectUID","0"];
  115.  
  116. [_objectID,_objectUID,_killer] call server_deleteObj;
  117.  
  118. _unit removeAllMPEventHandlers "MPKilled";
  119. _unit removeAllEventHandlers "Killed";
  120. _unit removeAllEventHandlers "HandleDamage";
  121. _unit removeAllEventHandlers "GetIn";
  122. _unit removeAllEventHandlers "GetOut";
  123. };
  124.  
  125. check_publishobject = {
  126. private["_allowed","_object","_playername"];
  127.  
  128. _object = _this select 0;
  129. _playername = _this select 1;
  130. _allowed = false;
  131.  
  132. if ((typeOf _object) in dayz_allowedObjects) then {
  133. //diag_log format ["DEBUG: Object: %1 published by %2 is Safe",_object, _playername];
  134. _allowed = true;
  135. };
  136. _allowed
  137. };
  138.  
  139. //event Handlers
  140. eh_localCleanup = {
  141. private ["_object"];
  142. _object = _this select 0;
  143. _object addEventHandler ["local", {
  144. if(_this select 1) then {
  145. private["_type","_unit"];
  146. _unit = _this select 0;
  147. _type = typeOf _unit;
  148. _myGroupUnit = group _unit;
  149. _unit removeAllMPEventHandlers "mpkilled";
  150. _unit removeAllMPEventHandlers "mphit";
  151. _unit removeAllMPEventHandlers "mprespawn";
  152. _unit removeAllEventHandlers "FiredNear";
  153. _unit removeAllEventHandlers "HandleDamage";
  154. _unit removeAllEventHandlers "Killed";
  155. _unit removeAllEventHandlers "Fired";
  156. _unit removeAllEventHandlers "GetOut";
  157. _unit removeAllEventHandlers "GetIn";
  158. _unit removeAllEventHandlers "Local";
  159. clearVehicleInit _unit;
  160. deleteVehicle _unit;
  161. deleteGroup _myGroupUnit;
  162. //_unit = nil;
  163. diag_log ("CLEANUP: DELETED A " + str(_type) );
  164. };
  165. }];
  166. };
  167.  
  168. server_hiveWrite = {
  169. private["_data"];
  170. _data = "HiveExt" callExtension _this;
  171. };
  172.  
  173. server_hiveReadWrite = {
  174. private["_key","_resultArray","_data"];
  175. _key = _this;
  176. _data = "HiveExt" callExtension _key;
  177. _resultArray = call compile format ["%1",_data];
  178. _resultArray
  179. };
  180.  
  181. server_hiveReadWriteLarge = {
  182. private["_key","_resultArray","_data"];
  183. _key = _this;
  184. _data = "HiveExt" callExtension _key;
  185. _resultArray = call compile _data;
  186. _resultArray
  187. };
  188.  
  189. server_checkIfTowed = {
  190. private ["_vehicle","_player","_attached"];
  191. if (DZE_HeliLift) then {
  192. _vehicle = _this select 0;
  193. _player = _this select 2;
  194. _attached = _vehicle getVariable["attached",false];
  195. if ((typeName _attached == "OBJECT")) then {
  196. _player action ["eject", _vehicle];
  197. detach _vehicle;
  198. _vehicle setVariable["attached",false,true];
  199. _attached setVariable["hasAttached",false,true];
  200. };
  201. };
  202. };
  203.  
  204. server_characterSync = {
  205. private ["_characterID","_playerPos","_playerGear","_playerBackp","_medical","_currentState","_currentModel","_key"];
  206. _characterID = _this select 0;
  207. _playerPos = _this select 1;
  208. _playerGear = _this select 2;
  209. _playerBackp = _this select 3;
  210. _medical = _this select 4;
  211. _currentState = _this select 5;
  212. _currentModel = _this select 6;
  213.  
  214. _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];
  215. _key call server_hiveWrite;
  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. _key = format["CHILD:103:%1:%2:%3:",_this select 0,_this select 1,_this select 2];
  627. _key call server_hiveWrite;
  628. };
  629.  
  630. //----------InitMissions--------//
  631. MissionGo = 0;
  632. MissionGoMinor = 0;
  633. if (isServer) then {
  634. SMarray = ["SM1","SM2","SM3","SM4","SM5","SM6"];
  635. [] execVM "\z\addons\dayz_server\missions\major\SMfinder.sqf"; //Starts major mission system
  636. SMarray2 = ["SM1","SM2","SM3","SM4","SM5","SM6"];
  637. [] execVM "\z\addons\dayz_server\missions\minor\SMfinder.sqf"; //Starts minor mission system
  638. };
  639. //---------EndInitMissions------//
  640.  
  641. dayz_perform_purge = {
  642. if(!isNull(_this)) then {
  643. _this removeAllMPEventHandlers "mpkilled";
  644. _this removeAllMPEventHandlers "mphit";
  645. _this removeAllMPEventHandlers "mprespawn";
  646. _this removeAllEventHandlers "FiredNear";
  647. _this removeAllEventHandlers "HandleDamage";
  648. _this removeAllEventHandlers "Killed";
  649. _this removeAllEventHandlers "Fired";
  650. _this removeAllEventHandlers "GetOut";
  651. _this removeAllEventHandlers "GetIn";
  652. _this removeAllEventHandlers "Local";
  653. clearVehicleInit _this;
  654. deleteVehicle _this;
  655. deleteGroup (group _this);
  656. };
  657. };
  658.  
  659. dayz_perform_purge_player = {
  660.  
  661. private ["_countr","_backpack","_backpackType","_backpackWpn","_backpackMag","_objWpnTypes","_objWpnQty","_location","_dir","_holder","_weapons","_magazines"];
  662. diag_log ("Purging player: " + str(_this));
  663.  
  664. if(!isNull(_this)) then {
  665.  
  666. _location = getPosATL _this;
  667. _dir = getDir _this;
  668.  
  669. _holder = createVehicle ["GraveDZE", _location, [], 0, "CAN_COLLIDE"];
  670. _holder setDir _dir;
  671. _holder setPosATL _location;
  672.  
  673. _holder enableSimulation false;
  674.  
  675. _weapons = weapons _this;
  676. _magazines = magazines _this;
  677.  
  678. // find backpack
  679. if(!(isNull unitBackpack _this)) then {
  680. _backpack = unitBackpack _this;
  681. _backpackType = typeOf _backpack;
  682. _backpackWpn = getWeaponCargo _backpack;
  683. _backpackMag = getMagazineCargo _backpack;
  684.  
  685. _holder addBackpackCargoGlobal [_backpackType,1];
  686.  
  687. // add items from backpack
  688. _objWpnTypes = _backpackWpn select 0;
  689. _objWpnQty = _backpackWpn select 1;
  690. _countr = 0;
  691. {
  692. _holder addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  693. _countr = _countr + 1;
  694. } forEach _objWpnTypes;
  695.  
  696. // add backpack magazine items
  697. _objWpnTypes = _backpackMag select 0;
  698. _objWpnQty = _backpackMag select 1;
  699. _countr = 0;
  700. {
  701. _holder addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  702. _countr = _countr + 1;
  703. } forEach _objWpnTypes;
  704. };
  705. };
  706.  
  707. // add weapons
  708. {
  709. _holder addWeaponCargoGlobal [_x, 1];
  710. } forEach _weapons;
  711.  
  712. // add mags
  713. {
  714. _holder addMagazineCargoGlobal [_x, 1];
  715. } forEach _magazines;
  716.  
  717. _this removeAllMPEventHandlers "mpkilled";
  718. _this removeAllMPEventHandlers "mphit";
  719. _this removeAllMPEventHandlers "mprespawn";
  720. _this removeAllEventHandlers "FiredNear";
  721. _this removeAllEventHandlers "HandleDamage";
  722. _this removeAllEventHandlers "Killed";
  723. _this removeAllEventHandlers "Fired";
  724. _this removeAllEventHandlers "GetOut";
  725. _this removeAllEventHandlers "GetIn";
  726. _this removeAllEventHandlers "Local";
  727. clearVehicleInit _this;
  728. deleteVehicle _this;
  729. deleteGroup (group _this);
  730. // _this = nil;
  731. };
  732.  
  733.  
  734. dayz_removePlayerOnDisconnect = {
  735. if(!isNull(_this)) then {
  736. _this removeAllMPEventHandlers "mphit";
  737. deleteVehicle _this;
  738. deleteGroup (group _this);
  739. };
  740. };
  741.  
  742. server_timeSync = {
  743. //Send request
  744. private ["_hour","_minute","_date","_key","_result","_outcome"];
  745. _key = "CHILD:307:";
  746. _result = _key call server_hiveReadWrite;
  747. _outcome = _result select 0;
  748. if(_outcome == "PASS") then {
  749. _date = _result select 1;
  750.  
  751. if(dayz_fullMoonNights) then {
  752. _hour = _date select 3;
  753. _minute = _date select 4;
  754. //Force full moon nights
  755. _date = [2013,8,3,_hour,_minute];
  756. };
  757.  
  758. setDate _date;
  759. PVDZE_plr_SetDate = _date;
  760. publicVariable "PVDZE_plr_SetDate";
  761. diag_log ("TIME SYNC: Local Time set to " + str(_date));
  762. };
  763. };
  764.  
  765. // must spawn these
  766. server_spawncleanDead = {
  767. private ["_deathTime","_delQtyZ","_delQtyP","_qty","_allDead"];
  768. _allDead = allDead;
  769. _delQtyZ = 0;
  770. _delQtyP = 0;
  771. {
  772. if (local _x) then {
  773. if (_x isKindOf "zZombie_Base") then
  774. {
  775. _x call dayz_perform_purge;
  776. sleep 0.05;
  777. _delQtyZ = _delQtyZ + 1;
  778. } else {
  779. if (_x isKindOf "CAManBase") then {
  780. _deathTime = _x getVariable ["processedDeath", diag_tickTime];
  781. if (diag_tickTime - _deathTime > 1800) then {
  782. _x call dayz_perform_purge_player;
  783. sleep 0.025;
  784. _delQtyP = _delQtyP + 1;
  785. };
  786. };
  787. };
  788. };
  789. sleep 0.025;
  790. } forEach _allDead;
  791. if (_delQtyZ > 0 or _delQtyP > 0) then {
  792. _qty = count _allDead;
  793. diag_log (format["CLEANUP: Deleted %1 players and %2 zombies out of %3 dead",_delQtyP,_delQtyZ,_qty]);
  794. };
  795. };
  796. server_cleanupGroups = {
  797. if (DZE_DYN_AntiStuck3rd > 3) then { DZE_DYN_GroupCleanup = nil; DZE_DYN_AntiStuck3rd = 0; };
  798. if(!isNil "DZE_DYN_GroupCleanup") exitWith { DZE_DYN_AntiStuck3rd = DZE_DYN_AntiStuck3rd + 1;};
  799. DZE_DYN_GroupCleanup = true;
  800. {
  801. if ((count units _x == 0) && !(_x getVariable["SAR_protect",false])) then { //Edited by XsG to prevent SAR_AI Units being cleaned
  802. deleteGroup _x;
  803. };
  804. sleep 0.001;
  805. } forEach allGroups;
  806. DZE_DYN_GroupCleanup = nil;
  807. };
  808.  
  809. server_checkHackers = {
  810. if (DZE_DYN_AntiStuck2nd > 3) then { DZE_DYN_HackerCheck = nil; DZE_DYN_AntiStuck2nd = 0; };
  811. if(!isNil "DZE_DYN_HackerCheck") exitWith { DZE_DYN_AntiStuck2nd = DZE_DYN_AntiStuck2nd + 1;};
  812. DZE_DYN_HackerCheck = true;
  813. {
  814. if(vehicle _x != _x && (vehicle _x getVariable ["Sarge",0] != 1) && !(vehicle _x in PVDZE_serverObjectMonitor) && (isPlayer _x) && !((typeOf vehicle _x) in DZE_safeVehicle)) && !(vehicle _x getVariable ["Mission",0] != 1) && (vehicle _x getVariable ["Sarge",0] != 1) ) then { //Edited by XsG to prevent mission and Sar_AI units triggering anti-hack.
  815. diag_log ("CLEANUP: KILLING A HACKER " + (name _x) + " " + str(_x) + " IN " + (typeOf vehicle _x));
  816. (vehicle _x) setDamage 0.1;
  817. _x setDamage 0.1;
  818. sleep 0.25;
  819. };
  820. sleep 0.001;
  821. } forEach allUnits;
  822. DZE_DYN_HackerCheck = nil;
  823. };
  824.  
  825. server_spawnCleanFire = {
  826. private ["_delQtyFP","_qty","_delQtyNull","_missionFires"];
  827. _missionFires = allMissionObjects "Land_Fire_DZ";
  828. _delQtyFP = 0;
  829. {
  830. if (local _x) then {
  831. deleteVehicle _x;
  832. sleep 0.025;
  833. _delQtyFP = _delQtyFP + 1;
  834. };
  835. sleep 0.001;
  836. } forEach _missionFires;
  837. if (_delQtyFP > 0) then {
  838. _qty = count _missionFires;
  839. diag_log (format["CLEANUP: Deleted %1 fireplaces out of %2",_delQtyNull,_qty]);
  840. };
  841. };
  842. server_spawnCleanLoot = {
  843. private ["_created","_delQty","_nearby","_age","_keep","_qty","_missionObjs","_dateNow"];
  844. if (DZE_DYN_AntiStuck > 3) then { DZE_DYN_cleanLoot = nil; DZE_DYN_AntiStuck = 0; };
  845. if(!isNil "DZE_DYN_cleanLoot") exitWith { DZE_DYN_AntiStuck = DZE_DYN_AntiStuck + 1;};
  846. DZE_DYN_cleanLoot = true;
  847.  
  848. _missionObjs = allMissionObjects "ReammoBox";
  849. _delQty = 0;
  850. _dateNow = (DateToNumber date);
  851. {
  852. _keep = _x getVariable ["permaLoot",false];
  853. if (!_keep) then {
  854. _created = _x getVariable ["created",-0.1];
  855. if (_created == -0.1) then {
  856. _x setVariable ["created",_dateNow,false];
  857. _created = _dateNow;
  858. } else {
  859. _age = (_dateNow - _created) * 525948;
  860. if (_age > 20) then {
  861. _nearby = {(isPlayer _x) and (alive _x)} count (_x nearEntities [["CAManBase","AllVehicles"], 130]);
  862. if (_nearby==0) then {
  863. deleteVehicle _x;
  864. sleep 0.025;
  865. _delQty = _delQty + 1;
  866. };
  867. };
  868. };
  869. };
  870. sleep 0.001;
  871. } forEach _missionObjs;
  872. if (_delQty > 0) then {
  873. _qty = count _missionObjs;
  874. diag_log (format["CLEANUP: Deleted %1 Loot Piles out of %2",_delQty,_qty]);
  875. };
  876. DZE_DYN_cleanLoot = nil;
  877. };
  878.  
  879. server_spawnCleanAnimals = {
  880. private ["_pos","_delQtyAnimal","_qty","_missonAnimals","_nearby"];
  881. _missonAnimals = entities "CAAnimalBase";
  882. _delQtyAnimal = 0;
  883. {
  884. if (local _x) then {
  885. _x call dayz_perform_purge;
  886. sleep 0.05;
  887. _delQtyAnimal = _delQtyAnimal + 1;
  888. } else {
  889. if (!alive _x) then {
  890. _pos = getPosATL _x;
  891. if (count _pos > 0) then {
  892. _nearby = {(isPlayer _x) and (alive _x)} count (_pos nearEntities [["CAManBase","AllVehicles"], 130]);
  893. if (_nearby==0) then {
  894. _x call dayz_perform_purge;
  895. sleep 0.05;
  896. _delQtyAnimal = _delQtyAnimal + 1;
  897. };
  898. };
  899. };
  900. };
  901. sleep 0.001;
  902. } forEach _missonAnimals;
  903. if (_delQtyAnimal > 0) then {
  904. _qty = count _missonAnimals;
  905. diag_log (format["CLEANUP: Deleted %1 Animals out of %2",_delQtyAnimal,_qty]);
  906. };
  907. };
  908.  
  909. server_getLocalObjVars = {
  910. private ["_player","_obj","_objectID","_objectUID","_weapons","_magazines","_backpacks"];
  911.  
  912. _player = _this select 0;
  913. _obj = _this select 1;
  914.  
  915. _objectID = _obj getVariable["ObjectID","0"];
  916. _objectUID = _obj getVariable["ObjectUID","0"];
  917.  
  918. _weapons = _obj getVariable ["WeaponCargo", false];
  919. _magazines = _obj getVariable ["MagazineCargo", false];
  920. _backpacks = _obj getVariable ["BackpackCargo", false];
  921.  
  922. PVDZE_localVarsResult = [_weapons,_magazines,_backpacks];
  923. (owner _player) publicVariableClient "PVDZE_localVarsResult";
  924.  
  925. diag_log format["SAFE UNLOCKED: ID:%1 UID:%2 BY %3(%4)", _objectID, _objectUID, (name _player), (getPlayerUID _player)];
  926. };
  927.  
  928. server_setLocalObjVars = {
  929. private ["_obj","_holder","_weapons","_magazines","_backpacks","_player","_objectID","_objectUID"];
  930.  
  931. _obj = _this select 0;
  932. _holder = _this select 1;
  933. _player = _this select 2;
  934.  
  935. _objectID = _obj getVariable["ObjectID","0"];
  936. _objectUID = _obj getVariable["ObjectUID","0"];
  937.  
  938. _weapons = getWeaponCargo _obj;
  939. _magazines = getMagazineCargo _obj;
  940. _backpacks = getBackpackCargo _obj;
  941.  
  942. deleteVehicle _obj;
  943.  
  944. _holder setVariable ["WeaponCargo", _weapons];
  945. _holder setVariable ["MagazineCargo", _magazines];
  946. _holder setVariable ["BackpackCargo", _backpacks];
  947.  
  948. diag_log format["SAFE LOCKED: ID:%1 UID:%2 BY %3(%4)", _objectID, _objectUID, (name _player), (getPlayerUID _player)];
  949. };
  950.  
  951. //Set Default Starting loadout
  952. //XSG_startinginventory = [];
  953. //XSG_startingbackpack = [];
  954. //XSG_startinginfection = 0 ;
  955. //XSG_startingmodel = "";
Advertisement
Add Comment
Please, Sign In to add comment