Advertisement
Guest User

server_functions.sqf

a guest
Feb 18th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.25 KB | None | 0 0
  1. [] execVM "\z\addons\dayz_server\init\AH.sqf";
  2. waituntil {!isnil "bis_fnc_init"};
  3.  
  4. BIS_MPF_remoteExecutionServer = {
  5. if ((_this select 1) select 2 == "JIPrequest") then {
  6. [nil,(_this select 1) select 0,"loc",rJIPEXEC,[any,any,"per","execVM","ca\Modules\Functions\init.sqf"]] call RE;
  7. };
  8. };
  9.  
  10. BIS_Effects_Burn = {};
  11.  
  12. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\KK_Functions.sqf";
  13.  
  14. server_playerLogin = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_playerLogin.sqf";
  15. server_playerSetup = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_playerSetup.sqf";
  16. server_onPlayerDisconnect = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_onPlayerDisconnect.sqf";
  17. server_updateObject = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_updateObject.sqf";
  18. server_playerDied = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_playerDied.sqf";
  19. server_publishObj = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_publishObject.sqf";
  20. server_publishFullObject = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_publishFullObject.sqf";
  21. server_deleteObj = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_deleteObj.sqf";
  22. server_swapObject = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_swapObject.sqf";
  23. server_publishVeh = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_publishVehicle.sqf";
  24. server_publishVeh2 = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_publishVehicle2.sqf";
  25. server_publishVeh3 = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_publishVehicle3.sqf";
  26. server_tradeObj = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_tradeObject.sqf";
  27. server_traders = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_traders.sqf";
  28. server_playerSync = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_playerSync.sqf";
  29. server_spawnCrashSite = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_spawnCrashSite.sqf";
  30. server_spawnEvents = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_spawnEvent.sqf";
  31. //server_weather = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_weather.sqf";
  32. fnc_plyrHit = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_plyrHit.sqf";
  33. server_deaths = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_playerDeaths.sqf";
  34. server_maintainArea = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_maintainArea.sqf";
  35.  
  36. /* PVS/PVC - Skaronator */
  37. server_sendToClient = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_sendToClient.sqf";
  38.  
  39. //onPlayerConnected {[_uid,_name] call server_onPlayerConnect;};
  40. onPlayerDisconnected {[_uid,_name] call server_onPlayerDisconnect;};
  41.  
  42. server_updateNearbyObjects = {
  43. private["_pos"];
  44. _pos = _this select 0;
  45. {
  46. [_x, "gear"] call server_updateObject;
  47. } count nearestObjects [_pos, dayz_updateObjects, 10];
  48. };
  49.  
  50. server_handleZedSpawn = {
  51. private["_zed"];
  52. _zed = _this select 0;
  53. _zed enableSimulation false;
  54. };
  55.  
  56. zombie_findOwner = {
  57. private["_unit"];
  58. _unit = _this select 0;
  59. #ifdef DZE_SERVER_DEBUG
  60. diag_log ("CLEANUP: DELETE UNCONTROLLED ZOMBIE: " + (typeOf _unit) + " OF: " + str(_unit) );
  61. #endif
  62. deleteVehicle _unit;
  63. };
  64.  
  65. vehicle_handleInteract = {
  66. private["_object"];
  67. _object = _this select 0;
  68. needUpdate_objects = needUpdate_objects - [_object];
  69. [_object, "all"] call server_updateObject;
  70. };
  71.  
  72. array_reduceSizeReverse = {
  73. private["_array","_count","_num","_newarray","_startnum","_index"];
  74. _array = _this select 0;
  75. _newarray = [];
  76. _count = _this select 1;
  77. _num = count _array;
  78. if (_num > _count) then {
  79. _startnum = _num - 1;
  80. _index = _count - 1;
  81. for "_i" from 0 to _index do {
  82. _newarray set [(_index-_i),_array select (_startnum - _i)];
  83. };
  84. _array = _newarray;
  85. };
  86. _array
  87. };
  88.  
  89. array_reduceSize = {
  90. private ["_array1","_array","_count","_num"];
  91. _array1 = _this select 0;
  92. _array = _array1 - ["Hatchet_Swing","Machete_Swing","Fishing_Swing","sledge_swing","crowbar_swing","CSGAS"];
  93. _count = _this select 1;
  94. _num = count _array;
  95. if (_num > _count) then {
  96. _array resize _count;
  97. };
  98. _array
  99. };
  100.  
  101. object_handleServerKilled = {
  102. private["_unit","_objectID","_objectUID","_killer"];
  103. _unit = _this select 0;
  104. _killer = _this select 1;
  105.  
  106. _objectID = _unit getVariable ["ObjectID","0"];
  107. _objectUID = _unit getVariable ["ObjectUID","0"];
  108.  
  109. [_objectID,_objectUID,_killer] call server_deleteObj;
  110.  
  111. _unit removeAllMPEventHandlers "MPKilled";
  112. _unit removeAllEventHandlers "Killed";
  113. _unit removeAllEventHandlers "HandleDamage";
  114. _unit removeAllEventHandlers "GetIn";
  115. _unit removeAllEventHandlers "GetOut";
  116. };
  117.  
  118. check_publishobject = {
  119. private["_allowed","_object","_playername"];
  120.  
  121. _object = _this select 0;
  122. _playername = _this select 1;
  123. _allowed = false;
  124.  
  125. if ((typeOf _object) in dayz_allowedObjects) then {
  126. //diag_log format ["DEBUG: Object: %1 published by %2 is Safe",_object, _playername];
  127. _allowed = true;
  128. };
  129. _allowed
  130. };
  131.  
  132. //event Handlers
  133. eh_localCleanup = {
  134. private ["_object"];
  135. _object = _this select 0;
  136. _object addEventHandler ["local", {
  137. if(_this select 1) then {
  138. private["_type","_unit"];
  139. _unit = _this select 0;
  140. _type = typeOf _unit;
  141. _myGroupUnit = group _unit;
  142. _unit removeAllMPEventHandlers "mpkilled";
  143. _unit removeAllMPEventHandlers "mphit";
  144. _unit removeAllMPEventHandlers "mprespawn";
  145. _unit removeAllEventHandlers "FiredNear";
  146. _unit removeAllEventHandlers "HandleDamage";
  147. _unit removeAllEventHandlers "Killed";
  148. _unit removeAllEventHandlers "Fired";
  149. _unit removeAllEventHandlers "GetOut";
  150. _unit removeAllEventHandlers "GetIn";
  151. _unit removeAllEventHandlers "Local";
  152. clearVehicleInit _unit;
  153. deleteVehicle _unit;
  154. if ((count (units _myGroupUnit) == 0) && (_myGroupUnit != grpNull)) then {
  155. deleteGroup _myGroupUnit;
  156. };
  157. //_unit = nil;
  158. // diag_log ("CLEANUP: DELETED A " + str(_type) );
  159. };
  160. }];
  161. };
  162.  
  163. server_hiveWrite = {
  164. private["_data"];
  165. _data = "HiveExt" callExtension _this;
  166. };
  167.  
  168. server_hiveReadWrite = {
  169. private["_key","_resultArray","_data"];
  170. _key = _this;
  171. _data = "HiveExt" callExtension _key;
  172. _resultArray = call compile format ["%1",_data];
  173. _resultArray
  174. };
  175.  
  176. server_hiveReadWriteLarge = {
  177. private["_key","_resultArray","_data"];
  178. _key = _this;
  179. _data = "HiveExt" callExtension _key;
  180. _resultArray = call compile _data;
  181. _resultArray
  182. };
  183.  
  184. server_checkIfTowed = {
  185. private ["_vehicle","_player","_attached"];
  186. if (DZE_HeliLift) then {
  187. _vehicle = _this select 0;
  188. _player = _this select 2;
  189. _attached = _vehicle getVariable["attached",false];
  190. if (typeName _attached == "OBJECT") then {
  191. _player action ["eject", _vehicle];
  192. detach _vehicle;
  193. _vehicle setVariable["attached",false,true];
  194. _attached setVariable["hasAttached",false,true];
  195. };
  196. };
  197. };
  198.  
  199. server_characterSync = {
  200. private ["_characterID","_playerPos","_playerGear","_playerBackp","_medical","_currentState","_currentModel","_key"];
  201. _characterID = _this select 0;
  202. _playerPos = _this select 1;
  203. _playerGear = _this select 2;
  204. _playerBackp = _this select 3;
  205. _medical = _this select 4;
  206. _currentState = _this select 5;
  207. _currentModel = _this select 6;
  208.  
  209. _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];
  210. _key call server_hiveWrite;
  211. };
  212.  
  213. if(isnil "dayz_MapArea") then {
  214. dayz_MapArea = 10000;
  215. };
  216. if(isnil "DynamicVehicleArea") then {
  217. DynamicVehicleArea = dayz_MapArea / 2;
  218. };
  219.  
  220. // Get all buildings && roads only once TODO: set variables to nil after done if nessicary
  221. MarkerPosition = getMarkerPos "center";
  222. RoadList = MarkerPosition nearRoads DynamicVehicleArea;
  223.  
  224. // Very taxing !!! but only on first startup
  225. BuildingList = [];
  226. {
  227. if (DZE_MissionLootTable) then {
  228. if (isClass (missionConfigFile >> "CfgBuildingLoot" >> (typeOf _x))) then
  229. {
  230. BuildingList set [count BuildingList,_x];
  231. };
  232. } else {
  233. if (isClass (configFile >> "CfgBuildingLoot" >> (typeOf _x))) then
  234. {
  235. BuildingList set [count BuildingList,_x];
  236. };
  237. };
  238.  
  239.  
  240. } count (MarkerPosition nearObjects ["building",DynamicVehicleArea]);
  241.  
  242. spawn_vehicles = {
  243. private ["_random","_lastIndex","_weights","_index","_vehicle","_velimit","_qty","_isAir","_isShip","_position","_dir","_istoomany","_veh","_objPosition","_marker","_iClass","_itemTypes","_cntWeights","_itemType","_num","_allCfgLoots"];
  244.  
  245. if (!isDedicated) exitWith { }; //Be sure the run this
  246.  
  247. while {count AllowedVehiclesList > 0} do {
  248. // BIS_fnc_selectRandom replaced because the index may be needed to remove the element
  249. _index = floor random count AllowedVehiclesList;
  250. _random = AllowedVehiclesList select _index;
  251.  
  252. _vehicle = _random select 0;
  253. _velimit = _random select 1;
  254.  
  255. _qty = {_x == _vehicle} count serverVehicleCounter;
  256.  
  257. // If under limit allow to proceed
  258. if (_qty <= _velimit) exitWith {};
  259.  
  260. // vehicle limit reached, remove vehicle from list
  261. // since elements cannot be removed from an array, overwrite it with the last element && cut the last element of (as long as order is not important)
  262. _lastIndex = (count AllowedVehiclesList) - 1;
  263. if (_lastIndex != _index) then {
  264. AllowedVehiclesList set [_index, AllowedVehiclesList select _lastIndex];
  265. };
  266. AllowedVehiclesList resize _lastIndex;
  267. };
  268.  
  269. if (count AllowedVehiclesList == 0) then {
  270. diag_log("DEBUG: unable to find suitable vehicle to spawn");
  271. } else {
  272.  
  273. // add vehicle to counter for next pass
  274. serverVehicleCounter set [count serverVehicleCounter,_vehicle];
  275.  
  276. // Find Vehicle Type to better control spawns
  277. _isAir = _vehicle isKindOf "Air";
  278. _isShip = _vehicle isKindOf "Ship";
  279.  
  280. if(_isShip || _isAir) then {
  281. if(_isShip) then {
  282. // Spawn anywhere on coast on water
  283. waitUntil{!isNil "BIS_fnc_findSafePos"};
  284. _position = [MarkerPosition,0,DynamicVehicleArea,10,1,2000,1] call BIS_fnc_findSafePos;
  285. //diag_log("DEBUG: spawning boat near coast " + str(_position));
  286. } else {
  287. // Spawn air anywhere that is flat
  288. waitUntil{!isNil "BIS_fnc_findSafePos"};
  289. _position = [MarkerPosition,0,DynamicVehicleArea,10,0,2000,0] call BIS_fnc_findSafePos;
  290. //diag_log("DEBUG: spawning air anywhere flat " + str(_position));
  291. };
  292.  
  293.  
  294. } else {
  295. // Spawn around buildings && 50% near roads
  296. if((random 1) > 0.5) then {
  297.  
  298. waitUntil{!isNil "BIS_fnc_selectRandom"};
  299. _position = RoadList call BIS_fnc_selectRandom;
  300.  
  301. _position = _position modelToWorld [0,0,0];
  302.  
  303. waitUntil{!isNil "BIS_fnc_findSafePos"};
  304. _position = [_position,0,10,10,0,2000,0] call BIS_fnc_findSafePos;
  305.  
  306. //diag_log("DEBUG: spawning near road " + str(_position));
  307.  
  308. } else {
  309.  
  310. waitUntil{!isNil "BIS_fnc_selectRandom"};
  311. _position = BuildingList call BIS_fnc_selectRandom;
  312.  
  313. _position = _position modelToWorld [0,0,0];
  314.  
  315. waitUntil{!isNil "BIS_fnc_findSafePos"};
  316. _position = [_position,0,40,5,0,2000,0] call BIS_fnc_findSafePos;
  317.  
  318. //diag_log("DEBUG: spawning around buildings " + str(_position));
  319.  
  320. };
  321. };
  322. // only proceed if two params otherwise BIS_fnc_findSafePos failed && may spawn in air
  323. if ((count _position) == 2) then {
  324.  
  325. _dir = round(random 180);
  326.  
  327. _istoomany = _position nearObjects ["AllVehicles",50];
  328. if((count _istoomany) > 0) exitWith { diag_log("DEBUG: Too many vehicles at " + str(_position)); };
  329.  
  330. //place vehicle
  331. _veh = createVehicle [_vehicle, _position, [], 0, "CAN_COLLIDE"];
  332. _veh setdir _dir;
  333. _veh setpos _position;
  334.  
  335. if(DZEdebug) then {
  336. _marker = createMarker [str(_position) , _position];
  337. _marker setMarkerShape "ICON";
  338. _marker setMarkerType "DOT";
  339. _marker setMarkerText _vehicle;
  340. };
  341.  
  342. // Get position with ground
  343. _objPosition = getPosATL _veh;
  344.  
  345. clearWeaponCargoGlobal _veh;
  346. clearMagazineCargoGlobal _veh;
  347. // _veh setVehicleAmmo DZE_vehicleAmmo;
  348.  
  349. // Add 0-3 loots to vehicle using random cfgloots
  350. _num = floor(random 4);
  351. _allCfgLoots = ["trash","civilian","food","generic","medical","military","policeman","hunter","worker","clothes","militaryclothes","specialclothes","trash"];
  352.  
  353. for "_x" from 1 to _num do {
  354. _iClass = _allCfgLoots call BIS_fnc_selectRandom;
  355.  
  356. _itemTypes = [];
  357. if (DZE_MissionLootTable) then{
  358. {
  359. _itemTypes set[count _itemTypes, _x select 0]
  360. } count getArray(missionConfigFile >> "cfgLoot" >> _iClass);
  361. }
  362. else {
  363. {
  364. _itemTypes set[count _itemTypes, _x select 0]
  365. } count getArray(configFile >> "cfgLoot" >> _iClass);
  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. } count _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. } count _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. #include "ESSconfig.sqf"
  630. currentInvites = [];
  631. publicVariable "currentInvites";
  632.  
  633. dayz_perform_purge = {
  634. if(!isNull(_this)) then {
  635. _group = group _this;
  636. _this removeAllMPEventHandlers "mpkilled";
  637. _this removeAllMPEventHandlers "mphit";
  638. _this removeAllMPEventHandlers "mprespawn";
  639. _this removeAllEventHandlers "FiredNear";
  640. _this removeAllEventHandlers "HandleDamage";
  641. _this removeAllEventHandlers "Killed";
  642. _this removeAllEventHandlers "Fired";
  643. _this removeAllEventHandlers "GetOut";
  644. _this removeAllEventHandlers "GetIn";
  645. _this removeAllEventHandlers "Local";
  646. clearVehicleInit _this;
  647. deleteVehicle _this;
  648. if ((count (units _group) == 0) && (_group != grpNull)) then {
  649. deleteGroup _group;
  650. };
  651. };
  652. };
  653.  
  654. dayz_perform_purge_player = {
  655.  
  656. private ["_countr","_backpack","_backpackType","_backpackWpn","_backpackMag","_objWpnTypes","_objWpnQty","_location","_dir","_holder","_weapons","_magazines"];
  657. diag_log ("Purging player: " + str(_this));
  658.  
  659. if(!isNull(_this)) then {
  660.  
  661. _location = getPosATL _this;
  662. _dir = getDir _this;
  663.  
  664. _holder = createVehicle ["GraveDZE", _location, [], 0, "CAN_COLLIDE"];
  665. _holder setDir _dir;
  666. _holder setPosATL _location;
  667.  
  668. _holder enableSimulation false;
  669.  
  670. _weapons = weapons _this;
  671. _magazines = magazines _this;
  672.  
  673. // find backpack
  674. if(!(isNull unitBackpack _this)) then {
  675. _backpack = unitBackpack _this;
  676. _backpackType = typeOf _backpack;
  677. _backpackWpn = getWeaponCargo _backpack;
  678. _backpackMag = getMagazineCargo _backpack;
  679.  
  680. _holder addBackpackCargoGlobal [_backpackType,1];
  681.  
  682. // add items from backpack
  683. _objWpnTypes = _backpackWpn select 0;
  684. _objWpnQty = _backpackWpn select 1;
  685. _countr = 0;
  686. {
  687. _holder addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  688. _countr = _countr + 1;
  689. } count _objWpnTypes;
  690.  
  691. // add backpack magazine items
  692. _objWpnTypes = _backpackMag select 0;
  693. _objWpnQty = _backpackMag select 1;
  694. _countr = 0;
  695. {
  696. _holder addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  697. _countr = _countr + 1;
  698. } count _objWpnTypes;
  699. };
  700. };
  701.  
  702. // add weapons
  703. {
  704. _holder addWeaponCargoGlobal [_x, 1];
  705. } count _weapons;
  706.  
  707. // add mags
  708. {
  709. _holder addMagazineCargoGlobal [_x, 1];
  710. } count _magazines;
  711. _group = group _this;
  712. _this removeAllMPEventHandlers "mpkilled";
  713. _this removeAllMPEventHandlers "mphit";
  714. _this removeAllMPEventHandlers "mprespawn";
  715. _this removeAllEventHandlers "FiredNear";
  716. _this removeAllEventHandlers "HandleDamage";
  717. _this removeAllEventHandlers "Killed";
  718. _this removeAllEventHandlers "Fired";
  719. _this removeAllEventHandlers "GetOut";
  720. _this removeAllEventHandlers "GetIn";
  721. _this removeAllEventHandlers "Local";
  722. clearVehicleInit _this;
  723. deleteVehicle _this;
  724. if ((count (units _group) == 0) && (_group != grpNull)) then {
  725. deleteGroup _group;
  726. };
  727. // _this = nil;
  728. };
  729.  
  730.  
  731. dayz_removePlayerOnDisconnect = {
  732. if(!isNull(_this)) then {
  733. _group = group _this;
  734. _this removeAllMPEventHandlers "mphit";
  735. deleteVehicle _this;
  736. deleteGroup (group _this);
  737. };
  738. };
  739.  
  740. server_timeSync = {
  741. //Send request
  742. private ["_hour","_minute","_date","_key","_result","_outcome"];
  743. _key = "CHILD:307:";
  744. _result = _key call server_hiveReadWrite;
  745. _outcome = _result select 0;
  746. if(_outcome == "PASS") then {
  747. _date = _result select 1;
  748.  
  749. if(dayz_fullMoonNights) then {
  750. _hour = _date select 3;
  751. _minute = _date select 4;
  752. //Force full moon nights
  753. _date = [2013,8,3,_hour,_minute];
  754. };
  755.  
  756. setDate _date;
  757. PVDZE_plr_SetDate = _date;
  758. publicVariable "PVDZE_plr_SetDate";
  759. diag_log ("TIME SYNC: Local Time set to " + str(_date));
  760. };
  761. };
  762.  
  763. // must spawn these
  764. server_spawncleanDead = {
  765. private ["_deathTime","_delQtyZ","_delQtyP","_qty","_allDead"];
  766. _allDead = allDead;
  767. _delQtyZ = 0;
  768. _delQtyP = 0;
  769. {
  770. if (local _x) then {
  771. if (_x isKindOf "zZombie_Base") then
  772. {
  773. _x call dayz_perform_purge;
  774. sleep 0.05;
  775. _delQtyZ = _delQtyZ + 1;
  776. } else {
  777. if (_x isKindOf "CAManBase") then {
  778. _deathTime = _x getVariable ["processedDeath", diag_tickTime];
  779. if (diag_tickTime - _deathTime > 1800) then {
  780. _x call dayz_perform_purge_player;
  781. sleep 0.025;
  782. _delQtyP = _delQtyP + 1;
  783. };
  784. };
  785. };
  786. };
  787. sleep 0.025;
  788. } count _allDead;
  789. if (_delQtyZ > 0 || _delQtyP > 0) then {
  790. _qty = count _allDead;
  791. diag_log (format["CLEANUP: Deleted %1 players && %2 zombies out of %3 dead",_delQtyP,_delQtyZ,_qty]);
  792. };
  793. };
  794. server_cleanupGroups = {
  795. if (DZE_DYN_AntiStuck3rd > 3) then { DZE_DYN_GroupCleanup = nil; DZE_DYN_AntiStuck3rd = 0; };
  796. if(!isNil "DZE_DYN_GroupCleanup") exitWith { DZE_DYN_AntiStuck3rd = DZE_DYN_AntiStuck3rd + 1;};
  797. DZE_DYN_GroupCleanup = true;
  798. {
  799. if ((count (units _x) == 0) && (_x != grpNull)) then {
  800. deleteGroup _x;
  801. };
  802. sleep 0.001;
  803. } count allGroups;
  804. DZE_DYN_GroupCleanup = nil;
  805. };
  806.  
  807. server_checkHackers = {
  808. if (DZE_DYN_AntiStuck2nd > 3) then { DZE_DYN_HackerCheck = nil; DZE_DYN_AntiStuck2nd = 0; };
  809. if(!isNil "DZE_DYN_HackerCheck") exitWith { DZE_DYN_AntiStuck2nd = DZE_DYN_AntiStuck2nd + 1;};
  810. DZE_DYN_HackerCheck = true;
  811. {
  812. if (!((isNil "_x") || {(isNull _x)})) then {
  813. if(vehicle _x != _x && !(vehicle _x in PVDZE_serverObjectMonitor) && (isPlayer _x) && !((typeOf vehicle _x) in DZE_safeVehicle) && (vehicle _x getVariable ["MalSar",0] !=1)) then {
  814. diag_log ("CLEANUP: KILLING A HACKER " + (name _x) + " " + str(_x) + " IN " + (typeOf vehicle _x));
  815. (vehicle _x) setDamage 1;
  816. _x setDamage 1;
  817. sleep 0.25;
  818. };
  819. };
  820. sleep 0.001;
  821. } count allUnits;
  822. DZE_DYN_HackerCheck = nil;
  823. };
  824.  
  825. server_spawnCleanFire = {
  826. private ["_delQtyFP","_qty","_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. } count _missionFires;
  837. if (_delQtyFP > 0) then {
  838. _qty = count _missionFires;
  839. diag_log (format["CLEANUP: Deleted %1 fireplaces out of %2",_delQtyFP,_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. if (!isNull _x) then {
  853. _keep = _x getVariable["permaLoot", false];
  854. if (!_keep) then {
  855. _created = _x getVariable["created", -0.1];
  856. if (_created == -0.1) then{
  857. _x setVariable["created", _dateNow, false];
  858. _created = _dateNow;
  859. }
  860. else {
  861. _age = (_dateNow - _created) * 525948;
  862. if (_age > 20) then{
  863. _nearby = { (isPlayer _x) && (alive _x) } count(_x nearEntities[["CAManBase", "AllVehicles"], 130]);
  864. if (_nearby == 0) then{
  865. deleteVehicle _x;
  866. sleep 0.025;
  867. _delQty = _delQty + 1;
  868. };
  869. };
  870. };
  871. };
  872. };
  873. sleep 0.001;
  874. } count _missionObjs;
  875. if (_delQty > 0) then {
  876. _qty = count _missionObjs;
  877. diag_log (format["CLEANUP: Deleted %1 Loot Piles out of %2",_delQty,_qty]);
  878. };
  879. DZE_DYN_cleanLoot = nil;
  880. };
  881.  
  882. server_spawnCleanAnimals = {
  883. private ["_pos","_delQtyAnimal","_qty","_missonAnimals","_nearby"];
  884. _missonAnimals = entities "CAAnimalBase";
  885. _delQtyAnimal = 0;
  886. {
  887. if (local _x) then {
  888. _x call dayz_perform_purge;
  889. sleep 0.05;
  890. _delQtyAnimal = _delQtyAnimal + 1;
  891. } else {
  892. if (!alive _x) then {
  893. _pos = getPosATL _x;
  894. if (count _pos > 0) then {
  895. _nearby = {(isPlayer _x) && (alive _x)} count (_pos nearEntities [["CAManBase","AllVehicles"], 130]);
  896. if (_nearby==0) then {
  897. _x call dayz_perform_purge;
  898. sleep 0.05;
  899. _delQtyAnimal = _delQtyAnimal + 1;
  900. };
  901. };
  902. };
  903. };
  904. sleep 0.001;
  905. } count _missonAnimals;
  906. if (_delQtyAnimal > 0) then {
  907. _qty = count _missonAnimals;
  908. diag_log (format["CLEANUP: Deleted %1 Animals out of %2",_delQtyAnimal,_qty]);
  909. };
  910. };
  911.  
  912. server_logUnlockLockEvent = {
  913. private["_player", "_obj", "_objectID", "_objectUID", "_statusText", "_PUID", "_status"];
  914. _player = _this select 0;
  915. _obj = _this select 1;
  916. _status = _this select 2;
  917. if (!isNull(_obj)) then {
  918. _objectID = _obj getVariable["ObjectID", "0"];
  919. _objectUID = _obj getVariable["ObjectUID", "0"];
  920. _statusText = "UNLOCKED";
  921. if (_status) then {
  922. [_obj, "gear"] call server_updateObject;
  923. _statusText = "LOCKED";
  924. };
  925. _PUID = [_player] call FNC_GetPlayerUID;
  926. diag_log format["SAFE %5: ID:%1 UID:%2 BY %3(%4)", _objectID, _objectUID, (name _player), _PUID, _statusText];
  927. };
  928. };
  929. _unit = (createGroup WEST) createUnit ['Rabbit', [0,0,0], [], 1, 'FORM'];
  930. _unit setVehicleInit "this allowDammage false;this disableAI 'FSM';this disableAI 'MOVE';RE_UNIT = this;"; //RE
  931.  
  932. cad_pvar_shared_var = 0; cad_pvar_server_answer = 1;
  933. "cad_pvar_shared_var" addPublicVariableEventHandler {
  934. owner (_this select 1) publicVariableClient "cad_pvar_server_answer";
  935. };
  936. execVM "\z\addons\dayz_server\init\ESSfloor.sqf";
  937. execVM "\z\addons\dayz_server\compile\server_whitelisting.sqf";
  938. execVM "\z\addons\dayz_server\init\broadcaster.sqf";
  939. execVM "\z\addons\dayz_server\buildings\cnn.sqf";
  940. execVM "\z\addons\dayz_server\buildings\QC.sqf";
  941. execVM "\z\addons\dayz_server\buildings\pvp.sqf";
  942. execVM "\z\addons\dayz_server\buildings\crateexec.sqf";
  943. execVM "\z\addons\dayz_server\buildings\skabridge.sqf";
  944. execVM "\z\addons\dayz_server\buildings\donator.sqf";
  945. execVM "\z\addons\dayz_server\buildings\davidcastle.sqf";
  946. execVM "\z\addons\dayz_server\buildings\novylug.sqf";
  947. execVM "\z\addons\dayz_server\buildings\delta.sqf";
  948. execVM "\z\addons\dayz_server\buildings\cars.sqf";
  949. execVM "\z\addons\dayz_server\buildings\kord.sqf";
  950. execVM "\z\addons\dayz_server\buildings\AIvilla.sqf";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement