NyxGrimlock

Server_fuctions.sqf

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