Advertisement
meanbeandk

server_function.sqf

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