Advertisement
Guest User

Untitled

a guest
Aug 12th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. /*
  2. TPW AIR - Spawn ambient flybys of helicopters and aircraft
  3. Author: tpw
  4. Date: 20160714
  5. Version: 1.31
  6. Requires: CBA A3
  7. Compatibility: SP, MP client
  8.  
  9. Disclaimer: Feel free to use and modify this code, on the proviso that you post back changes and improvements so that everyone can benefit from them, and acknowledge the original author (tpw) in any derivative works.
  10.  
  11. To use:
  12. 1 - Save this script into your mission directory as eg tpw_air.sqf
  13. 2 - Call it with 0 = [10,300,2,[50,250,500],0] execvm "tpw_air.sqf"; where 10 = delay until flybys start (s), 300 = maximum time between flybys (sec). 0 = disable, 2 = maximum aircraft at a given time,[50,250,500] flying heights to randomly select, 0 = all aircraft (1 = civilian aircraft excluded, 2 = military aircraft excluded)
  14.  
  15. THIS SCRIPT WON'T RUN ON DEDICATED SERVERS.
  16. */
  17.  
  18. if (isDedicated) exitWith {};
  19. if (count _this < 5) exitwith {hint "TPW AIR incorrect/no config, exiting."};
  20. if (_this select 1 == 0) exitwith {};
  21. WaitUntil {!isNull FindDisplay 46};
  22.  
  23. // VARIABLES
  24. tpw_air_version = "1.31"; // Version string
  25. tpw_air_delay = _this select 0; // delay until flybys start
  26. tpw_air_time = _this select 1; // maximum time between flybys
  27. tpw_air_max = _this select 2; // maximum number of aircraft at a given time
  28. tpw_air_heights = _this select 3; // flying heights to randomly select
  29. tpw_air_civexclude = _this select 4; // 0 = all aircraft, 1 = civilian aircraft excluded, 2 = military aircraft excluded
  30. tpw_air_active = true; // Global enable/disabled
  31. tpw_air_speeds = ["NORMAL"]; // speeds for spawned aircraft
  32. tpw_air_inflight = 0;
  33.  
  34. // LIST OF AIRCRAFT - Thanks to Larrow for the code
  35. tpw_air_aircraft = ["C_Plane_Civil_01_F"];
  36.  
  37. // SELECT A COUPLE OF AIRCRAFT, SPAWN EACH TO CACHE THEM AND REDUCE STUTTERING
  38. _aircraft = [];
  39. for "_i" from 1 to 4 do
  40. {
  41. _aircraft pushback (tpw_air_aircraft deleteat floor random count tpw_air_aircraft);
  42. };
  43. tpw_air_aircraft = _aircraft;
  44. {_temp = _x createvehicle [0,0,0]; sleep 0.1; deletevehicle _temp} foreach tpw_air_aircraft;
  45.  
  46. // AIRCRAFT SPAWN AND FLYBY
  47. tpw_air_fnc_flyby =
  48. {
  49. private ["_pxoffset","_pyoffset","_dir","_dist","_startx","_endx","_starty","_endy","_startpos","_endpos","_heli","_height","_speed","_aircraft","_aircrafttype","_grp","_time","_pilot","_wp0"];
  50. position (_this select 0) params ["_px","_py"];
  51.  
  52. // Timer - aircraft will be removed after 5 minutes if it is still hanging around
  53. _time = time + 300;
  54.  
  55. // Offset so that aircraft doesn't necessarily fly straight over the top of whatever called this function
  56. _pxoffset = random 1000;
  57. _pyoffset = random 1000;
  58.  
  59. // Pick a random direction and distance to spawn
  60. _dir = random 360;
  61. _dist = 4000 + (random 4000);
  62.  
  63. // Pick random aircraft, height and speed
  64. _aircrafttype = tpw_air_aircraft select (floor (random (count tpw_air_aircraft)));
  65. _height = tpw_air_heights select (floor (random (count tpw_air_heights)));
  66. _speed = tpw_air_speeds select (floor (random (count tpw_air_speeds)));
  67.  
  68. // Calculate start and end positions of flyby
  69. _startx = _px + (_dist * sin _dir) + _pxoffset;
  70. _endx = _px - (_dist * sin _dir) + _pxoffset;
  71. _starty = _py + (_dist * cos _dir) + _pyoffset;
  72. _endy = _py - (_dist * cos _dir) + _pyoffset;
  73. _startpos = [_startx,_starty,_height];
  74. _endpos = [_endx,_endy,_height];
  75.  
  76. // Create aircraft, make it ignore everyone
  77. _grp = createGroup civilian;
  78. _aircraft = [_startpos,0,_aircrafttype,_grp] call BIS_fnc_spawnVehicle;
  79. _aircraft = _aircraft select 0;
  80. _aircraft enablesimulation false;
  81. _aircraft setvariable ["tpw_air",1];
  82. _pilot = driver _aircraft;
  83. _pilot setcaptive true;
  84. _pilot setskill 0;
  85. _pilot disableAI "TARGET";
  86. _pilot disableAI "AUTOTARGET";
  87. _grp setBehaviour "CARELESS";
  88. _grp setCombatMode "BLUE";
  89. _grp setSpeedMode _speed;
  90. _grp allowfleeing 0;
  91.  
  92. // Flyby
  93. tpw_air_inflight = tpw_air_inflight + 1;
  94. _aircraft enablesimulation true;
  95. _aircraft domove _endpos;
  96. _aircraft flyinheight _height;
  97. waitUntil {sleep 5;(_aircraft distance _endpos < 1000 || !alive _aircraft || time > _time )};
  98. deleteVehicle _aircraft;
  99. {
  100. deletevehicle _x;
  101. } foreach units _grp;
  102. deleteGroup _grp;
  103. tpw_air_inflight = tpw_air_inflight - 1;
  104. publicvariable "tpw_air_inflight";
  105. };
  106.  
  107. // RUN IT
  108. sleep tpw_air_delay;
  109. while {true} do
  110. {
  111. private ["_air","_counter"];
  112. // Spawn new aircraft as necessary
  113. if (tpw_air_active && tpw_air_inflight < tpw_air_max) then
  114. {
  115. [player] spawn tpw_air_fnc_flyby;
  116. sleep tpw_air_time / 2 + (random tpw_air_time/ 2);
  117. };
  118. sleep 33.33;
  119. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement