magclamp.sqf 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if(isNull vehicle player) exitWith {};
  37. ["RD501_magclamp_small_1",
  38. "RD501_mc_attached_small_1",
  39. "RD501_magclamp_small_forbidden",
  40. "RD501_magclamp_small_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  41. };
  42. macro_grp_fnc_name(magclamp,handle_large_pressed) = {
  43. if(isNull vehicle player) exitWith {};
  44. ["RD501_magclamp_large",
  45. "RD501_mc_attached_large",
  46. "RD501_magclamp_large_forbidden",
  47. "RD501_magclamp_large_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  48. };
  49. macro_grp_fnc_name(magclamp,handle_small_2_pressed) = {
  50. if(isNull vehicle player) exitWith {};
  51. ["RD501_magclamp_small_2",
  52. "RD501_mc_attached_small_2",
  53. "RD501_magclamp_small_forbidden",
  54. "RD501_magclamp_small_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  55. };
  56. macro_grp_fnc_name(magclamp,handle_drop_all) = {
  57. if(isNull vehicle player) exitWith {};
  58. _vehicle = vehicle player;
  59. _attached = _vehicle getVariable["RD501_mc_attached_small_1",objNull];
  60. if(isNull _attached) then {} else {
  61. detach _attached;
  62. _vehicle setVariable["RD501_mc_attached_small_1",objNull,true];
  63. _attached setVariable["RD501_mc_is_attached",false,true];
  64. };
  65. _attached = _vehicle getVariable["RD501_mc_attached_large",objNull];
  66. if(isNull _attached) then {} else {
  67. detach _attached;
  68. _vehicle setVariable["RD501_mc_attached_large",objNull,true];
  69. _attached setVariable["RD501_mc_is_attached",false,true];
  70. };
  71. _attached = _vehicle getVariable["RD501_mc_attached_small_2",objNull];
  72. if(isNull _attached) then {} else {
  73. detach _attached;
  74. _vehicle setVariable["RD501_mc_attached_small_2",objNull,true];
  75. _attached setVariable["RD501_mc_is_attached",false,true];
  76. };
  77. };
  78. //add keybinds
  79. ["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"],{
  80. [player] call macro_grp_fnc_name(magclamp,handle_small_1_pressed);
  81. },"",[DIK_7,[false,false,false]],false] call cba_fnc_addKeybind;
  82. ["RD501 Magclamp","large",["Large Clamp (Laat/C Center)","Activate/Deactivate center Magclamp on Laat/C"],{
  83. [player] call macro_grp_fnc_name(magclamp,handle_large_pressed);
  84. },"",[DIK_8,[false,false,false]],false] call cba_fnc_addKeybind;
  85. ["RD501 Magclamp","small_2",["Second Small Clamp (Laat/C Right)","Activate/Deactivate right Magclamp on Laat/C"],{
  86. [player] call macro_grp_fnc_name(magclamp,handle_small_2_pressed);
  87. },"",[DIK_9,[false,false,false]],false] call cba_fnc_addKeybind;
  88. ["RD501 Magclamp","detach_all",["Detach All","Detach all clamped vehicles"],{
  89. [player] call macro_grp_fnc_name(magclamp,handle_drop_all);
  90. },"",[DIK_0,[false,false,false]],false] call cba_fnc_addKeybind;