Advertisement
Guest User

Untitled

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