fnc_jlts_shield_aiToggle.sqf 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Author: MrClock
  3. * Modified by: Mirror
  4. * [Originally] called from the "Equip/unequip riot shield" CBA keybind
  5. * Modified to work directly with AI (just stripped out player specific stuff)
  6. *
  7. * Arguments:
  8. * None
  9. *
  10. * Originally:
  11. * [] call JLTS_fnc_handleRiotShield;
  12. *
  13. * Example:
  14. * _this call rd501_jlts_shield_aiToggle;
  15. *
  16. * Return Value:
  17. * None
  18. */
  19. params["_unit"];
  20. private _weapon = currentWeapon _unit;
  21. if (_weapon == "") exitWith {false;};
  22. private _items = [_weapon,_unit,false,true] call JLTS_fnc_getWeaponItems;
  23. if (getNumber(configFile >> "CfgWeapons" >> _weapon >> "JLTS_canHaveShield") == 1 && {getNumber(configFile >> "CfgWeapons" >> _weapon >> "JLTS_isShielded") != 1}) then {
  24. private _shield = [];
  25. {
  26. if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_isShieldItem") == 1) exitWith {
  27. _shield = [_x,getText(configFile >> "CfgWeapons" >> _x >> "JLTS_shieldAttachment")]
  28. };
  29. } forEach items _unit;
  30. if (_shield isEqualTo []) exitWith {false};
  31. [_unit,_weapon,_items,_shield] params["_unit","_weapon","_items","_shield"];
  32. private _shieldedVariant = getText(configFile >> "CfgWeapons" >> _weapon >> "JLTS_shieldedWeapon");
  33. [_unit,_weapon] call JLTS_fnc_magazineCorrection;
  34. [_unit,_shieldedVariant] remoteExec ["addWeapon",0,false];
  35. [_shieldedVariant,_unit,_items] call JLTS_fnc_addWeaponItems;
  36. [_shieldedVariant,_unit,[_shield select 1]] call JLTS_fnc_addWeaponItems;
  37. _unit removeItem (_shield select 0);
  38. } else {
  39. if (getNumber(configFile >> "CfgWeapons" >> _weapon >> "JLTS_isShielded") == 1) then {
  40. private _shield = [];
  41. switch ([_weapon] call JLTS_fnc_getWeaponType) do {
  42. case ("handgun"): {
  43. private _shieldAttachment = (handgunItems _unit) select 3;
  44. if (_shieldAttachment != "" && {getNumber(configFile >> "CfgWeapons" >> _shieldAttachment >> "JLTS_isShieldAttachment") == 1}) then {
  45. private _shieldItem = getText(configFile >> "CfgWeapons" >> _shieldAttachment >> "JLTS_shieldItem");
  46. _shield = [_shieldItem,_shieldAttachment];
  47. };
  48. };
  49. case ("primary"): {
  50. private _shieldAttachment = (primaryWeaponItems _unit) select 3;
  51. if (_shieldAttachment != "" && {getNumber(configFile >> "CfgWeapons" >> _shieldAttachment >> "JLTS_isShieldAttachment") == 1}) then {
  52. private _shieldItem = getText(configFile >> "CfgWeapons" >> _shieldAttachment >> "JLTS_shieldItem");
  53. _shield = [_shieldItem,_shieldAttachment];
  54. };
  55. };
  56. default {};
  57. };
  58. if (_shield isEqualTo []) then {
  59. _shield = ["JLTS_riot_shield_item",""];
  60. };
  61. if (!(_unit canAdd (_shield select 0))) then {
  62. private _baseVariant = getText(configFile >> "CfgWeapons" >> _weapon >> "JLTS_baseWeapon");
  63. [_unit,_weapon] call JLTS_fnc_magazineCorrection;
  64. [_unit,_baseVariant] remoteExec ["addWeapon",0,false];
  65. if (_shield select 1 != "") then {
  66. _items = _items - [_shield select 1];
  67. };
  68. [_baseVariant,_unit,_items] call JLTS_fnc_addWeaponItems;
  69. [_unit] call JLTS_fnc_cleanUpShields;
  70. private _weaponHolder = createVehicle["GroundWeaponHolder",getPos _unit,[],0,"CAN_COLLIDE"];
  71. _weaponHolder setDir ((getDir _unit) - random[5,10,15]);
  72. _weaponHolder addItemCargoGlobal [_shield select 0,1];
  73. } else {
  74. private _baseVariant = getText(configFile >> "CfgWeapons" >> _weapon >> "JLTS_baseWeapon");
  75. [_unit,_weapon] call JLTS_fnc_magazineCorrection;
  76. [_unit,_baseVariant] remoteExec ["addWeapon",0,false];
  77. if (_shield select 1 != "") then {
  78. _items = _items - [_shield select 1];
  79. };
  80. [_baseVariant,_unit,_items] call JLTS_fnc_addWeaponItems;
  81. [_unit] call JLTS_fnc_cleanUpShields;
  82. _unit addItem (_shield select 0);
  83. };
  84. };
  85. };