Guest User

Untitled

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