ShadowStalker

server_functions.sqf

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