Advertisement
Guest User

Untitled

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