Advertisement
Guest User

Untitled

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