Advertisement
Guest User

Untitled

a guest
May 26th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.14 KB | None | 0 0
  1. private ["_nul","_result","_pos","_wsDone","_dir","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_inventory","_hitPoints","_fuel","_damage","_key","_vehLimit","_hiveResponse","_objectCount","_codeCount","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0","_bQty","_vQty","_BuildingQueue","_objectQueue","_superkey","_shutdown","_res","_hiveLoaded","_ownerPUID"];
  2.  
  3. dayz_versionNo =        getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  4. dayz_hiveVersionNo =    getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  5.  
  6. // ### [CPC] Indestructible Buildables Fix
  7. _cpcimmune =[
  8. "CinderWallHalf_DZ",
  9. "CinderWall_DZ",
  10. "CinderWallDoorway_DZ",
  11. "MetalFloor_DZ",
  12. "CinderWallDoorSmallLocked_DZ",
  13. "CinderWallSmallDoorway_DZ",
  14. "CinderWallDoorLocked_DZ",
  15. "CinderWallDoor_DZ"
  16. ];
  17. // ### [CPC] Indestructible Buildables Fix
  18.  
  19. _hiveLoaded = false;
  20.  
  21. waitUntil{initialized}; //means all the functions are now defined
  22.  
  23. diag_log "HIVE: Starting";
  24.  
  25. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  26.    
  27. // Custom Configs
  28. if(isnil "MaxVehicleLimit") then {
  29.     MaxVehicleLimit = 50;
  30. };
  31.  
  32. if(isnil "MaxDynamicDebris") then {
  33.     MaxDynamicDebris = 100;
  34. };
  35. if(isnil "MaxAmmoBoxes") then {
  36.     MaxAmmoBoxes = 3;
  37. };
  38. if(isnil "MaxMineVeins") then {
  39.     MaxMineVeins = 50;
  40. };
  41. // Custon Configs End
  42.  
  43. if (isServer && isNil "sm_done") then {
  44.  
  45.     serverVehicleCounter = [];
  46.     _hiveResponse = [];
  47.  
  48.     for "_i" from 1 to 5 do {
  49.         diag_log "HIVE: trying to get objects";
  50.         _key = format["CHILD:302:%1:", dayZ_instance];
  51.         _hiveResponse = _key call server_hiveReadWrite;  
  52.         if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")})) then {
  53.             if ((_hiveResponse select 1) == "Instance already initialized") then {
  54.                 _superkey = profileNamespace getVariable "SUPERKEY";
  55.                 _shutdown = format["CHILD:400:%1:", _superkey];
  56.                 _res = _shutdown call server_hiveReadWrite;
  57.                 diag_log ("HIVE: attempt to kill.. HiveExt response:"+str(_res));
  58.             } else {
  59.                 diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  60.            
  61.             };
  62.             _hiveResponse = ["",0];
  63.         }
  64.         else {
  65.             diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  66.             _i = 99; // break
  67.         };
  68.     };
  69.    
  70.     _BuildingQueue = [];
  71.     _objectQueue = [];
  72.    
  73.     if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  74.    
  75.         // save superkey
  76.         profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  77.        
  78.         _hiveLoaded = true;
  79.    
  80.         diag_log ("HIVE: Commence Object Streaming...");
  81.         _key = format["CHILD:302:%1:", dayZ_instance];
  82.         _objectCount = _hiveResponse select 1;
  83.         _bQty = 0;
  84.         _vQty = 0;
  85.         for "_i" from 1 to _objectCount do {
  86.             _hiveResponse = _key call server_hiveReadWriteLarge;
  87.             //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  88.             if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  89.                 _BuildingQueue set [_bQty,_hiveResponse];
  90.                 _bQty = _bQty + 1;
  91.             } else {
  92.                 _objectQueue set [_vQty,_hiveResponse];
  93.                 _vQty = _vQty + 1;
  94.             };
  95.         };
  96.         diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  97.     };
  98.    
  99.     // # NOW SPAWN OBJECTS #
  100.     _totalvehicles = 0;
  101.     {
  102.         _idKey =        _x select 1;
  103.         _type =         _x select 2;
  104.         _ownerID =      _x select 3;
  105.  
  106.         _worldspace =   _x select 4;
  107.         _inventory =    _x select 5;
  108.         _hitPoints =    _x select 6;
  109.         _fuel =         _x select 7;
  110.         _damage =       _x select 8;
  111.        
  112.         try {
  113.             if (typeName _inventory == "STRING") then { throw "STRING" }
  114.         }
  115.         catch {
  116.             if (_exception == "STRING") then {diag_log format["ERROR: TypeName String, expected Array for %1 - RESETTING INVENTORY",_x]};
  117.             _inventory = [];
  118.         };
  119.        
  120.         _dir = 0;
  121.         _pos = [0,0,0];
  122.         _wsDone = false;
  123.         if (count _worldspace >= 2) then
  124.         {
  125.             _dir = _worldspace select 0;
  126.             if (count (_worldspace select 1) == 3) then {
  127.                 _pos = _worldspace select 1;
  128.                 _wsDone = true;
  129.             }
  130.         };         
  131.        
  132.         if (!_wsDone) then {
  133.             if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  134.             _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  135.             if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  136.             diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  137.         };
  138.        
  139.         _vector = [[0,0,0],[0,0,0]];
  140. _vecExists = false;
  141. _ownerPUID = "0";  
  142. if (count _worldspace >= 3) then{
  143.     if(count _worldspace == 3) then{
  144.             if(typename (_worldspace select 2) == "STRING")then{
  145.                 _ownerPUID = _worldspace select 2;
  146.             }else{
  147.                  if(typename (_worldspace select 2) == "ARRAY")then{
  148.                     _vector = _worldspace select 2;
  149.                     if(count _vector == 2)then{
  150.                         if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  151.                             _vecExists = true;
  152.                         };
  153.                     };
  154.                 };                  
  155.             };
  156.  
  157.     }else{
  158.         //Was not 3 elements, so check if 4 or more
  159.         if(count _worldspace == 4) then{
  160.             if(typename (_worldspace select 3) == "STRING")then{
  161.                 _ownerPUID = _worldspace select 3;
  162.             }else{
  163.                 if(typename (_worldspace select 2) == "STRING")then{
  164.                     _ownerPUID = _worldspace select 2;
  165.                 };
  166.             };
  167.  
  168.  
  169.             if(typename (_worldspace select 2) == "ARRAY")then{
  170.                 _vector = _worldspace select 2;
  171.                 if(count _vector == 2)then{
  172.                     if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  173.                         _vecExists = true;
  174.                     };
  175.                 };
  176.             }else{
  177.                 if(typename (_worldspace select 3) == "ARRAY")then{
  178.                     _vector = _worldspace select 3;
  179.                     if(count _vector == 2)then{
  180.                         if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  181.                             _vecExists = true;
  182.                         };
  183.                     };
  184.                 };
  185.             };
  186.  
  187.         }else{
  188.             //More than 3 or 4 elements found
  189.             //Might add a search for the vector, ownerPUID will equal 0
  190.         };
  191.     };
  192. };
  193.        
  194.         // Realign characterID to OwnerPUID - need to force save though.
  195.        
  196.         if (DZE_APlotforLife) then {
  197.             if (count _worldspace < 3) then
  198.             {
  199.                 _worldspace set [count _worldspace, "0"];
  200.             };     
  201.             _ownerPUID = _worldspace select 2;
  202.         } else {
  203.             _ownerPUID = _ownerID;
  204.         };
  205.        
  206.         // diag_log format["Server_monitor: [ObjectID = %1]  [ClassID = %2] [_ownerPUID = %3]", _idKey, _type, _ownerPUID];
  207.        
  208.         if (_damage < 1) then {
  209.             //diag_log format["OBJ: %1 - %2", _idKey,_type];
  210.            
  211.             //Create it
  212.             _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  213.             if (typeOf (_object) in  DZE_DoorsLocked) then {
  214.             _object setVariable ["doorfriends", _inventory, true];
  215.             };
  216.             _object setVariable ["lastUpdate",time];
  217.             _object setVariable ["ObjectID", _idKey, true];
  218.             _object setVariable ["ownerPUID", _ownerPUID, true];
  219.             if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then {
  220.             _object setVariable ["plotfriends", _inventory, true];
  221.             };
  222.             _object setVariable ["OwnerPUID", _ownerPUID, true];
  223.  
  224.             _lockable = 0;
  225.             if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  226.                 _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  227.             };
  228.  
  229.             // fix for leading zero issues on safe codes after restart
  230.             if (_lockable == 4) then {
  231.                 _codeCount = (count (toArray _ownerID));
  232.                 if(_codeCount == 3) then {
  233.                     _ownerID = format["0%1", _ownerID];
  234.                 };
  235.                 if(_codeCount == 2) then {
  236.                     _ownerID = format["00%1", _ownerID];
  237.                 };
  238.                 if(_codeCount == 1) then {
  239.                     _ownerID = format["000%1", _ownerID];
  240.                 };
  241.             };
  242.  
  243.             if (_lockable == 3) then {
  244.                 _codeCount = (count (toArray _ownerID));
  245.                 if(_codeCount == 2) then {
  246.                     _ownerID = format["0%1", _ownerID];
  247.                 };
  248.                 if(_codeCount == 1) then {
  249.                     _ownerID = format["00%1", _ownerID];
  250.                 };
  251.             };
  252.  
  253.             _object setVariable ["CharacterID", _ownerID, true];
  254.            
  255.             clearWeaponCargoGlobal  _object;
  256.             clearMagazineCargoGlobal  _object;
  257.             // _object setVehicleAmmo DZE_vehicleAmmo;
  258.            
  259.             _object setdir _dir;
  260.             if(_vecExists)then{
  261.             _object setVectorDirAndUp _vector;
  262.             };
  263.             _object setposATL _pos;
  264.             _object setDamage _damage;
  265.            
  266.             // ### [CPC] Indestructible Buildables Fix
  267.                     if (typeOf(_object) in _cpcimmune) then {
  268.                         _object addEventHandler ["HandleDamage", {false}];
  269.                         _object enableSimulation false;
  270.                     };
  271.             // ### [CPC] Indestructible Buildables Fix
  272.            
  273.             if ((typeOf _object) in dayz_allowedObjects) then {
  274.                     _object setVariable["memDir",_dir,true];
  275.                 if (DZE_GodModeBase) then {
  276.                     _object addEventHandler ["HandleDamage", {false}];
  277.                 } else {
  278.                     _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  279.                 };
  280.                 // Test disabling simulation server side on buildables only.
  281.                 _object enableSimulation false;
  282.                 // used for inplace upgrades && lock/unlock of safe
  283.                 _object setVariable ["OEMPos", _pos, true];
  284.                
  285.             };
  286.  
  287.             if (count _inventory > 0) then {
  288.                 if ((count _inventory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ") && !(typeOf( _object) in  DZE_DoorsLocked)) then {
  289.                     // Fill variables with loot
  290.                     _object setVariable ["WeaponCargo", (_inventory select 0),true];
  291.                     _object setVariable ["MagazineCargo", (_inventory select 1),true];
  292.                     _object setVariable ["BackpackCargo", (_inventory select 2),true];
  293.                 } else {
  294.  
  295.                     //Add weapons
  296.                     _objWpnTypes = (_inventory select 0) select 0;
  297.                     _objWpnQty = (_inventory select 0) select 1;
  298.                     _countr = 0;                   
  299.                     {
  300.                         if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  301.                             _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  302.                         };
  303.                         _isOK =     isClass(configFile >> "CfgWeapons" >> _x);
  304.                         if (_isOK) then {
  305.                             _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  306.                         };
  307.                         _countr = _countr + 1;
  308.                     } count _objWpnTypes;
  309.                
  310.                     //Add Magazines
  311.                     _objWpnTypes = (_inventory select 1) select 0;
  312.                     _objWpnQty = (_inventory select 1) select 1;
  313.                     _countr = 0;
  314.                     {
  315.                         if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  316.                         if (_x == "ItemTent") then { _x = "ItemTentOld" };
  317.                         _isOK =     isClass(configFile >> "CfgMagazines" >> _x);
  318.                         if (_isOK) then {
  319.                             _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  320.                         };
  321.                         _countr = _countr + 1;
  322.                     } count _objWpnTypes;
  323.  
  324.                     //Add Backpacks
  325.                     _objWpnTypes = (_inventory select 2) select 0;
  326.                     _objWpnQty = (_inventory select 2) select 1;
  327.                     _countr = 0;
  328.                     {
  329.                         _isOK =     isClass(configFile >> "CfgVehicles" >> _x);
  330.                         if (_isOK) then {
  331.                             _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  332.                         };
  333.                         _countr = _countr + 1;
  334.                     } count _objWpnTypes;
  335.                 };
  336.             }; 
  337.            
  338.             if (_object isKindOf "AllVehicles") then {
  339.             _object setVariable ["lastInventory", _inventory];
  340.             private ["_colour","_colour2","_clrinit","_clrinit2"];
  341.                 {
  342.                     _selection = _x select 0;
  343.                     _dam = _x select 1;
  344.                     if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  345.                     [_object,_selection,_dam] call object_setFixServer;
  346.                 } count _hitpoints;
  347.                 if(count _worldspace >= 4) then{   
  348.                 if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then {
  349.                 _colour = _worldspace select 2;
  350.                 _colour2 = _worldspace select 3;
  351.                    
  352.             if (_colour != "0") then {
  353.                 _object setVariable ["Colour",_colour,true];
  354.                 _clrinit = format ["#(argb,8,8,3)color(%1)",_colour];
  355.                 _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  356.             };
  357.             if (_colour2 != "0") then {        
  358.                 _object setVariable ["Colour2",_colour2,true];
  359.                 _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  360.                 _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  361.             };
  362.       };
  363. };
  364.  
  365.                 _object setFuel _fuel;
  366.  
  367.                 if (!((typeOf _object) in dayz_allowedObjects)) then {
  368.                    
  369.                     //_object setvelocity [0,0,1];
  370.                     _object call fnc_veh_ResetEH;      
  371.                    
  372.                     if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  373.                         _object setvehiclelock "locked";
  374.                     };
  375.                    
  376.                     _totalvehicles = _totalvehicles + 1;
  377.  
  378.                     // total each vehicle
  379.                     serverVehicleCounter set [count serverVehicleCounter,_type];
  380.                 };
  381.             };
  382.             [_object] execVM "\z\addons\dayz_server\compile\Server_DeleteObjInsafezone.sqf";
  383.  
  384.             //Monitor the object
  385.             PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  386.         };
  387.     } forEach (_BuildingQueue + _objectQueue);
  388.     // # END SPAWN OBJECTS #
  389.  
  390.     // preload server traders menu data into cache
  391.     if !(DZE_ConfigTrader) then {
  392.         {
  393.             // get tids
  394.             _traderData = call compile format["menu_%1;",_x];
  395.             if(!isNil "_traderData") then {
  396.                 {
  397.                     _traderid = _x select 1;
  398.  
  399.                     _retrader = [];
  400.  
  401.                     _key = format["CHILD:399:%1:",_traderid];
  402.                     _data = "HiveEXT" callExtension _key;
  403.  
  404.                     //diag_log "HIVE: Request sent";
  405.            
  406.                     //Process result
  407.                     _result = call compile format ["%1",_data];
  408.                     _status = _result select 0;
  409.            
  410.                     if (_status == "ObjectStreamStart") then {
  411.                         _val = _result select 1;
  412.                         //Stream Objects
  413.                         //diag_log ("HIVE: Commence Menu Streaming...");
  414.                         call compile format["ServerTcache_%1 = [];",_traderid];
  415.                         for "_i" from 1 to _val do {
  416.                             _data = "HiveEXT" callExtension _key;
  417.                             _result = call compile format ["%1",_data];
  418.                             call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  419.                             _retrader set [count _retrader,_result];
  420.                         };
  421.                         //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  422.                     };
  423.  
  424.                 } forEach (_traderData select 0);
  425.             };
  426.         } forEach serverTraders;
  427.     };
  428.  
  429.     if (_hiveLoaded) then {
  430.         //  spawn_vehicles
  431.         _vehLimit = MaxVehicleLimit - _totalvehicles;
  432.         if(_vehLimit > 0) then {
  433.             diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  434.             for "_x" from 1 to _vehLimit do {
  435.                 [] spawn spawn_vehicles;
  436.             };
  437.         } else {
  438.             diag_log "HIVE: Vehicle Spawn limit reached!";
  439.         };
  440.     };
  441.    
  442.     //  spawn_roadblocks
  443.     diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  444.     for "_x" from 1 to MaxDynamicDebris do {
  445.         [] spawn spawn_roadblocks;
  446.     };
  447.     //  spawn_ammosupply at server start 1% of roadblocks
  448.     diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  449.     for "_x" from 1 to MaxAmmoBoxes do {
  450.         [] spawn spawn_ammosupply;
  451.     };
  452.     // call spawning mining veins
  453.     diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  454.     for "_x" from 1 to MaxMineVeins do {
  455.         [] spawn spawn_mineveins;
  456.     };
  457.  
  458.     if(isnil "dayz_MapArea") then {
  459.         dayz_MapArea = 10000;
  460.     };
  461.     if(isnil "HeliCrashArea") then {
  462.         HeliCrashArea = dayz_MapArea / 2;
  463.     };
  464.     if(isnil "OldHeliCrash") then {
  465.         OldHeliCrash = false;
  466.     };
  467.  
  468.     // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  469.     if(OldHeliCrash) then {
  470.         _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  471.     };
  472.     if (isDedicated) then {
  473.         // Epoch Events
  474.         _id = [] spawn server_spawnEvents;
  475.         // server cleanup
  476.         [] spawn {
  477.             private ["_id"];
  478.             sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  479.             waitUntil {!isNil "server_spawnCleanAnimals"};
  480.             _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  481.         };
  482.  
  483.         // spawn debug box
  484.         _debugMarkerPosition = getMarkerPos "respawn_west";
  485.         _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  486.         _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  487.         _vehicle_0 setPos _debugMarkerPosition;
  488.         _vehicle_0 setVariable ["ObjectID","1",true];
  489.  
  490.         // max number of spawn markers
  491.         if(isnil "spawnMarkerCount") then {
  492.             spawnMarkerCount = 10;
  493.         };
  494.         actualSpawnMarkerCount = 0;
  495.         // count valid spawn marker positions
  496.         for "_i" from 0 to spawnMarkerCount do {
  497.             if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  498.                 actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  499.             } else {
  500.                 // exit since we did not find any further markers
  501.                 _i = spawnMarkerCount + 99;
  502.             };
  503.            
  504.         };
  505.         diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  506.        
  507.         endLoadingScreen;
  508.     };
  509.  
  510.     allowConnection = true;
  511.         ExecVM "\z\addons\dayz_server\WAI\init.sqf";
  512.     sm_done = true;
  513.     publicVariable "sm_done";
  514. };
  515.  
  516. execVM "\z\addons\dayz_server\DynamicTraders\init.sqf";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement