Advertisement
Guest User

Untitled

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