Guest User

server_functions.sqf

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