Advertisement
Guest User

Untitled

a guest
Dec 20th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.07 KB | None | 0 0
  1. private ["_nul","_result","_pos","_wsDone","_dir","_block","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_hitPoints","_fuel","_damage","_date","_key","_outcome","_vehLimit","_hiveResponse","_objectCount","_codeCount","_objectArray","_hour","_minute","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0"];
  2.  
  3. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  4. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  5.  
  6. _script = getText(missionConfigFile >> "onPauseScript");
  7. // ### [CPC] Indestructible Buildables Fix
  8. _cpcimmune =[
  9. "WoodFloor_DZ",
  10. "WoodFloorHalf_DZ",
  11. "WoodFloorQuarter_DZ",
  12. "WoodLargeWall_DZ",
  13. "WoodSmallWall_DZ",
  14. "WoodSmallWallThird_DZ",
  15. "CinderWallHalf_DZ",
  16. "CinderWall_DZ",
  17. "MetalFloor_DZ"
  18.  
  19. ];
  20. // ### [CPC] Indestructible Buildables Fix
  21.  
  22. if ((count playableUnits == 0) and !isDedicated) then {
  23. isSinglePlayer = true;
  24. };
  25.  
  26. waitUntil{initialized}; //means all the functions are now defined
  27.  
  28. diag_log "HIVE: Starting";
  29.  
  30. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  31.  
  32. // Custom Configs
  33. if(isnil "MaxVehicleLimit") then {
  34. MaxVehicleLimit = 50;
  35. };
  36. if(isnil "MaxHeliCrashes") then {
  37. MaxHeliCrashes = 5;
  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 and 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. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  61. _hiveResponse = ["",0];
  62. }
  63. else {
  64. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  65. _i = 99; // break
  66. };
  67. };
  68.  
  69. _objectArray = [];
  70. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  71. _objectCount = _hiveResponse select 1;
  72. diag_log ("HIVE: Commence Object Streaming...");
  73. for "_i" from 1 to _objectCount do {
  74. _hiveResponse = _key call server_hiveReadWriteLarge;
  75. _objectArray set [_i - 1, _hiveResponse];
  76. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  77. };
  78. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  79. };
  80.  
  81. // # START OF STREAMING #
  82. _countr = 0;
  83. _totalvehicles = 0;
  84. {
  85. //Parse Array
  86. _countr = _countr + 1;
  87.  
  88. _idKey = _x select 1;
  89. _type = _x select 2;
  90. _ownerID = _x select 3;
  91.  
  92. _worldspace = _x select 4;
  93. _intentory= _x select 5;
  94. _hitPoints= _x select 6;
  95. _fuel = _x select 7;
  96. _damage = _x select 8;
  97.  
  98. _dir = 0;
  99. _pos = [0,0,0];
  100. _wsDone = false;
  101. if (count _worldspace >= 2) then
  102. {
  103. _dir = _worldspace select 0;
  104. if (count (_worldspace select 1) == 3) then {
  105. _pos = _worldspace select 1;
  106. _wsDone = true;
  107. }
  108. };
  109. if (!_wsDone) then {
  110. if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  111. _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  112. if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  113. diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  114. };
  115.  
  116. if (_damage < 1) then {
  117. //diag_log format["OBJ: %1 - %2", _idKey,_type];
  118.  
  119. //Create it
  120. _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  121. _object setVariable ["lastUpdate",time];
  122. _object setVariable ["ObjectID", _idKey, true];
  123.  
  124. _lockable = 0;
  125. if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  126. _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  127. };
  128.  
  129. // fix for leading zero issues on safe codes after restart
  130. if (_lockable == 4) then {
  131. _codeCount = (count (toArray _ownerID));
  132. if(_codeCount == 3) then {
  133. _ownerID = format["0%1", _ownerID];
  134. };
  135. if(_codeCount == 2) then {
  136. _ownerID = format["00%1", _ownerID];
  137. };
  138. if(_codeCount == 1) then {
  139. _ownerID = format["000%1", _ownerID];
  140. };
  141. };
  142.  
  143. if (_lockable == 3) then {
  144. _codeCount = (count (toArray _ownerID));
  145. if(_codeCount == 2) then {
  146. _ownerID = format["0%1", _ownerID];
  147. };
  148. if(_codeCount == 1) then {
  149. _ownerID = format["00%1", _ownerID];
  150. };
  151. };
  152.  
  153. _object setVariable ["CharacterID", _ownerID, true];
  154.  
  155. clearWeaponCargoGlobal _object;
  156. clearMagazineCargoGlobal _object;
  157. // _object setVehicleAmmo DZE_vehicleAmmo;
  158.  
  159. if ((typeOf _object) in dayz_allowedObjects) then {
  160. _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  161. // Test disabling simulation server side on buildables only.
  162. _object enableSimulation false;
  163. // used for inplace upgrades and lock/unlock of safe
  164. _object setVariable ["OEMPos", _pos, true];
  165. };
  166.  
  167. _object setdir _dir;
  168. _object setposATL _pos;
  169. _object setDamage _damage;
  170. // ### [CPC] Indestructible Buildables Fix
  171. if (typeOf(_object) in _cpcimmune) then {
  172. _object addEventHandler ["HandleDamage", {false}];
  173. _object enableSimulation false;
  174. };
  175. // ### [CPC] Indestructible Buildables Fix
  176. if (count _intentory > 0) then {
  177. if (_type in DZE_LockedStorage) then {
  178. // Fill variables with loot
  179. _object setVariable ["WeaponCargo", (_intentory select 0), true];
  180. _object setVariable ["MagazineCargo", (_intentory select 1), true];
  181. _object setVariable ["BackpackCargo", (_intentory select 2), true];
  182. } else {
  183.  
  184. //Add weapons
  185. _objWpnTypes = (_intentory select 0) select 0;
  186. _objWpnQty = (_intentory select 0) select 1;
  187. _countr = 0;
  188. {
  189. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  190. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  191. };
  192. _isOK = isClass(configFile >> "CfgWeapons" >> _x);
  193. if (_isOK) then {
  194. _block = getNumber(configFile >> "CfgWeapons" >> _x >> "stopThis") == 1;
  195. if (!_block) then {
  196. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  197. };
  198. };
  199. _countr = _countr + 1;
  200. } forEach _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. _block = getNumber(configFile >> "CfgMagazines" >> _x >> "stopThis") == 1;
  212. if (!_block) then {
  213. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  214. };
  215. };
  216. _countr = _countr + 1;
  217. } forEach _objWpnTypes;
  218.  
  219. //Add Backpacks
  220. _objWpnTypes = (_intentory select 2) select 0;
  221. _objWpnQty = (_intentory select 2) select 1;
  222. _countr = 0;
  223. {
  224. _isOK = isClass(configFile >> "CfgVehicles" >> _x);
  225. if (_isOK) then {
  226. _block = getNumber(configFile >> "CfgVehicles" >> _x >> "stopThis") == 1;
  227. if (!_block) then {
  228. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  229. };
  230. };
  231. _countr = _countr + 1;
  232. } forEach _objWpnTypes;
  233. };
  234. };
  235.  
  236. if (_object isKindOf "AllVehicles") then {
  237. {
  238. _selection = _x select 0;
  239. _dam = _x select 1;
  240. if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
  241. [_object,_selection,_dam] call object_setFixServer;
  242. } forEach _hitpoints;
  243.  
  244. _object setFuel _fuel;
  245.  
  246. if (!((typeOf _object) in dayz_allowedObjects)) then {
  247.  
  248. //_object setvelocity [0,0,1];
  249. _object call fnc_veh_ResetEH;
  250.  
  251. if(_ownerID != "0" and !(_object isKindOf "Bicycle")) then {
  252. _object setvehiclelock "locked";
  253. };
  254.  
  255. _totalvehicles = _totalvehicles + 1;
  256.  
  257. // total each vehicle
  258. serverVehicleCounter set [count serverVehicleCounter,_type];
  259. };
  260. };
  261.  
  262. //Monitor the object
  263. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  264. };
  265. } forEach _objectArray;
  266. // # END OF STREAMING #
  267.  
  268.  
  269. // preload server traders menu data into cache
  270. {
  271. // get tids
  272. _traderData = call compile format["menu_%1;",_x];
  273. if(!isNil "_traderData") then {
  274. {
  275. _traderid = _x select 1;
  276.  
  277. _retrader = [];
  278.  
  279. _key = format["CHILD:399:%1:",_traderid];
  280. _data = "HiveEXT" callExtension _key;
  281.  
  282. //diag_log "HIVE: Request sent";
  283.  
  284. //Process result
  285. _result = call compile format ["%1",_data];
  286. _status = _result select 0;
  287.  
  288. if (_status == "ObjectStreamStart") then {
  289. _val = _result select 1;
  290. //Stream Objects
  291. //diag_log ("HIVE: Commence Menu Streaming...");
  292. call compile format["ServerTcache_%1 = [];",_traderid];
  293. for "_i" from 1 to _val do {
  294. _data = "HiveEXT" callExtension _key;
  295. _result = call compile format ["%1",_data];
  296. call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]",_traderid,_result];
  297. _retrader set [count _retrader,_result];
  298. };
  299. //diag_log ("HIVE: Streamed " + str(_val) + " objects");
  300. };
  301.  
  302. } forEach (_traderData select 0);
  303. };
  304. } forEach serverTraders;
  305.  
  306. // spawn_vehicles
  307. _vehLimit = MaxVehicleLimit - _totalvehicles;
  308. diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  309. if(_vehLimit > 0) then {
  310. for "_x" from 1 to _vehLimit do {
  311. [] spawn spawn_vehicles;
  312. };
  313. };
  314. // spawn_roadblocks
  315. diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  316. for "_x" from 1 to MaxDynamicDebris do {
  317. [] spawn spawn_roadblocks;
  318. };
  319. // spawn_ammosupply at server start 1% of roadblocks
  320. diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  321. for "_x" from 1 to MaxAmmoBoxes do {
  322. [] spawn spawn_ammosupply;
  323. };
  324. // call spawning mining veins
  325. diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  326. for "_x" from 1 to MaxMineVeins do {
  327. [] spawn spawn_mineveins;
  328. };
  329.  
  330. if(isnil "dayz_MapArea") then {
  331. dayz_MapArea = 10000;
  332. };
  333. if(isnil "HeliCrashArea") then {
  334. HeliCrashArea = dayz_MapArea / 2;
  335. };
  336. if(isnil "OldHeliCrash") then {
  337. OldHeliCrash = false;
  338. };
  339.  
  340. allowConnection = true;
  341.  
  342. // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  343. if(OldHeliCrash) then {
  344. _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  345. };
  346.  
  347. if (isDedicated) then {
  348. // Epoch Events
  349. _id = [] spawn server_spawnEvents;
  350. // server cleanup
  351. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  352.  
  353. // spawn debug box
  354. _debugMarkerPosition = getMarkerPos "respawn_west";
  355. _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  356. _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  357. _vehicle_0 setPos _debugMarkerPosition;
  358. _vehicle_0 setVariable ["ObjectID","1",true];
  359.  
  360. // max number of spawn markers
  361. if(isnil "spawnMarkerCount") then {
  362. spawnMarkerCount = 10;
  363. };
  364.  
  365. actualSpawnMarkerCount = 0;
  366.  
  367. // count valid spawn marker positions
  368. for "_i" from 0 to spawnMarkerCount do {
  369. if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  370. actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  371. } else {
  372. // exit since we did not find any further markers
  373. _i = spawnMarkerCount + 99;
  374. };
  375.  
  376. };
  377. diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  378. };
  379.  
  380. sm_done = true;
  381. publicVariable "sm_done";
  382. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement