magclamp.sqf 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "\a3\editor_f\Data\Scripts\dikCodes.h"
  2. #include "../../config_macros.hpp"
  3. macro_grp_fnc_name(magclamp,handle_universal) = {
  4. params ["_mc_pos", "_attached_var", "_forbid_param", "_offset_param"];
  5. _vehicle = vehicle player;
  6. if (isNull _vehicle) exitWith {};
  7. _position = (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> _mc_pos) call BIS_fnc_getCfgDataArray;
  8. if (count _position == 0) exitWith {};
  9. _attached = _vehicle getVariable[_attached_var,objNull];
  10. if(isNull _attached) then {
  11. _objects = nearestObjects [player, ["Car","Tank","Motorcycle","StaticWeapon","Air","Ship","Object"], 20];
  12. _target_index = 0;
  13. _target = _objects select _target_index;
  14. _is_attached = _target getVariable["RD501_mc_is_attached",false];
  15. _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
  16. while {_target isKindOf "Man" || isPlayer _target || _is_attached || _cant_be_clamped} do {
  17. _target_index = _target_index + 1;
  18. _target = _objects select _target_index;
  19. _is_attached = _target getVariable["RD501_mc_is_attached",false];
  20. _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
  21. };
  22. _offset = (configFile >> "CfgVehicles" >> (typeOf _target) >> _offset_param) call BIS_fnc_getCfgDataArray;
  23. if (count _offset == 3) then {
  24. _position = [(_position select 0) + (_offset select 0), (_position select 1) + (_offset select 1), (_position select 2) + (_offset select 2)];
  25. };
  26. _target attachTo [_vehicle, _position];
  27. _vehicle setVariable[_attached_var,_target,true];
  28. _target setVariable["RD501_mc_is_attached",true,true];
  29. } else {
  30. detach _attached;
  31. _vehicle setVariable[_attached_var,objNull,true];
  32. _attached setVariable["RD501_mc_is_attached",false,true];
  33. };
  34. };
  35. macro_grp_fnc_name(magclamp,handle_small_1_pressed) = {
  36. systemChat "left clamp";
  37. if(isNull vehicle player) exitWith {};
  38. ["RD501_magclamp_small_1",
  39. "RD501_mc_attached_small_1",
  40. "RD501_magclamp_small_forbidden",
  41. "RD501_magclamp_small_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  42. };
  43. macro_grp_fnc_name(magclamp,handle_large_pressed) = {
  44. systemChat "center clamp";
  45. if(isNull vehicle player) exitWith {};
  46. ["RD501_magclamp_large",
  47. "RD501_mc_attached_large",
  48. "RD501_magclamp_large_forbidden",
  49. "RD501_magclamp_large_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  50. };
  51. macro_grp_fnc_name(magclamp,handle_small_2_pressed) = {
  52. systemChat "right clamp";
  53. if(isNull vehicle player) exitWith {};
  54. ["RD501_magclamp_small_2",
  55. "RD501_mc_attached_small_2",
  56. "RD501_magclamp_small_forbidden",
  57. "RD501_magclamp_small_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  58. };
  59. macro_grp_fnc_name(magclamp,handle_drop_all) = {
  60. systemChat "drop all";
  61. if(isNull vehicle player) exitWith {};
  62. _vehicle = vehicle player;
  63. _attached = _vehicle getVariable["RD501_mc_attached_small_1",objNull];
  64. if(isNull _attached) then {} else {
  65. detach _attached;
  66. _vehicle setVariable["RD501_mc_attached_small_1",objNull,true];
  67. _attached setVariable["RD501_mc_is_attached",false,true];
  68. };
  69. _attached = _vehicle getVariable["RD501_mc_attached_large",objNull];
  70. if(isNull _attached) then {} else {
  71. detach _attached;
  72. _vehicle setVariable["RD501_mc_attached_large",objNull,true];
  73. _attached setVariable["RD501_mc_is_attached",false,true];
  74. };
  75. _attached = _vehicle getVariable["RD501_mc_attached_small_2",objNull];
  76. if(isNull _attached) then {} else {
  77. detach _attached;
  78. _vehicle setVariable["RD501_mc_attached_small_2",objNull,true];
  79. _attached setVariable["RD501_mc_is_attached",false,true];
  80. };
  81. };
  82. //add keybinds
  83. ["RD501 Magclamp","small_1",["First Small Clamp (Laat/I, Laat/C Left)","Activate/Deactivate left Magclamp on Laat/C or main Magclamp on Laat/I"],{
  84. [player] call macro_grp_fnc_name(magclamp,handle_small_1_pressed);
  85. },"",[DIK_7,[false,false,false]],false] call cba_fnc_addKeybind;
  86. ["RD501 Magclamp","large",["Large Clamp (Laat/C Center)","Activate/Deactivate center Magclamp on Laat/C"],{
  87. [player] call macro_grp_fnc_name(magclamp,handle_large_pressed);
  88. },"",[DIK_8,[false,false,false]],false] call cba_fnc_addKeybind;
  89. ["RD501 Magclamp","small_2",["Second Small Clamp (Laat/C Right)","Activate/Deactivate right Magclamp on Laat/C"],{
  90. [player] call macro_grp_fnc_name(magclamp,handle_small_2_pressed);
  91. },"",[DIK_9,[false,false,false]],false] call cba_fnc_addKeybind;
  92. ["RD501 Magclamp","detach_all",["Detach All","Detach all clamped vehicles"],{
  93. [player] call macro_grp_fnc_name(magclamp,handle_drop_all);
  94. },"",[DIK_0,[false,false,false]],false] call cba_fnc_addKeybind;