LeventHAN

fastrope.sqf

Sep 11th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.28 KB | None | 0 0
  1. // Fast Rope
  2.  
  3. #define MAX_SPEED_WHILE_FASTROPING 10
  4. #define MAX_SPEED_ROPES_AVAIL 30
  5.  
  6.  
  7. #define STR_TOSS_ROPES "Toss Ropes"
  8. #define STR_FAST_ROPE "Fast Rope"
  9. #define STR_CUT_ROPES "Cut Ropes"
  10.  
  11.  
  12. if (isdedicated) exitwith {};
  13. waituntil {player == player};
  14.  
  15. zlt_rope_ropes = [];
  16. zlt_mutexAction = false;
  17.  
  18. zlt_rope_helis = ["O_Heli_Light_02_unarmed_F","O_Heli_Light_02_F","B_Heli_Transport_01_F","B_Heli_Transport_01_camo_F","O_Heli_Attack_02_F","O_Heli_Attack_02_black_F","I_Heli_Transport_02_F","B_Heli_Light_01_F"];
  19. zlt_rope_helidata =
  20. [
  21.     [
  22.         ["O_Heli_Light_02_unarmed_F", "O_Heli_Light_02_F"],
  23.         [1.35,1.35,-24.95],
  24.         [-1.45,1.35,-24.95]
  25.     ],
  26.     [
  27.         ["B_Heli_Transport_01_F", "B_Heli_Transport_01_camo_F"],
  28.         [-1.11,2.5,-24.7],
  29.         [1.11,2.5,-24.7]
  30.     ],
  31.     [
  32.         ["O_Heli_Attack_02_F", "O_Heli_Attack_02_black_F"],
  33.         [1.3,1.3,-25],
  34.         [-1.3,1.3,-25]
  35.     ],
  36.     [
  37.         ["I_Heli_Transport_02_F"],
  38.         [0,-5,-26],
  39.         []
  40.     ]
  41.     [
  42.         ["B_Heli_Light_01_F"],
  43.         [0.6,0.5,-25.9],
  44.         [-0.8,0.5,-25.9]
  45.     ]
  46. ];
  47.  
  48.  
  49. zlt_fnc_tossropes = {
  50.     private ["_heli","_ropes","_oropes","_rope"];
  51.     _heli = _this;
  52.     _ropes = [];
  53.     _oropes = _heli getvariable ["zlt_ropes",[]];
  54.     if (count _oropes != 0 ) exitwith {};
  55.     _i = 0;
  56.     {
  57.         if ((typeof _heli) in (_x select 0)) exitwith {
  58.             _ropes = _ropes + [_x select 1];
  59.             if ( count (_x select 2) !=0 ) then {
  60.                 _ropes = _ropes + [_x select 2];
  61.             };
  62.         };
  63.         _i = _i +1;
  64.     } foreach zlt_rope_helidata;
  65.    
  66.     sleep random 0.3;
  67.     if ( count (_heli getvariable ["zlt_ropes",[]]) != 0 ) exitwith { zlt_mutexAction = false; };
  68.     _heli animateDoor ['door_R', 1];
  69.     _heli animateDoor ['door_L', 1];
  70.     {
  71.         _rope = createVehicle ["land_rope_f", [0,0,0], [], 0, "CAN_COLLIDE"];
  72.         _rope setdir (getdir _heli);
  73.         _rope attachto [_heli, _x];
  74.         _oropes = _oropes + [_rope];
  75.     } foreach _ropes;
  76.     _heli setvariable ["zlt_ropes",_oropes,true];
  77.    
  78.     _heli spawn {
  79.         private ["_heli","_ropes"];
  80.         _heli = _this;
  81.         while {alive _heli and count (_heli getvariable ["zlt_ropes", []]) != 0 and abs (speed _heli) < MAX_SPEED_ROPES_AVAIL } do {
  82.             sleep 0.3;
  83.         };
  84.         _ropes = (_heli getvariable ["zlt_ropes", []]);
  85.         {deletevehicle _x} foreach _ropes;
  86.         _heli setvariable ["zlt_ropes", [], true];
  87.     };
  88.  
  89. };
  90.  
  91. zlt_fnc_ropes_cond = {
  92.     _veh = vehicle player;
  93.     _flag = (_veh != player) and {(not zlt_mutexAction)} and {count (_veh getvariable ["zlt_ropes", []]) == 0} and { (typeof _veh) in zlt_rope_helis } and {alive player and alive _veh and (abs (speed _veh) < MAX_SPEED_ROPES_AVAIL ) };
  94.     _flag;
  95.  
  96. };
  97.  
  98. zlt_fnc_fastropeaiunits = {
  99.         private ["_heli","_grunits"];
  100.         diag_log ["zlt_fnc_fastropeaiunits", _this];
  101.         _heli = _this select 0;
  102.         _grunits = _this select 1;
  103.  
  104.         dostop (driver _heli );
  105.         (driver _heli) setBehaviour "Careless";
  106.         (driver _heli) setCombatMode "Blue";
  107.        
  108.         _heli spawn zlt_fnc_tossropes;
  109.  
  110.         [_heli, _grunits] spawn {
  111.             private ["_units","_heli"];
  112.             sleep random 0.5;
  113.             _units = _this select 1;
  114.             _heli = (_this select 0);
  115.             _units = _units - [player];
  116.             _units = _units - [driver _heli];
  117.             {if (!alive _x or isplayer _x or vehicle _x != _heli) then {_units = _units - [_x];}; } foreach _units;
  118.                        
  119.             { sleep (0.5 + random 0.7); _x spawn zlt_fnc_fastropeUnit; } foreach _units;
  120.             waituntil {sleep 0.5; { (getpos _x select 2) < 1 } count _units == count _units; };
  121.             sleep 10;
  122.             (driver _heli) doFollow (leader group (driver _heli ));
  123.             (driver _heli) setBehaviour "Aware";
  124.             (driver _heli) setCombatMode "White";
  125.             _heli call zlt_fnc_cutropes;
  126.            
  127.         };
  128. };
  129.  
  130.  
  131. zlt_fnc_fastrope = {
  132.     diag_log ["fastrope", _this];
  133.     zlt_mutexAction = true;
  134.     sleep random 0.3;
  135.     if (player == leader group player) then {
  136.         [vehicle player, units group player] call zlt_fnc_fastropeaiunits;
  137.     };
  138.     player call zlt_fnc_fastropeUnit;
  139.     zlt_mutexAction = false;
  140. };
  141.  
  142. zlt_fnc_fastropeUnit = {
  143.     private ["_unit","_heli","_ropes","_rope","_zmax","_zdelta","_zc"];
  144.     _unit = _this;
  145.     _heli = vehicle _unit;
  146.     if (_unit == _heli) exitWith {};
  147.  
  148.     _ropes = (_heli getvariable ["zlt_ropes", []]);
  149.     if (count _ropes == 0) exitwith {};
  150.    
  151.     _rope = _ropes call BIS_fnc_selectRandom;
  152.     _zmax = 22;
  153.     _zdelta = 7 / 10  ;
  154.    
  155.     _zc = _zmax;
  156.     _unit action ["eject", _heli];
  157.     _unit switchmove "gunner_standup01";
  158.    
  159.     _unit setpos [(getpos _unit select 0), (getpos _unit select 1), 0 max ((getpos _unit select 2) - 3)];
  160.     while {alive _unit and (getpos _unit select 2) > 1 and (abs (speed _heli)) < MAX_SPEED_WHILE_FASTROPING  and _zc > -24} do {
  161.         _unit attachTo [_rope, [0,0,_zc]];
  162.         _zc = _zc - _zdelta;
  163.         sleep 0.1;
  164.     };
  165.     _unit switchmove "";
  166.     detach _unit;
  167.  
  168. };
  169.  
  170.  
  171. zlt_fnc_cutropes = {
  172.     _veh = _this;
  173.     _ropes = (_veh getvariable ["zlt_ropes", []]);
  174.     {deletevehicle _x} foreach _ropes;
  175.     _veh setvariable ["zlt_ropes", [], true];
  176.     _veh animateDoor ['door_R', 0];
  177.     _veh animateDoor ['door_L', 0];
  178.  
  179. };
  180.  
  181. zlt_fnc_removeropes = {
  182.     (vehicle player) call zlt_fnc_cutropes;
  183. };
  184.  
  185. zlt_fnc_createropes = {
  186.     zlt_mutexAction = true;
  187.     (vehicle player) call zlt_fnc_tossropes;
  188.     zlt_mutexAction = false;
  189. };
  190.  
  191.  
  192.  
  193. player createDiarySubject [STR_SCRIPTS_NAME,STR_SCRIPTS_NAME];
  194. player createDiaryRecord [STR_SCRIPTS_NAME,[STR_SCRIPT_NAME, STR_HELP]];
  195.  
  196. player addAction["<t color='#00ccff'>"+STR_TOSS_ROPES+"</t>", zlt_fnc_createropes, [], -1, false, false, '','[] call zlt_fnc_ropes_cond'];
  197. player addAction["<t color='#00ccff'>"+STR_CUT_ROPES+"</t>", zlt_fnc_removeropes, [], -1, false, false, '','not zlt_mutexAction and count ((vehicle player) getvariable ["zlt_ropes", []]) != 0'];
  198. player addAction["<t color='#00ccff'>"+STR_FAST_ROPE+"</t>", zlt_fnc_fastrope, [], 15, false, false, '','not zlt_mutexAction and count ((vehicle player) getvariable ["zlt_ropes", []]) != 0 and player != driver vehicle player'];
  199.  
  200. player addEventHandler ["Respawn", {
  201.     player addAction["<t color='#00ccff'>"+STR_TOSS_ROPES+"</t>", zlt_fnc_createropes, [], -1, false, false, '','[] call zlt_fnc_ropes_cond'];
  202.     player addAction["<t color='#00ccff'>"+STR_CUT_ROPES+"</t>", zlt_fnc_removeropes, [], -1, false, false, '','not zlt_mutexAction and count ((vehicle player) getvariable ["zlt_ropes", []]) != 0'];
  203.     player addAction["<t color='#00ccff'>"+STR_FAST_ROPE+"</t>", zlt_fnc_fastrope, [], 15, false, false, '','not zlt_mutexAction and count ((vehicle player) getvariable ["zlt_ropes", []]) != 0 and player != driver vehicle player'];
  204. }];
Advertisement