Advertisement
Guest User

Untitled

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