Advertisement
skotracker

IgiLoadTaru.sqf

Apr 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 17.53 KB | None | 0 0
  1. /*
  2. This script is based on Xeno Taru mod from NorX Aengell.
  3. http://www.armaholic.com/page.php?id=27532
  4.  
  5. Original author: NorX Aengell
  6. Rewrite and Epoch adaptation: Slayer
  7.  
  8. */
  9.  
  10. IL_Taru_DevMod = false;
  11.  
  12. //above this altitude dropping with parachute
  13. IL_Taru_Parachute_Altitude = 45;
  14.  
  15. //open parachute when altitude is less or equal this parameter
  16. IL_Taru_Parachute_Open_Altitude = 30;
  17. //IL_Taru_Parachute_Altitude must be greater then IL_Taru_Parachute_Open_Altitude
  18.  
  19. IL_Taru_Disable_Deattaching_Altitude = 3;
  20. //Not posible to deattach when altitude is extrely low, because new position of pod will be under terrain level.
  21. //Recomended values are between 3 and 10.
  22.  
  23. if (hasInterface && !isDedicated) then {
  24.     if (IL_Taru_DevMod) then {
  25.          diag_log "Igi Load Taru started";
  26.     };
  27.  
  28.     IL_Taru_Init =
  29.     {
  30.         waituntil
  31.         {
  32.             sleep 2;
  33.  
  34.             {
  35.                 if (isnil {_x getVariable "IL_Taru_Action_Attach"}) then
  36.                 {
  37.                     _x setVariable ["IL_Taru_Action_Attach",true,false];
  38.  
  39.                     IL_Taru_Action_Attach = _x addAction ["<img image='IgiLoad\images\load.paa' /><t color=""#007f0e""> Attach Pod</t>", "[""attach"",_this] call IL_Taru_Do_Action;", nil, 2, false, true, "",
  40.                     "[_this] call IL_Verify_Heli and {[vehicle _this] call IL_Verify_Pod} and {!([vehicle _this] call IL_Verify_Attached_Object)}"];
  41.                 };
  42.  
  43.                 if (isnil {_x getVariable "IL_Taru_Action_Deattach"}) then
  44.                 {
  45.                     _x setVariable ["IL_Taru_Action_Deattach",true,false];
  46.  
  47.                     IL_Taru_Action_Deattach = _x addAction ["<img image='IgiLoad\images\unload.paa' /><t color=""#ff0000""> Detach Pod</t>", "[""deattach"",_this] call IL_Taru_Do_Action;", nil, 2, false, true, "",
  48.                     "[_this] call IL_Verify_Heli and [_this] call IL_Verify_Altitude and {[vehicle _this] call IL_Verify_Attached_Object}"];
  49.                 };
  50.  
  51.                 if (isnil {_x getVariable "IL_Taru_Action_Drop"}) then
  52.                 {
  53.                     _x setVariable ["IL_Taru_Action_Drop",true,false];
  54.  
  55.                     IL_Taru_Action_Drop = _x addAction ["<img image='IgiLoad\images\unload_para.paa' /><t color=""#b200ff""> Drop Pod</t>", "[""drop"",_this] call IL_Taru_Do_Action;", nil, 2, false, true, "",
  56.                     "[_this] call IL_Verify_Heli and {[vehicle _this] call IL_Verify_Attached_Object}"];
  57.                 };
  58.             } foreach units group player;
  59.         };
  60.     };
  61.  
  62.     IL_Verify_Attached_Object =
  63.     {
  64.         if (IL_Taru_DevMod) then {
  65.             diag_log "IL_Verify_Attached_Object called";
  66.         };
  67.         _helico = (_this select 0);
  68.         _object_Verifier = false;
  69.         if (count (attachedObjects _helico) isEqualTo 0) exitwith {_object_Verifier};
  70.         {
  71.             if (_x isKindOf "Pod_Heli_Transport_04_base_F") exitwith {_object_Verifier = true;};
  72.         } foreach attachedObjects _helico;
  73.         if (IL_Taru_DevMod) then {
  74.              diag_log format["IL_Verify_Attached_Object returns %1",_object_Verifier];
  75.         };
  76.         _object_Verifier
  77.     };
  78.  
  79.     IL_Verify_Pod =
  80.     {
  81.         if (IL_Taru_DevMod) then {
  82.             diag_log "IL_Verify_Pod called";
  83.         };
  84.         _pod = getSlingLoad (_this select 0);
  85.         _pod_Verifier = false;
  86.         if (isnull (getSlingLoad vehicle player)) exitwith {_pod_Verifier};
  87.         if (_pod isKindOf "Pod_Heli_Transport_04_base_F") then {_pod_Verifier = true;};
  88.         if (IL_Taru_DevMod) then {
  89.              diag_log format["IL_Verify_Pod returns %1",_pod_Verifier];
  90.         };
  91.         _pod_Verifier
  92.     };
  93.  
  94.     IL_Verify_Heli =
  95.     {
  96.         if (IL_Taru_DevMod) then {
  97.             diag_log "IL_Verify_Heli called";
  98.         };
  99.         _helico = vehicle (_this select 0);
  100.         _helico_Verifier = false;
  101.         if (_helico isKindOf "Heli_Transport_04_base_F") then {_helico_Verifier = true;};
  102.         if (IL_Taru_DevMod) then {
  103.              diag_log format["IL_Verify_Heli returns %1",_helico_Verifier];
  104.         };
  105.         _helico_Verifier
  106.     };
  107.  
  108.     IL_Verify_Altitude = {
  109.         if (IL_Taru_DevMod) then {
  110.             diag_log "IL_Verify_Altitude called";
  111.         };
  112.         _helico = vehicle (_this select 0);
  113.         _allow_deattach = false;
  114.         if ((getPosATL _helico) select 2 > IL_Taru_Disable_Deattaching_Altitude) then {_allow_deattach = true;};
  115.         if (IL_Taru_DevMod) then {
  116.              diag_log format["IL_Verify_Altitude returns %1",_allow_deattach];
  117.         };
  118.         _allow_deattach
  119.     };
  120.  
  121.     IL_Taru_Do_Action =
  122.     {
  123.         _action = _this select 0;
  124.         _helico = "";
  125.  
  126.         if (typename (_this select 1) isEqualTo "OBJECT") then {_helico = vehicle (_this select 1);};
  127.         if (typename (_this select 1) isEqualTo "ARRAY") then {_helico = vehicle ((_this select 1) select 0);};
  128.  
  129.         _cables = ropes _helico;
  130.  
  131.         if (ropeUnwound (_cables select 0)) then
  132.         {
  133.             [_action, _helico] call IL_Pod_Manager;
  134.         };
  135.     };
  136.  
  137.     IL_Taru_Transmission =
  138.     {
  139.         private ["_soundToPlay", "_helico", "_soundToPlay","_args","_pod"];
  140.         _args = _this select 1;
  141.         _helico = vehicle (_args select 1);
  142.         _soundPath = [(str missionConfigFile), 0, -15] call BIS_fnc_trimString;
  143.  
  144.         switch (_args select 0) do {
  145.             case 'rope_unwind': {
  146.                 _pod = _args select 2;
  147.                 _helico disableCollisionWith _pod;
  148.                 {ropeUnwind [_x, _args select 3, _args select 4];} foreach ropes _helico;
  149.                 sleep 4;
  150.                 _helico enableCollisionWith _pod;
  151.             };
  152.             case 'rope_unwind_and_wait': {
  153.                 _pod = _args select 2;
  154.                 _helico disableCollisionWith _pod;
  155.                 {ropeUnwind [_x, _args select 3, _args select 4];} foreach ropes _helico;
  156.                 waituntil {ropeLength ((ropes _helico) select 0) isEqualTo 1};
  157.                 sleep 4;
  158.                 _helico enableCollisionWith _pod;
  159.             };
  160.             case 'chat_attach': {
  161.                  if (!(player in crew _helico)) exitWith{};
  162.                  ["Success",["Pod successfully attached!"]] call ExileClient_gui_notification_event_addNotification;
  163.             };
  164.             case 'chat_deattach': {
  165.                 if (!(player in crew _helico)) exitWith{};
  166.                  ["Success",["Pod successfully dettached!"]] call ExileClient_gui_notification_event_addNotification;
  167.             };
  168.             case 'chat_drop_with_parachute': {
  169.                  if (!(player in crew _helico)) exitWith{};
  170.                  ["Success",["Pod Paradropt!"]] call ExileClient_gui_notification_event_addNotification;
  171.             };
  172.             case 'chat_drop_without_parachute': {
  173.                  if (!(player in crew _helico)) exitWith{};
  174.                  ["Success",["Pod drop without Parachut!"]] call ExileClient_gui_notification_event_addNotification;
  175.             };
  176.             case 'sound_attach': {
  177.                  if (!(player in crew _helico)) exitWith{};
  178.                  _soundToPlay = _soundPath + "IgiLoad\sounds\attach.wss";
  179.                 playSound3D [_soundToPlay, _helico, false, getPosATL _helico, 10, 1, 0];
  180.             };
  181.             case 'sound_deattach': {
  182.                  if (!(player in crew _helico)) exitWith{};
  183.                  _soundToPlay = _soundPath + "IgiLoad\sounds\deattach.wss";
  184.                 playSound3D [_soundToPlay, _helico, false, getPosATL _helico, 10, 1, 0];
  185.             };
  186.             case 'sound_drop': {
  187.                  if (!(player in crew _helico)) exitWith{};
  188.                  _soundToPlay = _soundPath + "IgiLoad\sounds\drop.wss";
  189.                 playSound3D [_soundToPlay, _helico, false, getPosATL _helico, 10, 1, 0];
  190.             };
  191.         };
  192.     };
  193.  
  194.     waitUntil {!isNull player};
  195.     [] spawn IL_Taru_Init;
  196.     IL_Taru_EH_Respawn = player addEventHandler ["Respawn", "[] spawn IL_Taru_Init;"];
  197. };
  198.  
  199. IL_Pod_Manager = {
  200.     IL_CLient_Pod_Manager = _this;
  201.     if (isDedicated || isServer) then
  202.     {
  203.         IL_CLient_Pod_Manager spawn IL_Server_Pod_Manager;
  204.     }
  205.     else
  206.     {
  207.         publicVariableServer "IL_CLient_Pod_Manager";
  208.     };
  209. };
  210. "IL_Client_Pod_Manager" addPublicVariableEventHandler IL_Pod_Manager;
  211.  
  212. IL_Client_Control = {
  213.     private ["_nearBy","_heli","_heli_pos"];
  214.     IL_Server_Client_Control = _this;
  215.     if (hasInterface && !isDedicated) then
  216.     {
  217.         IL_Server_Client_Control spawn IL_Taru_Transmission; Exile_
  218.     }
  219.     else
  220.     {
  221.         _heli = IL_Server_Client_Control select 1;
  222.         _nearBy = (getPosATL _heli) nearEntities [["Exile_Unit_Player","LandVehicle","Ship","Air"], 300];
  223.         {
  224.             if (isPlayer _x) then {
  225.                 (owner _x) publicVariableClient "IL_Server_Client_Control";
  226.             };
  227.         } forEach _nearBy;
  228.     };
  229. };
  230. "IL_Server_Client_Control" addPublicVariableEventHandler IL_Client_Control;
  231.  
  232.  
  233. if (isDedicated || isServer) then {
  234.     if (IL_Taru_DevMod) then {
  235.          diag_log "Igi Load Taru started";
  236.     };
  237.  
  238.     IL_Server_Pod_Manager = {
  239.         private ["_args"];
  240.         _args = _this select 1;
  241.         switch (_args select 0) do {
  242.             case "attach": {
  243.                  [_args select 1] spawn IL_Taru_Attach_Pod;
  244.             };
  245.             case "deattach": {
  246.                  [_args select 1] spawn IL_Taru_Deattach_Pod;
  247.             };
  248.             case "drop": {
  249.                  [_args select 1] spawn IL_Taru_Drop_Pod;
  250.             };
  251.         };
  252.     };
  253.  
  254.     IL_Taru_Attach_Pod =
  255.     {
  256.         _helico = _this select 0;
  257.         _pod = getSlingLoad _helico;
  258.         _mass_of_pod = getmass getSlingLoad _helico;
  259.         _mass_of_heli = getmass _helico;
  260.  
  261.         if (!isTouchingGround _helico) then
  262.         {
  263.  
  264.             ["sound_attach", _helico] call IL_Client_Control;
  265.             ["rope_unwind_and_wait", _helico, _pod, 1.9, 1, 1] call IL_Client_Control;
  266.             sleep 1;
  267.             {ropeUnwind [_x, 1.9, 1];} foreach ropes _helico;
  268.  
  269.             waituntil {ropeLength (ropes _helico select 0) isEqualTo 1};
  270.  
  271.         };
  272.  
  273.         _helico disableCollisionWith _pod;
  274.         [] call {
  275.             _pod_type = typeOf _pod;
  276.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_bench_F") exitwith
  277.             {
  278.                 _pod attachTo [_helico,[0,0.1,-1.13]];
  279.                 _helico setCustomWeightRTD 680;
  280.                 _helico setmass _mass_of_pod + _mass_of_heli;
  281.             };
  282.  
  283.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_covered_F") exitwith
  284.             {
  285.                 _pod attachTo [_helico,[-0.1,-1.05,-0.82]];
  286.                 _helico setCustomWeightRTD 1413;
  287.                 _helico setmass _mass_of_pod + _mass_of_heli;
  288.             };
  289.  
  290.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_fuel_F") exitwith
  291.             {
  292.                 _pod attachTo [_helico,[0,-0.282,-1.25]];
  293.                 _helico setCustomWeightRTD 13311;
  294.                 _helico setmass _mass_of_pod + _mass_of_heli;
  295.             };
  296.  
  297.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_medevac_F") exitwith
  298.             {
  299.                 _pod attachTo [_helico,[-0.14,-1.05,-0.92]];
  300.                 _helico setCustomWeightRTD 1321;
  301.                 _helico setmass _mass_of_pod + _mass_of_heli;
  302.             };
  303.  
  304.             if (_pod_type in ["Land_Pod_Heli_Transport_04_repair_F","Land_Pod_Heli_Transport_04_box_F","Land_Pod_Heli_Transport_04_ammo_F"]) exitwith
  305.             {
  306.                 _pod attachTo [_helico,[-0.09,-1.05,-1.1]];
  307.                 _helico setCustomWeightRTD 1270;
  308.                 _helico setmass _mass_of_pod + _mass_of_heli;
  309.             };
  310.          };
  311.  
  312.         ["rope_unwind", _helico, _pod, 250, 1] call IL_Client_Control;
  313.         sleep 1;
  314.         {ropeUnwind [_x, 250, 1];} foreach ropes _helico;
  315.         _helico enableCollisionWith _pod;
  316.         ["sound_attach", _helico] call IL_Client_Control;
  317.         ["chat_attach", _helico] call IL_Client_Control;
  318.  
  319.         if (isnil {_helico getVariable "EH_GetOut_Taru"}) then
  320.         {
  321.             _helico addEventHandler ["Getin", "[_this] spawn IL_Taru_GetIn;"];
  322.             _helico setVariable ["EH_GetIn_Taru", true, false];
  323.         };
  324.     };
  325.  
  326.     IL_Taru_Deattach_Pod =
  327.     {
  328.         _helico = _this select 0;
  329.         _attached_object = [];
  330.         _mass_of_heli = getmass _helico;
  331.         {
  332.             if (_x isKindOf "Pod_Heli_Transport_04_base_F") exitwith {_attached_object = _x;};
  333.         } foreach attachedObjects _helico;
  334.  
  335.         _mass_of_pod = getmass _attached_object;
  336.         _helico disableCollisionWith _attached_object;
  337.  
  338.         [] call {
  339.             _pod_type = typeOf _attached_object;
  340.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_bench_F") exitwith
  341.             {
  342.                 _attached_object attachTo [_helico,[0,0.1,-2.83]];
  343.             };
  344.  
  345.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_covered_F") exitwith
  346.             {
  347.                 _attached_object attachTo [_helico,[-0.1,-1.05,-2.52]];
  348.             };
  349.  
  350.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_fuel_F") exitwith
  351.             {
  352.                 _attached_object attachTo [_helico,[0,-0.282,-3.05]];
  353.             };
  354.  
  355.             if (_pod_type isEqualTo "Land_Pod_Heli_Transport_04_medevac_F") exitwith
  356.             {
  357.                 _attached_object attachTo [_helico,[-0.14,-1.05,-2.62]];
  358.             };
  359.  
  360.             if (_pod_type in ["Land_Pod_Heli_Transport_04_repair_F","Land_Pod_Heli_Transport_04_box_F","Land_Pod_Heli_Transport_04_ammo_F"]) exitwith
  361.             {
  362.                 _attached_object attachTo [_helico,[-0.09,-1.05,-2.8]];
  363.             };
  364.         };
  365.  
  366.         ["rope_unwind", _helico, _attached_object, 1,9, 10] call IL_Client_Control;
  367.         sleep 1;
  368.         {
  369.             ropeUnwind [_x, 1.9, 10];
  370.         } foreach ropes _helico;
  371.         ["sound_deattach", _helico] call IL_Client_Control;
  372.  
  373.         _helico setCustomWeightRTD 0;
  374.         _helico setmass _mass_of_heli - _mass_of_pod;
  375.         ["sound_deattach", _helico] call IL_Client_Control;
  376.         ["chat_deattach", _helico] call IL_Client_Control;
  377.         detach _attached_object;
  378.         sleep 4;
  379.         _helico enableCollisionWith _attached_object;
  380.         //if (!isTouchingGround _helico) then {waituntil {ropeLength (ropes _helico select 0) isEqualTo 10};};
  381.     };
  382.  
  383.     IL_Taru_Drop_Pod =
  384.     {
  385.         _helico = _this select 0;
  386.         _attached_object = [];
  387.  
  388.         {
  389.             if (_x isKindOf "Pod_Heli_Transport_04_base_F") exitwith {_attached_object = _x;};
  390.         } foreach attachedObjects _helico;
  391.  
  392.         _helico disableCollisionWith _attached_object;
  393.         {ropeCut [_x, 0];} foreach ropes _helico;
  394.         _helico setCustomWeightRTD 0;
  395.         ["sound_drop", _helico] call IL_Client_Control;
  396.         detach _attached_object;
  397.         sleep 4;
  398.         _helico enableCollisionWith _attached_object;
  399.  
  400.         sleep 0.5;
  401.  
  402.         if ((getPosATL _attached_object) select 2 >= IL_Taru_Parachute_Altitude) exitwith
  403.         {
  404.             ["chat_drop_with_parachute", _helico] call IL_Client_Control;
  405.  
  406.             waituntil {(getPosATL _attached_object) select 2 <= IL_Taru_Parachute_Open_Altitude};
  407.  
  408.             _parachute = createVehicle ["B_Parachute_02_F",getposatl _attached_object, [], 0, "CAN COLLIDE"];
  409.             _parachute attachTo [_attached_object,[0,0,-1]];
  410.  
  411.             [_attached_object,_parachute,_helico] spawn
  412.             {
  413.                 _attached_object = _this select 0;
  414.                 _parachute = _this select 1;
  415.                 _helico = _this select 2;
  416.  
  417.                 waituntil
  418.                 {
  419.                     if ((getPosATL _attached_object) select 2 <= 5) exitwith
  420.                     {
  421.                         detach _attached_object;
  422.                         _vitesse_nacelle = velocity _attached_object;
  423.                         _parachute setVelocity [_vitesse_nacelle select 0 + 1, _vitesse_nacelle select 1 + 1, 0];
  424.                         true
  425.                     };
  426.                     false
  427.                 };
  428.             };
  429.  
  430.             waituntil
  431.             {
  432.                 if (getposasl _helico distance getposasl _attached_object >= 50) exitwith
  433.                 {
  434.                     detach _parachute;
  435.                     _attached_object attachTo [_parachute,[0,0,-1]];
  436.                     true
  437.                 };
  438.                 false
  439.             };
  440.         };
  441.  
  442.         ["chat_drop_without_parachute", _helico] call IL_Client_Control;
  443.     };
  444.  
  445.     IL_Taru_GetIn =
  446.     {
  447.         _vehicle = _this select 0 select 0;
  448.         if ([_vehicle] call IL_Verify_Heli) then
  449.         {
  450.             if (count attachedObjects _vehicle > 0) then
  451.             {
  452.                 _time = time + 2;
  453.                 waituntil
  454.                 {
  455.                     _vehicle setvelocity [0, 0, 0];
  456.                     if (time > _time or {time > _time + 15}) exitwith {true};
  457.                 };
  458.             };
  459.         };
  460.     };
  461.  
  462.     IL_Save_Pod_Position =
  463.     {
  464.         while{true}do {
  465.             sleep 20;
  466.             {
  467.                sleep 2;
  468.                //when you dropping with parachute or deattaching pod without player, new position of the pod is not saved to db.
  469.                //with following ugly hack we are saving pod position every 20 seconds
  470.                if (_x isKindOf "Pod_Heli_Transport_04_base_F") then {
  471.                   _x call ExileServer_object_vehicle_database_update;
  472.                };
  473.             } forEach vehicles;
  474.         };
  475.     };
  476.  
  477.     [] spawn IL_Save_Pod_Position;
  478. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement