Advertisement
Guest User

system_monitor.sqf

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