Advertisement
Guest User

server_functions.sqf

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