Advertisement
secondcoming

AutoLockPicker.sqf

May 16th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 13.43 KB | None | 0 0
  1. /*
  2.     AutoLockPicker
  3.     by second_coming
  4.     http://www.exilemod.com/profile/60-second_coming/
  5.    
  6.     Allow players to have a chance to lock pick any locked door or safe (also a chance to eloctrocute on failed unlocking!)
  7.    
  8.     Initial Script Code: Stealthstick's "Explosive-To-Vehicle" Script
  9.     Electrocution effect: http://www.altisliferpg.com/topic/224-effects-on-marijuana-use/
  10.  
  11.     */ 
  12.  
  13. // ======================================================================================================================================================================================
  14. // User configurable Variables
  15. // ======================================================================================================================================================================================
  16.  
  17. // Which locks can be opened
  18. LockpickLandVehicles                = false;                        // All land vehicles (cars, vans, trucks etc)   ::: acceptable values true or false
  19. LockpickAir                         = false;                    // Helis and jets                           ::: acceptable values true or false
  20. LockpickShip                        = false;                        // Boats, jetskis and submarines                ::: acceptable values true or false
  21. LockpickDoors                   = true;                     // Exile build-able doors                       ::: acceptable values true or false
  22. LockpickSafes                   = true;                     // Exile build-able doors                       ::: acceptable values true or false
  23. LockpickDistance                    = 2;                            // Maximum distance away from the object to unlock
  24.  
  25. // Chance to succeed or be electrocuted
  26. SuccessChance                   = 15;                       // (Between 1-100) % Chance to successfully pick the lock
  27. ElectrocuteChance               = 20;                       // (Between 1-100) % Chance of electrocution on if the lock pick fails
  28.  
  29. // Damage Settings
  30. InflictDamage                   = true;                     // If true damage is added, if false just stun     
  31. MinimumDamage                   = 50;                       // (Between 1-100) min% of full health Damage to inflict must be less than MaximumDamage
  32. MaximumDamage                   = 90;                       // (Between 1-100) max% of full health Damage to inflict must be more than MinimumDamage
  33. StunTime                        = 10;                       // Time in seconds to stun the player on electrocution (if it doesn't kill them)
  34.  
  35. // Materials Required to Create AutoLockPicker
  36. MaterialRequired1                   = 'Exile_Item_Laptop';          // First material required to create AutoLockPicker (default is 'CircuitParts' or Electronic Component)
  37. MaterialRequired1Count              = 1;
  38. MaterialRequired2                   = 'Exile_Item_ExtensionCord';   // Second material required to create AutoLockPicker (default is 'ItemCorrugated' or small metal parts)
  39. MaterialRequired2Count              = 2;
  40.  
  41. // Usage Restrictions
  42. AllowInSafeZone                 = false;                        // (Leave true if you don't use inSafezone) Allow use of AutoLockPicker in safezones
  43.                                                            
  44. _MinimumPlayers                     = 0;                            // Number of players required online before the option to lock pick becomes available (set to 0 to always allow)
  45. AllowLockPicksNear              = true;                     // (Leave true for no restriction) selecting false will make the script check if one has been placed within LockpickDistance m of the player
  46.  
  47. UnlockableItems = ["Exile_Construction_WoodDoor_Reinforced_Static","Exile_Construction_WoodDoor_Static","Exile_Construction_WoodGate_Reinforced_Static","Exile_Construction_WoodGate_Static","Land_City_Gate_F","Land_Stone_Gate_F"];
  48. // ======================================================================================================================================================================================
  49. // End of User configurable Variables
  50. // ======================================================================================================================================================================================
  51.  
  52. MISSION_ROOT = call
  53. {
  54.     private "_arr";
  55.     _arr = toArray __FILE__;
  56.     _arr resize (count _arr - 18);
  57.     toString _arr
  58. };
  59.  
  60. LockPickingInProgress = false;
  61.  
  62. if(AllowInSafeZone && count playableUnits >= _MinimumPlayers) then
  63. {
  64.     SafeToALP = true;
  65. }
  66. else
  67. {
  68.     if(!ExilePlayerInSafezone && count playableUnits >= _MinimumPlayers) then
  69.     {
  70.         SafeToALP = true;
  71.     }
  72.     else
  73.     {
  74.         SafeToALP = false; 
  75.     };
  76. };
  77.  
  78. LockPickableItems = [];
  79.  
  80. if(LockpickLandVehicles) then
  81. {
  82.     LockPickableItems = LockPickableItems + ["LandVehicle"];
  83. };
  84.  
  85. if(LockpickAir) then
  86. {
  87.     LockPickableItems = LockPickableItems + ["Air"];
  88. };
  89.  
  90. if(LockpickShip) then
  91. {
  92.     LockPickableItems = LockPickableItems + ["Ship"];
  93. };
  94.  
  95. if(LockpickDoors) then
  96. {
  97.    
  98.     LockPickableItems = LockPickableItems + UnlockableItems;
  99. };
  100.  
  101. if(LockpickSafes) then
  102. {
  103.    
  104.     LockPickableItems = LockPickableItems + ["Exile_Container_Safe"];
  105. };
  106.  
  107.  
  108.  
  109.  
  110. AutoLockPicker_MatsCheck =
  111. {
  112.     _charge1 = _this select 0;
  113.     _charge2 = _this select 1;
  114.     _unit = _this select 2;
  115.     _hasIt1 = _charge1 in (magazines _unit);
  116.     _hasIt1Count = {_x == _charge1} count magazines player;
  117.     _hasIt2 = _charge2 in (magazines _unit);
  118.     _hasIt2Count = {_x == _charge2} count magazines player;
  119.     _hasEnough = false;
  120.     if(_hasIt1Count >= MaterialRequired1Count && _hasIt2Count >= MaterialRequired2Count) then
  121.     {
  122.         _hasEnough = true;
  123.     };
  124.    
  125.     _CanPlace = false;
  126.     _nearALP = nearestObjects [_unit,["Land_PortableLongRangeRadio_F"],LockpickDistance];
  127.     if(AllowLockPicksNear || (count _nearALP == 0 && !AllowLockPicksNear)) then
  128.     {
  129.         _CanPlace = true;  
  130.     };
  131.  
  132.     _target = cursorTarget;
  133.     _LockPickable = false;
  134.     if ((typeOf cursorTarget) in LockPickableItems) then
  135.     {
  136.         _LockPickable = true;
  137.     }
  138.     else
  139.     {
  140.        
  141.         if  (_target isKindOf "LandVehicle" && LockpickLandVehicles) then
  142.         {
  143.             _LockPickable = true;
  144.         };
  145.         if  (_target isKindOf "Air" && LockpickAir) then
  146.         {
  147.             _LockPickable = true;
  148.         }; 
  149.         if  (_target isKindOf "Ship" && LockpickShip) then
  150.         {
  151.             _LockPickable = true;
  152.         };         
  153.     };
  154.    
  155.     _locked = 0;
  156.     _locked =  _target getVariable "ExileIsLocked";
  157.    
  158.     //hint format ["Target: %1 Lockpickable: %2 Locked: %3 Distance: %4",(typeOf cursorTarget),_LockPickable,locked cursorTarget,_unit distance cursorTarget];
  159.     _nearVehs = false;
  160.     if (_LockPickable && _unit distance _target < LockpickDistance) then
  161.     {
  162.         _nearVehs = true;
  163.     };
  164.    
  165.     _return = (_hasEnough && _nearVehs && alive _unit && SafeToALP && _CanPlace && _locked == -1 && !LockPickingInProgress);
  166.     _return
  167. };
  168.  
  169. AutoLockPicker_Countdown = { [ format["<t size='0.70' color='#00FFFF'>%1</t>",_this], 0,1,5,0,0,301] spawn bis_fnc_dynamicText; };
  170.  
  171. AutoLockPicker_Activate =
  172. {
  173.     _unit = _this select 0;
  174.     LockPickingInProgress = true;
  175.     _lockpicks = _unit getVariable ["lockpicks",[]];
  176.     {
  177.         //systemchat format["Lockpick: %1",_x];
  178.         if(alive _x && SafeToALP) then
  179.         {
  180.             _time = 30;
  181.             _attemptFinished = false;
  182.             _nearVehicle = (nearestObjects [_x,LockPickableItems,LockpickDistance]) select 0;
  183.             player playActionNow "medicStart";
  184.             removeAllActions player;
  185.             while {alive player and (player distance _nearVehicle) < LockpickDistance and (_time > 0) and !_attemptFinished} do
  186.             {      
  187.                 if!(["medic",animationState player] call BIS_fnc_inString) then
  188.                 {
  189.                     player playActionNow "medicStart";
  190.                 }; 
  191.                 (format["time remaining %1 sec", _time] ) call AutoLockPicker_Countdown;
  192.                 if (_time <= 0.1) then { ("") call AutoLockPicker_Countdown; _attemptFinished = true; player playActionNow "medicstop"; };
  193.                 _time = _time - 1;
  194.                 if(_time > 1) then { sleep 1; };       
  195.             };
  196.             ("") call AutoLockPicker_Countdown;
  197.             [player] call AutoLockPicker_Actions;
  198.             // Chance to unlock
  199.             _chance = Ceil random 100;         
  200.             if(_chance <= SuccessChance) then{
  201.                 // Unlock the door or vehicle
  202.                 //player switchMove "";
  203.                 _nearVehicle = (nearestObjects [_x,LockPickableItems,LockpickDistance]) select 0;
  204.                 deleteVehicle _x;
  205.  
  206.                 ALPUNLOCK = [_nearVehicle];
  207.                 uiSleep 0.2;
  208.                 publicVariableServer "ALPUNLOCK";
  209.                 uiSleep 0.2;
  210.                
  211.                 if ((typeOf _nearVehicle) in UnlockableItems) then
  212.                 {
  213.                     ["Success", "The AutoLockPicker worked! Opening door"] call ExileClient_gui_notification_event_addNotification;
  214.                     _nearVehicle setVariable ["ExileIsLocked", 0, true];
  215.                     _nearVehicle lock 0;
  216.                 }
  217.                 else
  218.                 {
  219.                     ["Success", "The AutoLockPicker worked! Unlocking Safe"] call ExileClient_gui_notification_event_addNotification;
  220.                     _nearVehicle setVariable ["ExileIsLocked", 0, true];
  221.                     _nearVehicle lock 0;                   
  222.                 }
  223.             }
  224.             else
  225.             {
  226.                 //_unit switchMove "";
  227.                 _chance2 = Ceil random 100;
  228.                 if(_chance2 <= ElectrocuteChance) then
  229.                 {
  230.                     // Chance of electrocution
  231.                     _DamagetoInflict = (Ceil random (MaximumDamage - MinimumDamage))/100;                  
  232.                     _damage = Damage player;
  233.                     _damage = _damage + (MinimumDamage/100) + _DamagetoInflict;                            
  234.                     playSound3D [MISSION_ROOT + "electrocute.ogg", player, false, getPosASL player, 1, 1, 0];
  235.                     if(_damage > 1 && InflictDamage) then
  236.                     {
  237.                         ["RestartWarning", "The AutoLockPicker malfunctioned and electrocuted you"] call ExileClient_gui_notification_event_addNotification;
  238.                         systemChat "The AutoLockPicker malfunctioned and electrocuted you";
  239.                         player setDamage 1;
  240.                         ExileClientPlayerAttributes set [0, 0];
  241.                         // Activate ppEffects
  242.                         "chromAberration" ppEffectEnable true;
  243.                         "radialBlur" ppEffectEnable true;
  244.                         enableCamShake true;
  245.  
  246.                         // 5secs of effects
  247.                         for "_i" from 0 to 4 do
  248.                         {
  249.                             "chromAberration" ppEffectAdjust [random 0.25,random 0.25,true];
  250.                             "chromAberration" ppEffectCommit 1;  
  251.                             "radialBlur" ppEffectAdjust  [random 0.02,random 0.02,0.15,0.15];
  252.                             "radialBlur" ppEffectCommit 1;
  253.                             addcamShake[random 3, 1, random 3];
  254.                             uiSleep 1;
  255.                         };
  256.  
  257.                         //Stop effects
  258.                         "chromAberration" ppEffectAdjust [0,0,true];
  259.                         "chromAberration" ppEffectCommit 5;
  260.                         "radialBlur" ppEffectAdjust  [0,0,0,0];
  261.                         "radialBlur" ppEffectCommit 5;
  262.                         uiSleep 6;
  263.  
  264.                         //Deactivate ppEffects
  265.                         "chromAberration" ppEffectEnable false;
  266.                         "radialBlur" ppEffectEnable false;
  267.                         resetCamShake; 
  268.                     }
  269.                     else
  270.                     {
  271.                         ["RestartWarning", "The AutoLockPicker malfunctioned and gave you an electric shock"] call ExileClient_gui_notification_event_addNotification;                                     
  272.                         systemChat "The AutoLockPicker malfunctioned and gave you an electric shock";
  273.                         if(InflictDamage) then
  274.                         {
  275.                             player setDamage _damage;
  276.                             ExileClientPlayerAttributes set [0, (1 - _damage) * 100];
  277.                         };
  278.                                                
  279.                         player playActionNow "GestureSpasm0";
  280.  
  281.                         // Activate ppEffects
  282.                         "chromAberration" ppEffectEnable true;
  283.                         "radialBlur" ppEffectEnable true;
  284.                         enableCamShake true;
  285.  
  286.                         uiSleep 1;
  287.                        
  288.                         // Stop the player from moving while shocked
  289.                         player enablesimulation false;
  290.                        
  291.                         // StunTime seconds of effects
  292.                         for "_i" from 0 to StunTime do
  293.                         {
  294.                             "chromAberration" ppEffectAdjust [random 0.25,random 0.25,true];
  295.                             "chromAberration" ppEffectCommit 1;  
  296.                             "radialBlur" ppEffectAdjust  [random 0.02,random 0.02,0.15,0.15];
  297.                             "radialBlur" ppEffectCommit 1;
  298.                             addcamShake[random 5, 1, random 5];
  299.                             uiSleep 1;
  300.                         };
  301.  
  302.                         player enablesimulation true;
  303.                        
  304.                         //Stop effects
  305.                         "chromAberration" ppEffectAdjust [0,0,true];
  306.                         "chromAberration" ppEffectCommit 5;
  307.                         "radialBlur" ppEffectAdjust  [0,0,0,0];
  308.                         "radialBlur" ppEffectCommit 5;
  309.                         uiSleep 3;
  310.                         player playActionNow "PlayerStand";
  311.                         //Deactivate ppEffects
  312.                         "chromAberration" ppEffectEnable false;
  313.                         "radialBlur" ppEffectEnable false;
  314.                         resetCamShake;
  315.    
  316.                     };                 
  317.                     deleteVehicle _x;  
  318.                     LockPickingInProgress = false;                 
  319.                 }
  320.                 else
  321.                 {
  322.                     ["RestartWarning", "The AutoLockPicker failed to unlock the door, try again"] call ExileClient_gui_notification_event_addNotification;
  323.                     deleteVehicle _x;
  324.                 }
  325.             };
  326.         };
  327.     } forEach _lockpicks;
  328.     _unit setVariable ["lockpicks",[]];
  329. };
  330.  
  331. AutoLockPicker_AttachALP =
  332. {
  333.     _array = _this select 3;
  334.     _charge = _array select 0;
  335.     _unit = _array select 1;
  336.     private "_class";
  337.    
  338.     for "_i" from 1 to MaterialRequired2Count step 1 do
  339.     {
  340.         _unit removemagazine MaterialRequired2;
  341.         uiSleep 0.1;
  342.     };
  343.     _unit setUnitPos "MIDDLE";
  344.  
  345.     switch _charge do
  346.     {
  347.         case "Land_PortableLongRangeRadio_F":
  348.         {
  349.             _class = "Land_PortableLongRangeRadio_F";
  350.         };
  351.     };
  352.    
  353.     _nearVehicle = (nearestObjects [_unit,LockPickableItems,LockpickDistance]) select 0;
  354.     _autolockpick = _class createVehicle [0,0,0];
  355.     _autolockpick attachTo [_unit,[0,0,0],"leftHand"];
  356.     _random0 = random 180;
  357.     _random1 = random 180;
  358.     [_autolockpick,_random0,_random1] call BIS_fnc_SetPitchBank;
  359.     [_autolockpick,_nearVehicle,_unit,_random0,_random1] spawn
  360.     {      
  361.         _autolockpick = _this select 0;
  362.         _nearVehicle = _this select 1;
  363.         _unit = _this select 2;
  364.         _random0 = _this select 3;
  365.         _random1 = _this select 4;
  366.        
  367.         _autolockpick attachTo [_nearVehicle, [0,0,0.2]];
  368.         [_autolockpick,_random0,_random1] call BIS_fnc_SetPitchBank;
  369.         _unit setVariable ["lockpicks",(_unit getVariable ["lockpicks",[]]) + [_autolockpick]];
  370.         uiSleep 8;
  371.     };
  372.     uiSleep 1;
  373.     [_unit] call AutoLockPicker_Activate;
  374. };
  375.  
  376.  
  377. AutoLockPicker_Actions =
  378. {
  379.     private ["_unit"];
  380.     _unit = _this select 0;
  381.     _unit addAction ["<t color=""#0099FF"">" +"Use AutoLockPicker", AutoLockPicker_AttachALP, ["Land_PortableLongRangeRadio_F",_unit], 1, true, true, "","[MaterialRequired1,MaterialRequired2,_target] call AutoLockPicker_MatsCheck"];
  382.     //_unit addAction ["<t color=""#3D993D"">" +"Activate AutoLockPicker", AutoLockPicker_Activate, [_unit], 1, true, true, "","[_target] call AutoLockPicker_UnitCheck"];
  383. };
  384.  
  385. //removeAllActions player;
  386. //=======================
  387. [player] call AutoLockPicker_Actions;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement