magclamp.sqf 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if (isNull objectParent player) exitWith {};
  6. private _vehicle = vehicle player;
  7. if !((driver _vehicle) == player or (gunner _vehicle) == player) exitWith {};
  8. private _position = (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> _mc_pos) call BIS_fnc_getCfgDataArray;
  9. if (count _position == 0) exitWith {};
  10. private _attached = _vehicle getVariable[_attached_var,objNull];
  11. if(isNull _attached) then {
  12. private _objects = nearestObjects [player, ["Car","Tank","Motorcycle","StaticWeapon","Air","Ship","Object","Thing"], 20];
  13. private _target_index = 0;
  14. private _target = _objects select _target_index;
  15. private _is_attached = _target getVariable["RD501_mc_is_attached",false];
  16. private _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
  17. while {_target == _vehicle || _target isKindOf "Man" || _is_attached || _cant_be_clamped} do {
  18. _target_index = _target_index + 1;
  19. _target = _objects select _target_index;
  20. _is_attached = _target getVariable["RD501_mc_is_attached",false];
  21. _cant_be_clamped = (configFile >> "CfgVehicles" >> (typeOf _target) >> _forbid_param) call BIS_fnc_getCfgDataBool;
  22. };
  23. if (isNull _target) exitWith {};
  24. private _offset = (configFile >> "CfgVehicles" >> (typeOf _target) >> _offset_param) call BIS_fnc_getCfgDataArray;
  25. if (count _offset == 3) then {
  26. _position = [(_position select 0) + (_offset select 0), (_position select 1) + (_offset select 1), (_position select 2) + (_offset select 2)];
  27. };
  28. _target attachTo [_vehicle, _position];
  29. _vehicle setVariable[_attached_var,_target,true];
  30. _target setVariable["RD501_mc_is_attached",true,true];
  31. } else {
  32. detach _attached;
  33. _vehicle setVariable[_attached_var,objNull,true];
  34. if (_mc_pos == "RD501_magclamp_large") then
  35. {
  36. _vehicle setVariable["RD501_mc_stop_refuel",true,true];
  37. };
  38. _attached setVariable["RD501_mc_is_attached",false,true];
  39. };
  40. };
  41. macro_grp_fnc_name(magclamp,handle_small_1_pressed) = {
  42. ["RD501_magclamp_small_1",
  43. "RD501_mc_attached_small_1",
  44. "RD501_magclamp_small_forbidden",
  45. "RD501_magclamp_small_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  46. };
  47. macro_grp_fnc_name(magclamp,handle_large_pressed) = {
  48. ["RD501_magclamp_large",
  49. "RD501_mc_attached_large",
  50. "RD501_magclamp_large_forbidden",
  51. "RD501_magclamp_large_offset"] call macro_grp_fnc_name(magclamp,handle_universal);
  52. };
  53. macro_grp_fnc_name(magclamp,handle_small_2_pressed) = {
  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. if (isNull objectParent player) exitWith {};
  61. private _vehicle = vehicle player;
  62. if !((driver _vehicle) == player or (gunner _vehicle) == player) exitWith {};
  63. private _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_stop_refuel",true,true];
  73. _vehicle setVariable["RD501_mc_attached_large",objNull,true];
  74. _attached setVariable["RD501_mc_is_attached",false,true];
  75. };
  76. _attached = _vehicle getVariable["RD501_mc_attached_small_2",objNull];
  77. if(isNull _attached) then {} else {
  78. detach _attached;
  79. _vehicle setVariable["RD501_mc_attached_small_2",objNull,true];
  80. _attached setVariable["RD501_mc_is_attached",false,true];
  81. };
  82. };
  83. // add keybinds
  84. ["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"],{
  85. [player] call macro_grp_fnc_name(magclamp,handle_small_1_pressed);
  86. },"",[DIK_7,[false,false,false]],false] call cba_fnc_addKeybind;
  87. ["RD501 Magclamp","large",["Large Clamp (Laat/C Center)","Activate/Deactivate center Magclamp on Laat/C"],{
  88. [player] call macro_grp_fnc_name(magclamp,handle_large_pressed);
  89. },"",[DIK_8,[false,false,false]],false] call cba_fnc_addKeybind;
  90. ["RD501 Magclamp","small_2",["Second Small Clamp (Laat/C Right)","Activate/Deactivate right Magclamp on Laat/C"],{
  91. [player] call macro_grp_fnc_name(magclamp,handle_small_2_pressed);
  92. },"",[DIK_9,[false,false,false]],false] call cba_fnc_addKeybind;
  93. ["RD501 Magclamp","detach_all",["Detach All","Detach all clamped vehicles"],{
  94. [player] call macro_grp_fnc_name(magclamp,handle_drop_all);
  95. },"",[DIK_0,[false,false,false]],false] call cba_fnc_addKeybind;
  96. // refuel target function
  97. ["RD501_mc_set_fuel", {
  98. _vehicle = (vehicle this);
  99. if (isNull _vehicle) exitWith {};
  100. _vehicle setFuel _this;
  101. }, []] call CBA_fnc_addEventHandlerArgs;