Advertisement
Guest User

Untitled

a guest
Oct 18th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.19 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.  
  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.  
  60. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  61.  
  62. // save superkey
  63. profileNamespace setVariable ["SUPERKEY",(_hiveResponse select 2)];
  64.  
  65. _hiveLoaded = true;
  66.  
  67. diag_log ("HIVE: Commence Object Streaming...");
  68. _key = format["CHILD:302:%1:", dayZ_instance];
  69. _objectCount = _hiveResponse select 1;
  70. _bQty = 0;
  71. _vQty = 0;
  72. for "_i" from 1 to _objectCount do {
  73. _hiveResponse = _key call server_hiveReadWriteLarge;
  74. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  75. if ((_hiveResponse select 2) isKindOf "ModularItems") then {
  76. _BuildingQueue set [_bQty,_hiveResponse];
  77. _bQty = _bQty + 1;
  78. } else {
  79. _objectQueue set [_vQty,_hiveResponse];
  80. _vQty = _vQty + 1;
  81. };
  82. };
  83. diag_log ("HIVE: got " + str(_bQty) + " Epoch Objects and " + str(_vQty) + " Vehicles");
  84. };
  85.  
  86. // # NOW SPAWN OBJECTS #
  87. _totalvehicles = 0;
  88. {
  89. _idKey = _x select 1;
  90. _type = _x select 2;
  91. _ownerID = _x select 3;
  92.  
  93. _worldspace = _x select 4;
  94. _intentory = _x select 5;
  95. _hitPoints = _x select 6;
  96. _fuel = _x select 7;
  97. _damage = _x select 8;
  98.  
  99. _dir = 0;
  100. _pos = [0,0,0];
  101. _wsDone = false;
  102. if (count _worldspace >= 2) then
  103. {
  104. _dir = _worldspace select 0;
  105. if (count (_worldspace select 1) == 3) then {
  106. _pos = _worldspace select 1;
  107. _wsDone = true;
  108. }
  109. };
  110.  
  111. if (!_wsDone) then {
  112. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  113. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  114. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  115. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  116. };
  117.  
  118. // Realign characterID to OwnerPUID - need to force save though. plotpole life
  119.  
  120. if (count _worldspace < 3) then
  121. {
  122. _worldspace set [count _worldspace, "0"];
  123. };
  124.  
  125. _ownerPUID = _worldspace select 2;
  126.  
  127. // diag_log format["Server_monitor: [ObjectID = %1] [ClassID = %2] [_ownerPUID = %3]", _idKey, _type, _ownerPUID];
  128.  
  129. if (_damage < 1) then {
  130. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  131.  
  132. //Create it
  133. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  134. if (typeOf (_object) in DZE_DoorsLocked) then {
  135. _object setVariable ["doorfriends", _intentory, true];
  136. };
  137. _object setVariable ["lastUpdate",time];
  138. _object setVariable ["ObjectID", _idKey, true];
  139. if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then {
  140. _object setVariable ["plotfriends", _intentory, true];
  141. };
  142. _object setVariable ["OwnerPUID", _ownerPUID, true];
  143. [_type,_object] execVM "\z\addons\dayz_server\compile\remove_ammo.sqf";
  144.  
  145. _lockable = 0;
  146. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  147. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  148. };
  149.  
  150. // fix for leading zero issues on safe codes after restart
  151. if (_lockable == 4) then {
  152. _codeCount = (count (toArray _ownerID));
  153. if(_codeCount == 3) then {
  154. _ownerID = format["0%1", _ownerID];
  155. };
  156. if(_codeCount == 2) then {
  157. _ownerID = format["00%1", _ownerID];
  158. };
  159. if(_codeCount == 1) then {
  160. _ownerID = format["000%1", _ownerID];
  161. };
  162. };
  163.  
  164. if (_lockable == 3) then {
  165. _codeCount = (count (toArray _ownerID));
  166. if(_codeCount == 2) then {
  167. _ownerID = format["0%1", _ownerID];
  168. };
  169. if(_codeCount == 1) then {
  170. _ownerID = format["00%1", _ownerID];
  171. };
  172. };
  173.  
  174. _object setVariable ["CharacterID", _ownerID, true];
  175.  
  176. clearWeaponCargoGlobal _object;
  177. clearMagazineCargoGlobal _object;
  178. // _object setVehicleAmmo DZE_vehicleAmmo;
  179.  
  180. _object setdir _dir;
  181. _object setposATL _pos;
  182. _object setDamage _damage;
  183.  
  184. if ((typeOf _object) in dayz_allowedObjects) then {
  185. if (DZE_GodModeBase) then {
  186. _object addEventHandler ["HandleDamage", {false}];
  187. } else {
  188. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  189. };
  190. // Test disabling simulation server side on buildables only.
  191. _object enableSimulation false;
  192. // used for inplace upgrades && lock/unlock of safe
  193. _object setVariable ["OEMPos", _pos, true];
  194.  
  195. };
  196.  
  197. if ((count _intentory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ")) then {
  198. if (_type in DZE_LockedStorage) then {
  199. // Fill variables with loot
  200. _object setVariable ["WeaponCargo", (_intentory select 0),true];
  201. _object setVariable ["MagazineCargo", (_intentory select 1),true];
  202. _object setVariable ["BackpackCargo", (_intentory select 2),true];
  203. } else {
  204.  
  205. //Add weapons
  206. _objWpnTypes = (_intentory select 0) select 0;
  207. _objWpnQty = (_intentory select 0) select 1;
  208. _countr = 0;
  209. {
  210. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  211. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  212. };
  213. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  214. if (_isOK) then {
  215. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  216. };
  217. _countr = _countr + 1;
  218. } count _objWpnTypes;
  219.  
  220. //Add Magazines
  221. _objWpnTypes = (_intentory select 1) select 0;
  222. _objWpnQty = (_intentory select 1) select 1;
  223. _countr = 0;
  224. {
  225. if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  226. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  227. _isOK = isClass(configFile >> "CfgMagazines" >> _x);
  228. if (_isOK) then {
  229. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  230. };
  231. _countr = _countr + 1;
  232. } count _objWpnTypes;
  233.  
  234. //Add Backpacks
  235. _objWpnTypes = (_intentory select 2) select 0;
  236. _objWpnQty = (_intentory select 2) select 1;
  237. _countr = 0;
  238. {
  239. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  240. if (_isOK) then {
  241. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  242. };
  243. _countr = _countr + 1;
  244. } count _objWpnTypes;
  245. };
  246. };
  247.  
  248. if (_object isKindOf "AllVehicles") then {
  249. {
  250. _selection = _x select 0;
  251. _dam = _x select 1;
  252. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  253. [_object,_selection,_dam] call object_setFixServer;
  254. } count _hitpoints;
  255.  
  256. _object setFuel _fuel;
  257.  
  258. if (!((typeOf _object) in dayz_allowedObjects)) then {
  259.  
  260. //_object setvelocity [0,0,1];
  261. _object call fnc_veh_ResetEH;
  262.  
  263. if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  264. _object setvehiclelock "locked";
  265. };
  266.  
  267. _totalvehicles = _totalvehicles + 1;
  268.  
  269. // total each vehicle
  270. serverVehicleCounter set [count serverVehicleCounter,_type];
  271. };
  272. };
  273.  
  274. //Monitor the object
  275. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  276. };
  277. } count (_BuildingQueue + _objectQueue);
  278. // # END SPAWN OBJECTS #
  279.  
  280. // preload server traders menu data into cache
  281. if !(DZE_ConfigTrader) then {
  282. {
  283. // get tids
  284. _traderData = call compile format["menu_%1;",_x];
  285. if(!isNil "_traderData") then {
  286. {
  287. _traderid = _x select 1;
  288.  
  289. _retrader = [];
  290.  
  291. _key = format["CHILD:399:%1:",_traderid];
  292. _data = "HiveEXT" callExtension _key;
  293.  
  294. //diag_log "HIVE: Request sent";
  295.  
  296. //Process result
  297. _result = call compile format ["%1",_data];
  298. _status = _result select 0;
  299.  
  300. if (_status == "ObjectStreamStart") then {
  301. _val = _result select 1;
  302. //Stream Objects
  303. //diag_log ("HIVE: Commence Menu Streaming...");
  304. call compile format["ServerTcache_%1 = [];",_traderid];
  305. for "_i" from 1 to _val do {
  306. _data = "HiveEXT" callExtension _key;
  307. _result = call compile format ["%1",_data];
  308. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  309. _retrader set [count _retrader,_result];
  310. };
  311. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  312. };
  313.  
  314. } forEach (_traderData select 0);
  315. };
  316. } forEach serverTraders;
  317. };
  318.  
  319. if (_hiveLoaded) then {
  320. // spawn_vehicles
  321. _vehLimit = MaxVehicleLimit - _totalvehicles;
  322. if(_vehLimit > 0) then {
  323. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  324. for "_x" from 1 to _vehLimit do {
  325. [] spawn spawn_vehicles;
  326. };
  327. } else {
  328. diag_log "HIVE: Vehicle Spawn limit reached!";
  329. };
  330. };
  331.  
  332. // spawn_roadblocks
  333. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  334. for "_x" from 1 to MaxDynamicDebris do {
  335. [] spawn spawn_roadblocks;
  336. };
  337. // spawn_ammosupply at server start 1% of roadblocks
  338. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  339. for "_x" from 1 to MaxAmmoBoxes do {
  340. [] spawn spawn_ammosupply;
  341. };
  342. // call spawning mining veins
  343. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  344. for "_x" from 1 to MaxMineVeins do {
  345. [] spawn spawn_mineveins;
  346. };
  347.  
  348. if(isnil "dayz_MapArea") then {
  349. dayz_MapArea = 10000;
  350. };
  351. if(isnil "HeliCrashArea") then {
  352. HeliCrashArea = dayz_MapArea / 2;
  353. };
  354. if(isnil "OldHeliCrash") then {
  355. OldHeliCrash = false;
  356. };
  357.  
  358. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  359. if(OldHeliCrash) then {
  360. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  361. };
  362. if (isDedicated) then {
  363. // Epoch Events
  364. _id = [] spawn server_spawnEvents;
  365. // server cleanup
  366. [] spawn {
  367. private ["_id"];
  368. sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  369. waitUntil {!isNil "server_spawnCleanAnimals"};
  370. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  371. };
  372.  
  373. // spawn debug box
  374. _debugMarkerPosition = getMarkerPos "respawn_west";
  375. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  376. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  377. _vehicle_0 setPos _debugMarkerPosition;
  378. _vehicle_0 setVariable ["ObjectID","1",true];
  379.  
  380. // max number of spawn markers
  381. if(isnil "spawnMarkerCount") then {
  382. spawnMarkerCount = 10;
  383. };
  384. actualSpawnMarkerCount = 0;
  385. // count valid spawn marker positions
  386. for "_i" from 0 to spawnMarkerCount do {
  387. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  388. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  389. } else {
  390. // exit since we did not find any further markers
  391. _i = spawnMarkerCount + 99;
  392. };
  393.  
  394. };
  395. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  396.  
  397. endLoadingScreen;
  398. };
  399.  
  400. allowConnection = true;
  401. call compile preprocessFileLineNumbers "\z\addons\dayz_server\DZAI\init\dzai_initserver.sqf";
  402. call compile preprocessFileLineNumbers "\z\addons\dayz_server\DZMS\DZMSInit.sqf";
  403. sm_done = true;
  404. publicVariable "sm_done";
  405. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement