Advertisement
pit_ESUS

Untitled

Mar 24th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 9.38 KB | None | 0 0
  1. // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
  2. // Mine Detector Script
  3. // Version alpha 0.62
  4. // Date: 2015.11.19
  5. // Author: Lala14
  6. // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
  7.  
  8. // init line:
  9. // null = [] execVM "minedetector.sqf";
  10. /*Definable Start*/
  11. if (isNil "MDMineDetectorAction") then {
  12. MDMineDetectorAction = 1; //1 means player has to use an addaction to use the minedetector otherwise it won't work, 0 = player doesnt need an addaction and it is always on
  13. };
  14. if (isNil "MDMineDetectorWalkOnly") then {
  15. MDMineDetectorWalkOnly = 1; //Requires MDMineDetectorAction = 1, Forces when the addAction is on that the player will be forced to work (if is already forced walk then the action will not un force walk the player)
  16. };
  17. if (isNil "MDMineDetectorVisualiseDetector") then {
  18. MDMineDetectorVisualiseDetector = 1; //Requires MDMineDetectorAction =1, Makes the player hold a minedetector when using it
  19. };
  20. if (isNil "MDMineDetectorDistance") then {
  21. MDMineDetectorDistance = 40; //The distance at which the detector will detect mines
  22. };
  23. /*Definable End*/
  24. waitUntil {!isNull player};
  25.  
  26. // config [ ["kindOf AMMO classnames",pitch multiplier(noise),distance multiplier (noise),"kindOf cfgVehicles classnames"] ]
  27. if (isNil "MDLala_Config") then { MDLala_Config = [] };
  28. MDLala_Config = MDLala_Config + [
  29.     ["SafeGaurdForMods",14,5,"Unknown"],
  30.     ["ATMine_Range_Ammo",14,5,"ATMine"],
  31.     ["APERSMine_Range_Ammo",14,5,"APERSMine"],
  32.     ["APERSTripMine_Wire_Ammo",14,5,"APERSTripMine"],
  33.     ["APERSBoundingMine_Range_Ammo",9,10,"APERSBoundingMine"],
  34.     ["SLAMDirectionalMine_Wire_Ammo",14,5,"SLAMDirectionalMine"],
  35.     ["ClaymoreDirectionalMine_Remote_Ammo",14,5,"Claymore_F"],
  36.     ["DemoCharge_Remote_Ammo",14,5,"DemoCharge_F"],
  37.     ["SatchelCharge_Remote_Ammo",14,5,"SatchelCharge_F"],
  38.     ["UnderwaterMine_Range_Ammo",14,5,"UnderwaterMine"],
  39.     ["UnderwaterMineAB_Range_Ammo",14,5,"UnderwaterMineAB"],
  40.     ["UnderwaterMinePDM_Range_Ammo",14,5,"UnderwaterMinePDM"],
  41.     ["IEDUrbanSmall_Remote_Ammo",14,5,"IEDUrbanSmall_F"],
  42.     ["IEDLandSmall_Remote_Ammo",14,5,"IEDLandSmall_F"],
  43.     ["IEDUrbanBig_Remote_Ammo",14,5,"IEDUrbanBig_F"],
  44.     ["IEDLandBig_Remote_Ammo",14,5,"IEDLandBig_F"]
  45. ];
  46.  
  47. MDLALA_fnc_in_List = {
  48.     private ["_indexno"];
  49.     _indexno = 0;
  50.  
  51.     {
  52.         if ((_x select 0) isEqualTo _this) then
  53.         {
  54.             _indexno = _forEachIndex;
  55.         };
  56.     }forEach MDLala_Config;
  57.     _indexno
  58. };
  59.  
  60. MDLALA_fnc_Condition_Detect = {
  61.     private ["_unit","_mine"];
  62.     _unit = _this select 0;
  63.     if ((isNil "_unit") OR (isNull _unit)) exitWith {[]};
  64.     _mine = [];
  65.  
  66.     //nearestObjects [_unit, ["MineBase","MineGeneric"],10]; <--- not working :D
  67.     //"ATMine","APERSMine","APERSTripMine","APERSBoundingMine","SLAMDirectionalMine","Claymore_F","DemoCharge_F","SatchelCharge_F","UnderwaterMine","UnderwaterMineAB","UnderwaterMinePDM","IEDUrbanSmall_F","IEDLandSmall_F","IEDUrbanBig_F","IEDLandBig_F"
  68.     if (nearestObject [_unit, "TimeBombCore"] distance _unit < nearestObject [_unit, "MineBase"] distance _unit) then {_mine = [nearestObject [_unit, "TimeBombCore"]];};
  69.     if (nearestObject [_unit, "TimeBombCore"] distance _unit > nearestObject [_unit, "MineBase"] distance _unit) then {_mine = [nearestObject [_unit, "MineBase"]];};
  70.  
  71.     if (count _mine == 0 OR _mine select 0 distance _unit > MDMineDetectorDistance) then {_mine = _unit nearObjects ["TimeBombCore", MDMineDetectorDistance];}; //these are innaccurate but may prove worthy
  72.     if (count _mine == 0 OR _mine select 0 distance _unit > MDMineDetectorDistance) then {_mine = _unit nearObjects ["MineBase", MDMineDetectorDistance];}; //these are innaccurate but may prove worthy
  73.     if (typeof (nearestObject [_unit, "TimeBombCore"]) == "APERSBoundingMine_Range_Ammo" && _unit distance (nearestObject [_unit, "TimeBombCore"]) < 6) then {_mine = [nearestObject [_unit, "TimeBombCore"]]}; //override for this mine since it's set off radius is 5m
  74.     _mine;
  75. };
  76.  
  77. MDLALA_fnc_Mine_Noise = {
  78.     private ["_unit","_missiondir","_timesleep","_pitch","_minedo"];
  79.     _unit = _this select 0;
  80.     if (!(alive _unit) OR (isNull _unit)) exitWith {};
  81.     _action = _this select 1;
  82.     if (count _this < 2) then {_action = false;};
  83.     _missiondir = call { private "_arr"; _arr = toArray str missionConfigFile; _arr resize (count _arr - 15); toString _arr };
  84.     _timesleep = 5;
  85.     _pitch = 5;
  86.  
  87.  
  88.     waitUntil{if (!alive _unit) exitWith {true}; ("MineDetector" in items _unit) && (count ([_unit] call MDLALA_fnc_Condition_Detect) > 0)};
  89.  
  90.     if (!alive _unit) exitWith {};
  91.  
  92.     while {((([_unit] call MDLALA_fnc_Condition_Detect select 0) distance _unit) < MDMineDetectorDistance) && (alive _unit)} do
  93.     {
  94.         if (!("MineDetector" in items _unit) OR (vehicle _unit != _unit) OR !(alive _unit)) exitWith {};
  95.         _minetype = typeOf ([_unit] call MDLALA_fnc_Condition_Detect select 0);
  96.         _minename = getText (configFile >> "cfgVehicles" >> (MDLala_Config select (_minetype call MDLALA_fnc_in_List) select 3) >> "displayName");
  97.         _distance = ([_unit] call MDLALA_fnc_Condition_Detect select 0) distance _unit;
  98.  
  99.         _pitch = (MDLala_Config select (_minetype call MDLALA_fnc_in_List) select 1) - _distance;
  100.         _timesleep = (_distance / (MDLala_Config select (_minetype call MDLALA_fnc_in_List) select 2));
  101.  
  102.         //hintSilent format ["Mine = %4\nDistance = %1\nTime Until Next Beep =  %2\nPitch = %3",_distance,_timesleep,_pitch,_minename];
  103.         playSound3D ["A3\UI_F\data\sound\CfgNotifications\addItemOk.wss",_unit,false,[getPosASL _unit select 0,getPosASL _unit select 1,(getPosASL _unit select 2) + 1],100,_pitch,5];
  104.         //playSound3D [_missiondir + "beep.wav",_unit,false,[getPosASL _unit select 0,getPosASL _unit select 1,(getPosASL _unit select 2) + 1],100,_pitch,5];
  105.         //playSound3D ["A3\Sounds_F\sfx\hint-3.wss",_unit,false,[getPosASL _unit select 0,getPosASL _unit select 1,(getPosASL _unit select 2) + 1],100,_pitch,5];
  106.         //playSound3D ["A3\missions_F\data\sounds\click.wss",_unit,false,[getPosASL _unit select 0,getPosASL _unit select 1,(getPosASL _unit select 2) + 1],100,_pitch,5];
  107.         //playSound3D ["A3\missions_F\data\sounds\click.wss",_unit,false,getPosASL ([_unit] call MDLALA_fnc_Condition_Detect select 0),100,5,5];
  108.         //playSound3D [_missiondir + "Beep.ogg",_unit,false,getPosASL _unit,100,2,10];
  109.         sleep _timesleep;
  110.     };
  111.  
  112.     if (!alive _unit) exitWith {};
  113.  
  114.     if (_action) then
  115.     {
  116.         _minedo = [_unit,true,(_this select 2)] spawn MDLALA_fnc_Mine_Noise;
  117.         _unit setVariable ["MineDetectorStart",_minedo,true];
  118.     } else {
  119.         [_unit] spawn MDLALA_fnc_Mine_Noise;
  120.     };
  121. };
  122.  
  123. MDLALA_fnc_returnAttachedObjects = {
  124.     private ["_array","_item"];
  125.     _array = _this select 0;
  126.     _item = _this select 1;
  127.     _found = false;
  128.  
  129.     {
  130.         if (_item == typeOf _x) exitWith {_found = true};
  131.     }forEach _array;
  132.     _found;
  133. };
  134.  
  135. MDLALA_fnc_visualMineDetector = {
  136.     private ["_unit","_visualiseDetector"];
  137.     _unit = _this select 0;
  138.  
  139.     if ([attachedObjects _unit,"Item_MineDetector"] call MDLALA_fnc_returnAttachedObjects) exitWith {};
  140.  
  141.     _unit switchMove "AmovPercMstpSrasWrflDnon_AmovPercMstpSrasWpstDnon_end";
  142.     _visualiseDetector = createVehicle ["Item_MineDetector", (getPosATL _unit), [], 0, "NONE"];
  143.     _visualiseDetector attachTo [_unit, [0.01, 0, 0.6], "LeftHandMiddle1"];
  144.     waitUntil {isNil {_unit getVariable "MineDetectorStart"}};
  145.     deleteVehicle _visualiseDetector;
  146.     _unit switchMove "AmovPercMstpSrasWrflDnon_AmovPercMstpSrasWpstDnon_end";
  147. };
  148.  
  149. MDLALA_fnc_MineDetector_selectAction = {
  150.     private ["_walkingalready","_unit","_action","_actionid","_minedo"];
  151.     _unit = _this select 0;
  152.     _action = _this select 1;
  153.     _actionid = _this select 2;
  154.     _walkingalready = _unit getVariable ["MineDetectorWalk",false];
  155.  
  156.     if (isForcedWalk _unit && !_walkingalready) then {_unit setVariable ["MineDetectorWalking",isForcedWalk _unit,true];};
  157.  
  158.     if (_action && !_walkingalready) then {
  159.         _unit setUserActionText [_actionid,"<t color='#FF0000'>Stop MineDetector</t>"];
  160.         if (MDMineDetectorWalkOnly == 1) then {
  161.             _unit forceWalk true;
  162.         };
  163.         _unit setVariable ["MineDetectorWalk",true,true];
  164.         _minedo = [_unit,true,_actionid] spawn MDLALA_fnc_Mine_Noise;
  165.         _unit setVariable ["MineDetectorStart",_minedo,true];
  166.         if (MDMineDetectorVisualiseDetector == 1) then {
  167.             [_unit] spawn MDLALA_fnc_visualMineDetector;
  168.         };
  169.     } else {
  170.     _unit setUserActionText [_actionid,"<t color='#FF0000'>Use MineDetector</t>"];
  171.         if (isNil {_unit getVariable "MineDetectorWalking"}) then {
  172.             _unit forceWalk false;
  173.         };
  174.     _unit setVariable ["MineDetectorWalk",false,true];
  175.     _unit setVariable ["MineDetectorWalking",nil,true];
  176.     terminate (_unit getVariable "MineDetectorStart");
  177.     _unit setVariable ["MineDetectorStart",nil,true];
  178.     };
  179. };
  180.  
  181. MDLALA_fnc_MineDetector_addAction = {
  182.     private ["_unit"];
  183.     _unit = _this select 0;
  184.     if (isNil {_unit getVariable "MDMineDetectorActions"}) then {
  185.         _unit addAction ["<t color='#FF0000'>Use MineDetector</t>",{[(_this select 0),true,(_this select 2)] spawn MDLALA_fnc_MineDetector_selectAction;}, [], 0, false, true, "", '"MineDetector" in items _target'];
  186.         _unit setVariable ["MDMineDetectorActions",true,true]
  187.     };
  188. };
  189.  
  190. sleep 0.1;
  191. if (MDMineDetectorAction isEqualTo 1) then
  192. {
  193.     [player] spawn MDLALA_fnc_MineDetector_addAction;
  194.     player addEventHandler ["Respawn",{ (_this select 0) setVariable ["MDMineDetectorActions",nil,true]; [(_this select 0)] spawn MDLALA_fnc_MineDetector_addAction; }];
  195. } else {
  196.     [player] spawn MDLALA_fnc_Mine_Noise;
  197.     player addEventHandler ["Respawn",{ [(_this select 0)] spawn MDLALA_fnc_Mine_Noise;} ];
  198. };
  199. systemChat "Mine Detector: Initialized";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement