Advertisement
Guest User

Darth_Rogue - EtV.sqf

a guest
Jan 5th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.34 KB | None | 0 0
  1. /*
  2.     Stealthstick's "Explosive-To-Vehicle" Script adapted by second_coming and DarthRogue to
  3.     Allow players to attach their explosive charges to any vehicle or lockable Epoch door.
  4.  
  5. */
  6. EtV_ChargeCheck =
  7. {
  8.    
  9.     _charge = _this select 0;
  10.     _unit = _this select 1;
  11.     _hasIt = _charge in (magazines _unit);
  12.     _nearVehs = nearestObjects [_unit,["Air","Ship","LandVehicle","PlotPole_EPOCH","CinderWallGarage_EPOCH","WoodLargeWallDoorL_EPOCH","WoodLargeWallDoor_EPOCH"],5];
  13.  
  14.     _return = (_hasIt && count _nearVehs > 0 && alive _unit  && !inSafeZone);
  15.     _return
  16. };
  17.  
  18. EtV_TouchOff =
  19. {
  20.     _array = _this select 3;
  21.     _unit = _array select 0;
  22.     _explosives = _unit getVariable ["charges",[]];
  23.     {
  24.         if(alive _x && !inSafeZone) then
  25.         {
  26.             _nearVehicle = (nearestObjects [_x,["Air","Ship","LandVehicle","PlotPole_EPOCH","CinderWallGarage_EPOCH","WoodLargeWallDoorL_EPOCH","WoodLargeWallDoor_EPOCH"],5]) select 0;
  27.             "HelicopterExploSmall" createVehicle (position _x);
  28.             deleteVehicle _x;
  29.             _existingDamage = damage _nearVehicle;
  30.             _nearVehicle setDamage _existingDamage + 0.34;
  31.             _destroyed = damage _nearvehicle > 0.99;
  32.             if (_destroyed) then
  33.                 {
  34.                     _nearVehicle call EPOCH_save_killedBuilding;
  35.                 };
  36.         };
  37.     } forEach _explosives;
  38.     _unit setVariable ["charges",[]];
  39.    
  40. };
  41.  
  42. EtV_UnitCheck =
  43. {
  44.     private "_return";
  45.     _unit = _this select 0;
  46.     _explosives = _unit getVariable ["charges",[]];
  47.     if(count _explosives > 0) then
  48.     {
  49.         _return = true;
  50.     }
  51.     else
  52.     {
  53.         _return = false;
  54.     };
  55.    
  56.     _return
  57. };
  58.  
  59. EtV_TimedCharge =
  60. {
  61.     _explosive = _this select 0;
  62.     _unit = _this select 1;
  63.     //_illogic = group server createUnit ["logic", Position _explosive, [], 0, "FORM"];
  64.     _grp = createGroup sidelogic;
  65.     _illogic = _grp createUnit ["logic", Position _explosive, [], 0, "FORM"];
  66.     [_illogic] join _grp;
  67.     _illogic attachTo [_explosive];
  68.     while {alive _explosive} do
  69.     {
  70.         waitUntil {!isNil {_illogic getVariable "timer"};};
  71.         if(_illogic getVariable "timer" == 0) exitWith
  72.         {
  73.             _charges = _unit getVariable ["charges",[]];
  74.             _unit setVariable ["charges",_charges - [_explosive]];
  75.             "HelicopterExploSmall" createVehicle (position _explosive);
  76.             deleteVehicle _explosive;
  77.         };
  78.         sleep 1;
  79.         _oldTime = _illogic getVariable "timer";
  80.         _illogic setVariable ["timer",_oldTime - 1];
  81.     };
  82. };
  83.  
  84. EtV_AttachCharge =
  85. {
  86.     _array = _this select 3;
  87.     _charge = _array select 0;
  88.     _unit = _array select 1;
  89.     private "_class";
  90.    
  91.     _unit removeMagazine _charge;
  92.     _unit playMove "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";
  93.    
  94.     switch _charge do
  95.     {
  96.         case "DemoCharge_Remote_Mag":
  97.         {
  98.             _class = "DemoCharge_Remote_Ammo";
  99.         };
  100.  
  101.  
  102.  
  103.  
  104.     };
  105.    
  106.     _nearVehicle = (nearestObjects [_unit,["Air","Ship","LandVehicle","PlotPole_EPOCH","CinderWallGarage_EPOCH","WoodLargeWallDoorL_EPOCH","WoodLargeWallDoor_EPOCH"],5]) select 0;
  107.     _explosive = _class createVehicle [0,0,0];
  108.     _explosive attachTo [_unit,[0,0,0],"leftHand"];
  109.     _random0 = random 180;
  110.     _random1 = random 180;
  111.     [_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
  112.     [_explosive,_nearVehicle,_unit,_random0,_random1] spawn
  113.     {      
  114.         _explosive = _this select 0;
  115.         _nearVehicle = _this select 1;
  116.         _unit = _this select 2;
  117.         _random0 = _this select 3;
  118.         _random1 = _this select 4;
  119.        
  120.         sleep 1.5;
  121.        
  122.         if ((typeOf _nearVehicle) in ["CinderWallGarage_EPOCH","PlotPole_EPOCH","WoodLargeWallDoorL_EPOCH","WoodLargeWallDoor_EPOCH"]) then
  123.         {
  124.             _explosive attachTo [_nearVehicle, [0,0,0.6]];
  125.         }
  126.         else
  127.         {
  128.             _explosive attachTo [_nearVehicle, [0,0,0.2]];
  129.         };  
  130.        
  131.         [_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
  132.         _unit setVariable ["charges",(_unit getVariable ["charges",[]]) + [_explosive]];
  133.         [_explosive,_unit] spawn EtV_TimedCharge;
  134.     };
  135. };
  136.  
  137. EtV_ClosestExplosive =
  138. {
  139.     _unit = _this select 0;
  140.     _charges = _unit getVariable ["charges",[]];
  141.     _newArray = [];
  142.     {_newArray = _newArray + [player distance _x];} forEach _charges;
  143.     _closest = _newArray call BIS_fnc_lowestNum;
  144.     _selection = _newArray find _closest;
  145.     _charge = _charges select _selection;
  146.     _charge
  147. };
  148.  
  149. EtV_Timer =
  150. {
  151.     private "_explosive";
  152.     _array = _this select 3;
  153.     _unit = _array select 0;
  154.     _explosive = [_unit] call EtV_ClosestExplosive;
  155.     _illogic = (nearestObjects [_explosive,["Logic"],50]) select 0;
  156.     if(!isNil "_illogic") then
  157.     {
  158.         _oldTime = _illogic getVariable ["timer",0];
  159.         _illogic setVariable ["timer",_oldTime + 30];
  160.         _newTime = _illogic getVariable "timer";
  161.         hint format ["Explosive timer set to %1 seconds.",_newTime];
  162.     };
  163. };
  164.  
  165. EtV_UnitCheckTimer =
  166. {
  167.     private "_return";
  168.     _unit = _this select 0;
  169.     _explosives = _unit getVariable ["charges",[]];
  170.     _return = false;
  171.     {if(_unit distance _x <= 5) exitWith {_return = true;};} forEach _explosives;
  172.     _return
  173. };
  174.  
  175. //[unit] spawn EtV_Actions;
  176. EtV_Actions =
  177. {
  178.     private ["_unit"];
  179.     _unit = _this select 0;
  180.  
  181.     _unit addAction ["<t color=""#FFE496"">" +"Attach Explosive Charge", EtV_AttachCharge, ["DemoCharge_Remote_Mag",_unit], 1, true, true, "","['DemoCharge_Remote_Mag',_target] call EtV_ChargeCheck"];
  182.     _unit addAction ["<t color=""#CC3300"">" +"Touch-Off Explosives", EtV_TouchOff, [_unit], 1, true, true, "","[_target] call EtV_UnitCheck"];
  183.     _unit addAction ["<t color=""#CC3300"">" +"+30Secs to Timer", EtV_Timer, [_unit], 1, true, true, "","[_target] call EtV_UnitCheckTimer"];
  184. };
  185.  
  186. //=======================
  187. EtVInitialized = true;
  188. [player] call EtV_Actions;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement