Guest User

Untitled

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