Guest User

Untitled

a guest
May 9th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.29 KB | None | 0 0
  1. // 0 = [this, <other parameters>] spawn jebus_fnc_main;
  2. // 0 = [this, "LIVES=",1] spawn jebus_fnc_main;
  3.  
  4. if (!isServer) exitWith {};
  5.  
  6. waituntil {!isnil "bis_fnc_init"};
  7.  
  8. private [
  9. "_unit"
  10. ,"_cacheRadius"
  11. ,"_crewList"
  12. ,"_crewInventoryList"
  13. ,"_crewSkillList"
  14. ,"_debug"
  15. ,"_exitTrigger"
  16. ,"_firstLoop"
  17. ,"_gaiaParameter"
  18. ,"_gaiaZone"
  19. ,"_infantryList"
  20. ,"_infantryInventoryList"
  21. ,"_infantrySkillList"
  22. ,"_initString"
  23. ,"_initialDelay"
  24. ,"_lives"
  25. ,"_newGroup"
  26. ,"_subgroupList"
  27. ,"_newSubgroupList"
  28. ,"_newVehicle"
  29. ,"_pauseRadius"
  30. ,"_reduceRadius"
  31. ,"_respawnDelay"
  32. ,"_respawnDir"
  33. ,"_respawnMarkers"
  34. ,"_respawnPos"
  35. ,"_special"
  36. ,"_tmpGroup"
  37. ,"_tmpRespawnPos"
  38. ,"_tmpZone"
  39. ,"_trigger"
  40. ,"_unitGroup"
  41. ,"_unitSide"
  42. ,"_unitsInGroup"
  43. ,"_vehicleHitpointsDamageList"
  44. ,"_vehicleHealthList"
  45. ,"_vehicleFuelList"
  46. ,"_vehicleList"
  47. ,"_vehiclePositionList"
  48. ,"_vehicleItemList"
  49. ,"_vehicleLockedList"
  50. ,"_vehicleMagazineList"
  51. ,"_vehiclePylonList"
  52. ,"_vehicleWeaponList"
  53. ,"_vehicleBackpackList"
  54. ,"_vehicleMaterialsList"
  55. ,"_vehicleTexturesList"
  56. ,"_vehicleAnimationNames"
  57. ,"_vehicleAnimationPhases"
  58. ,"_waypointList"
  59. ,"_subgroupWaypointList"
  60. ,"_synchronizedObjectsList"
  61. ];
  62.  
  63. _unit = _this select 0;
  64.  
  65. // Make sure unit is a unit and not a group (Thanks to S.Crowe)
  66. if (typeName _unit == "GROUP") then { _unit = leader _unit; };
  67.  
  68. _respawnPos = getPos _unit;
  69. _respawnDir = getDir _unit;
  70. _unitSide = side _unit;
  71.  
  72. _unitGroup = (group _unit);
  73. _subgroupList = [];
  74. _newSubgroupList = [];
  75. _unitsInGroup = units _unitGroup;
  76.  
  77. _waypointList = [];
  78. _subgroupWaypointList = [];
  79. _synchronizedObjectsList = [];
  80. _infantryList = [];
  81. _infantryInventoryList = [];
  82. _infantrySkillList = [];
  83. _vehicleList = [];
  84. _vehicleHitpointsDamageList = [];
  85. _vehicleHealthList = [];
  86. _vehicleFuelList = [];
  87. _vehiclePositionList = [];
  88. _vehicleLockedList = [];
  89. _vehicleItemList = [];
  90. _vehicleMagazineList = [];
  91. _vehiclePylonList = [];
  92. _vehicleWeaponList = [];
  93. _vehicleBackpackList = [];
  94. _vehicleMaterialsList = [];
  95. _vehicleTexturesList = [];
  96. _vehicleAnimationNames = [];
  97. _vehicleAnimationPhases = [];
  98. _crewList = [];
  99. _crewInventoryList = [];
  100. _crewSkillList = [];
  101. _crewSubgroupList = [];
  102. _respawnPosList = [];
  103. _respawnPosList pushBack _respawnPos;
  104.  
  105. //Set up default parameters
  106. _lives = -1;
  107. _cacheRadius = 0;
  108. _reduceRadius = 0;
  109. _pauseRadius = 200;
  110. _respawnDelay = 30;
  111. _initialDelay = 0;
  112. _gaiaParameter = "";
  113. _gaiaZone = 0;
  114. _special = "NONE";
  115. _respawnMarkers = [];
  116. _initString = "";
  117. _debug = false;
  118.  
  119. //Get parameters
  120. for "_parameterIndex" from 1 to (count _this - 1) do {
  121. switch (_this select _parameterIndex) do {
  122. case "LIVES=" : {_lives = _this select (_parameterIndex + 1)};
  123. case "DELAY=" : {_respawnDelay = _this select (_parameterIndex + 1)};
  124. case "START=" : {_initialDelay = _this select (_parameterIndex + 1)};
  125. case "CACHE=" : {_cacheRadius = _this select (_parameterIndex + 1)};
  126. case "REDUCE=" : {_reduceRadius = _this select (_parameterIndex + 1)};
  127. case "GAIA_MOVE=" : {_gaiaParameter = "MOVE"; _gaiaZone = _this select (_parameterIndex + 1)};
  128. case "GAIA_NOFOLLOW=" : {_gaiaParameter = "NOFOLLOW"; _gaiaZone = _this select (_parameterIndex + 1)};
  129. case "GAIA_FORTIFY=" : {_gaiaParameter = "FORTIFY"; _gaiaZone = _this select (_parameterIndex + 1)};
  130. case "FLYING" : {_special = "FLY"};
  131. case "RESPAWNMARKERS=" : {_respawnMarkers = _this select (_parameterIndex + 1)};
  132. case "PAUSE=" : {_pauseRadius = _this select (_parameterIndex + 1)};
  133. case "EXIT=" : {_exitTrigger = _this select (_parameterIndex + 1)};
  134. case "INIT=" : {_initString = _this select (_parameterIndex + 1)};
  135. case "DEBUG" : {_debug = true};
  136. };
  137. };
  138.  
  139. //Add additional respawn positions where applicable
  140. {
  141. _respawnPosList pushBack (getMarkerPos _x);
  142. } forEach _respawnMarkers;
  143.  
  144. //Determine number of lives if passed an array
  145. if (typeName _lives == "ARRAY") then {
  146. _minLives = _lives select 0;
  147. _maxLives = _lives select 1;
  148. _lives = _minLives + floor random (_maxLives - _minLives);
  149. };
  150.  
  151. _syncs = synchronizedObjects _unit;
  152.  
  153. {
  154. if (typeOf _x == "EmptyDetector") then
  155. {
  156. _trigger = _x;
  157. if (_debug) then {systemChat "Synchronized trigger activation present"};
  158. }
  159. else
  160. {
  161. _synchronizedObjectsList append [_x];
  162. };
  163. } forEach _syncs;
  164.  
  165. //Check for synchronized trigger
  166. /*
  167. if (count (synchronizedObjects _unit) > 0) then {
  168. _trigger = (synchronizedObjects _unit) select 0;
  169. if (_debug) then {systemChat "Synchronized trigger activation present"};
  170. };
  171. */
  172.  
  173. //Freeze units
  174. {
  175. _x enableSimulationGlobal false;
  176. } forEach _unitsInGroup;
  177.  
  178. //Save waypoint data
  179. _waypointList = [_unitGroup] call jebus_fnc_saveWaypoints;
  180.  
  181. //Save unit data and delete
  182. {
  183. if ( (vehicle _x) isKindOf "LandVehicle" || (vehicle _x) isKindOf "Air" || (vehicle _x) isKindOf "Ship") then {
  184. _vehicleList append [typeOf (vehicle _x)];
  185. _vehicleHitpointsDamageList append [getAllHitpointsDamage (vehicle _x)];
  186. _vehicleHealthList append [damage (vehicle _x)];
  187. _vehicleFuelList append [fuel (vehicle _x)];
  188. _vehiclePositionList append [getPos (vehicle _x)];
  189. _vehicleLockedList append [locked (vehicle _x)];
  190. _vehicleItemList append [itemCargo (vehicle _x)];
  191. _vehicleMagazineList append [magazineCargo (vehicle _x)];
  192. _vehicleWeaponList append [weaponCargo (vehicle _x)];
  193. _vehicleBackpackList append [backpackCargo (vehicle _x)];
  194. _vehicleMaterialsList append [getObjectMaterials (vehicle _x)];
  195. _vehicleTexturesList append [getObjectTextures (vehicle _x)];
  196. _vehiclePylonList append [getPylonMagazines (vehicle _x)];
  197.  
  198. _thisVehicle = (vehicle _x);
  199. _thisAnimationNames = animationNames (vehicle _x);
  200. _thisAnimationPhases = [];
  201. {
  202. _thisAnimationPhases append [_thisVehicle animationPhase _x];
  203. } forEach _thisAnimationNames;
  204. _vehicleAnimationNames append [_thisAnimationNames];
  205. _vehicleAnimationPhases append [_thisAnimationPhases];
  206.  
  207.  
  208. _tmpCrew = crew (vehicle _x);
  209. sleep 0.1;
  210. deleteVehicle (vehicle _x);
  211. sleep 0.1;
  212. _tmpCrewList = [];
  213. _tmpCrewInventoryList = [];
  214. _tmpCrewSkillList = [];
  215. _tmpCrewSubgroupList = [];
  216. {
  217. _tmpCrewList append [typeOf (vehicle _x)];
  218. _tmpCrewInventoryList append [getUnitLoadout _x];
  219. _tmpCrewSkillList append [skill _x];
  220.  
  221. if (!((group _x) isEqualTo _unitGroup)) then
  222. {
  223. if (!(group _x in _subgroupList)) then
  224. {
  225. _subgroupList append [group _x];
  226. _subgroupWaypointList append [[group _x] call jebus_fnc_saveWaypoints];
  227. };
  228. };
  229.  
  230. _tmpIndex = _subgroupList find (group _x);
  231. _tmpCrewSubgroupList append [_tmpIndex];
  232.  
  233. deleteVehicle _x;
  234. sleep 0.1
  235. } forEach _tmpCrew;
  236.  
  237. _crewList set [(count _vehicleList - 1), _tmpCrewList];
  238. _crewInventoryList set [(count _vehicleList - 1), _tmpCrewInventoryList];
  239. _crewSkillList set [(count _vehicleList - 1), _tmpCrewSkillList];
  240. _crewSubgroupList set [(count _vehicleList - 1), _tmpCrewSubgroupList];
  241. } else {
  242. _infantryList append [typeOf (vehicle _x)];
  243. _infantryInventoryList append [getUnitLoadout _x];
  244. _infantrySkillList append [skill _x];
  245. deleteVehicle (vehicle _x);
  246. sleep 0.1;
  247. };
  248.  
  249. sleep 0.1;
  250.  
  251. } forEach _unitsInGroup;
  252.  
  253. deleteGroup _unitGroup;
  254. {
  255. systemChat format ["%1", _x];
  256. deleteGroup _x;
  257. } forEach _subgroupList;
  258. sleep 1;
  259.  
  260. _firstLoop = true;
  261.  
  262. //Main loop
  263. while { _lives != 0 } do {
  264. //Wait for trigger activation (Thanks to pritchardgsd)
  265. if (! isNil "_trigger") then {
  266. while {! (triggerActivated _trigger)} do {
  267. sleep 10;
  268. if (_debug) then {systemChat "Waiting for trigger activation"};
  269. };
  270. };
  271.  
  272. if (_firstLoop && _initialDelay > 0) then {
  273. sleep _initialDelay;
  274. _firstLoop = false;
  275. systemChat "First Loop!";
  276. };
  277.  
  278. if (_debug) then {systemChat "Spawning group."};
  279.  
  280. _newGroup = createGroup _unitSide;
  281. _newGroup setVariable ["groupInitialising", true, false];
  282. _newSubgroupList = [];
  283. {
  284. _newTmpGroup = createGroup _unitSide;
  285. _newTmpGroup setVariable ["groupInitialising", true, false];
  286. _newSubgroupList append [_newTmpGroup];
  287. } forEach _subgroupList;
  288.  
  289. _tmpRespawnPos = selectRandom _respawnPosList;
  290.  
  291. while {[_tmpRespawnPos, _unitSide, _pauseRadius] call jebus_fnc_enemyInRadius} do {
  292. if (_debug) then {systemChat "Enemies in pause radius. Waiting."};
  293. sleep 5;
  294. };
  295.  
  296. //Spawn vehicles - spawn, disable sim, add crew, enable sim......
  297. for "_vehicleIndex" from 0 to (count _vehicleList - 1) do {
  298. private "_newVehiclePosition";
  299.  
  300. _newVehicleType = (_vehicleList select _vehicleIndex);
  301. if (_tmpRespawnPos isEqualTo _respawnPos) then {
  302. _newVehiclePosition = (_vehiclePositionList select _vehicleIndex);
  303. } else {
  304. if (_vehicleIndex == 0) then {
  305. _newVehiclePosition = _tmpRespawnPos;
  306. } else {
  307. _newVehiclePosition = _tmpRespawnPos findEmptyPosition [5, 50, _newVehicleType];
  308. };
  309. };
  310. _newVehicle = createVehicle [_newVehicleType, _newVehiclePosition, [], 0, _special];
  311. _newGroup setFormDir _respawnDir;
  312. _newVehicle setDir _respawnDir;
  313. _newGroup addVehicle _newVehicle;
  314. _newVehicle enableSimulationGlobal false;
  315. _newVehicle lock (_vehicleLockedList select _vehicleIndex);
  316. _newVehicle setDamage (_vehicleHealthList select _vehicleIndex);
  317. _newVehicle setFuel (_vehicleFuelList select _vehicleIndex);
  318. _hitpoint = (_vehicleHitpointsDamageList select _vehicleIndex) select 0;
  319. _hitpointDamage = (_vehicleHitpointsDamageList select _vehicleIndex) select 2;
  320. {
  321. _newVehicle setHitPointDamage [_x, _hitpointDamage select _forEachIndex];
  322. } forEach _hitpoint;
  323. //hint format["%1", _hitpoint];
  324. clearItemCargoGlobal _newVehicle;
  325. clearMagazineCargoGlobal _newVehicle;
  326. clearWeaponCargoGlobal _newVehicle;
  327. clearBackpackCargoGlobal _newVehicle;
  328. {
  329. _newVehicle addItemCargoGlobal [_x,1];
  330. } forEach (_vehicleItemList select _vehicleIndex);
  331. {
  332. _newVehicle addMagazineCargoGlobal [_x,1];
  333. } forEach (_vehicleMagazineList select _vehicleIndex);
  334. {
  335. _newVehicle addWeaponCargoGlobal [_x,1];
  336. } forEach (_vehicleWeaponList select _vehicleIndex);
  337. {
  338. _newVehicle addBackpackCargoGlobal [_x,1];
  339. } forEach (_vehicleBackpackList select _vehicleIndex);
  340. {
  341. _newVehicle setPylonLoadOut [(_forEachIndex + 1), _x];
  342. } forEach (_vehiclePylonList select _vehicleIndex);
  343. {
  344. _newVehicle setObjectMaterialGlobal [_forEachIndex, _x];
  345. } forEach (_vehicleMaterialsList select _vehicleIndex);
  346. {
  347. _newVehicle setObjectTextureGlobal [_forEachIndex, _x];
  348. } forEach (_vehicleTexturesList select _vehicleIndex);
  349.  
  350. _thisAnimationNames = _vehicleAnimationNames select _vehicleIndex;
  351. _thisAnimationPhases = _vehicleAnimationPhases select _vehicleIndex;
  352. {
  353. _newVehicle animateSource [_x, _thisAnimationPhases select _forEachIndex];
  354. } forEach _thisAnimationNames;
  355.  
  356. sleep 0.1;
  357.  
  358. _tmpGroup = [_tmpRespawnPos, _unitSide, (_crewList select _vehicleIndex)] call BIS_fnc_spawnGroup;
  359. {
  360. _tmpInventory = _crewInventoryList select _vehicleIndex;
  361. _x setUnitLoadout (_tmpInventory select _forEachIndex);
  362. _tmpSkill = _crewSkillList select _vehicleIndex;
  363. _x setSkill (_tmpSkill select _forEachIndex);
  364. _tmpSubgroupindex = _crewSubgroupList select _vehicleIndex;
  365. _tmpIndex = _tmpSubgroupindex select _forEachIndex;
  366. if (_tmpIndex isEqualTo -1) then
  367. {
  368. [_x] joinSilent _newGroup;
  369. }
  370. else
  371. {
  372. [_x] joinSilent (_newSubgroupList select _tmpIndex);
  373. };
  374. sleep 0.1;
  375. _x moveInAny _newVehicle;
  376.  
  377. } forEach (units _tmpGroup);
  378.  
  379. waituntil {
  380. sleep 1;
  381. count crew _newVehicle >= count (units _tmpGroup)
  382. };
  383.  
  384. if (_newVehicle isKindOf "Plane" && _special == "FLY") then {
  385. _newVehicle setVelocity [
  386. 60 * sin _respawnDir,
  387. 60 * cos _respawnDir,
  388. 0
  389. ];
  390. };
  391.  
  392. _newVehicle enableSimulationGlobal true;
  393.  
  394. sleep 0.1;
  395.  
  396. //(units _tmpGroup) joinSilent _newGroup;
  397.  
  398. {_x addCuratorEditableObjects [[_newVehicle],true]} forEach allCurators;
  399. sleep 0.1;
  400. };
  401.  
  402. //Spawn infantry
  403. _tmpGroup = [_tmpRespawnPos, _unitSide, _infantryList] call BIS_fnc_spawnGroup;
  404. sleep 0.1;
  405. {
  406. _x setUnitLoadout (_infantryInventoryList select _forEachIndex);
  407. _x setSkill (_infantrySkillList select _forEachIndex);
  408. sleep 0.1;
  409. } forEach (units _tmpGroup);
  410.  
  411. (units _tmpGroup) joinSilent _newGroup;
  412.  
  413. sleep 0.1;
  414.  
  415. {_x addCuratorEditableObjects [units _newGroup,false]} forEach allCurators;
  416.  
  417. //Initiate caching
  418. if ("CACHE=" in _this) then {
  419. [_newGroup, _cacheRadius, _debug] spawn jebus_fnc_cache;
  420. {
  421. [_x, _cacheRadius, _debug] spawn jebus_fnc_cache;
  422. } forEach _newSubgroupList;
  423. };
  424.  
  425. //Initiate reducing
  426. if ("REDUCE=" in _this) then {
  427. [_newGroup, _reduceRadius, _debug] spawn jebus_fnc_reduce;
  428. {
  429. [_x, _reduceRadius, _debug] spawn jebus_fnc_reduce;
  430. } forEach _newSubgroupList;
  431. };
  432.  
  433. _newGroup allowfleeing 0;
  434. {
  435. _x allowfleeing 0;
  436. } forEach _newSubgroupList;
  437.  
  438. //Initiate GAIA
  439. if (_gaiaParameter in ["MOVE", "NOFOLLOW", "FORTIFY"]) then {
  440. if (_debug) then {systemChat _gaiaParameter};
  441. switch (typeName _gaiaZone) do {
  442. case "ARRAY" : {
  443. _tmpZone = selectRandom _gaiaZone;
  444. if (typeName _tmpZone == "SCALAR") then {_tmpZone = str (_tmpZone);};
  445. };
  446. case "SCALAR" : {_tmpZone = str (_gaiaZone);};
  447. default {_tmpZone = _gaiaZone};
  448. };
  449.  
  450. _newGroup setVariable ["GAIA_ZONE_INTEND",[_tmpZone, _gaiaParameter], false];
  451. {
  452. _x setVariable ["GAIA_ZONE_INTEND",[_tmpZone, _gaiaParameter], false];
  453. } forEach _newSubgroupList;
  454. };
  455.  
  456. //Apply waypoints
  457. [_newGroup, _waypointList, _debug] call jebus_fnc_applyWaypoints;
  458. {
  459. [_x, _subgroupWaypointList select _forEachIndex, _debug] call jebus_fnc_applyWaypoints;
  460. } forEach _newSubgroupList;
  461.  
  462.  
  463. //Execute init string
  464. _proxyThis = leader _newgroup;
  465.  
  466. {
  467. _proxyThis synchronizeObjectsAdd [_x];
  468. } forEach _synchronizedObjectsList;
  469.  
  470.  
  471. call compile format [_initString];
  472.  
  473. _newGroup setVariable ["groupInitialising", nil];
  474. {
  475. _x setVariable ["groupInitialising", nil];
  476. } forEach _newSubgroupList;
  477.  
  478. //Check every 5 seconds to see if group is eliminated
  479. waituntil {
  480. sleep 5;
  481. cnt = {alive _x} count (units _newGroup);
  482. {
  483. _y = _x;
  484. cnti = {alive _x} count (units _y);
  485. cnt = cnt + cnti;
  486. } forEach _newSubgroupList;
  487. cnt < 1;
  488. };
  489.  
  490. if (_debug) then {systemChat "Group eliminated. Waiting for respawn."};
  491.  
  492. //Respawn delay
  493. if (typeName _respawnDelay == "ARRAY") then {
  494. _minTime = _respawnDelay select 0;
  495. _maxTime = _respawnDelay select 1;
  496. _tempRespawnDelay = _minTime + random (_maxTime - _minTime);
  497. if (_debug) then {systemChat format ["Respawn delay = %1 seconds", _tempRespawnDelay]};
  498. sleep _tempRespawnDelay;
  499. } else {
  500. if (_debug) then {systemChat format ["Respawn delay = %1 seconds", _respawnDelay]};
  501. sleep _respawnDelay;
  502. };
  503.  
  504. //Check if exit trigger has been activated
  505. if (! isNil "_exitTrigger") then {
  506. if (triggerActivated _exitTrigger) then {
  507. if (_debug) then {systemChat "Exit trigger activated"};
  508. _lives = 1;
  509. };
  510. };
  511.  
  512. _lives = _lives - 1;
  513.  
  514. if (_debug) then {
  515. if (_lives < 0) then {systemChat "Infinite lives."} else
  516. {systemChat format["Lives remaining = %1", _lives]};
  517. };
  518.  
  519. //Clean up empty groups
  520. {
  521. if ((count (units _x)) isEqualTo 0) then {
  522. if (isNil {_x getVariable "groupInitialising"}) then {
  523. deleteGroup _x;
  524. };
  525. };
  526. } count allGroups;
  527.  
  528. };
  529.  
  530. if (_debug) then {systemChat "Exiting script."};
Advertisement
Add Comment
Please, Sign In to add comment