Advertisement
Guest User

Untitled

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