From 52c19d53af9fbdcbd56eac528eedbefe40c78488 Mon Sep 17 00:00:00 2001 From: Mike-MF Date: Tue, 20 Aug 2024 23:24:58 +0100 Subject: [PATCH] Magazine Repack - Add ability to disable repacking via class (#10232) * Magazine Repack - Add ability to disable repacking via class * Update addons/magazinerepack/functions/fnc_getMagazineChildren.sqf Co-authored-by: PabstMirror * Bretts suggestion * Documentation * Apply suggestions from code review Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Review missed a line * Fix getting number instead of config & microoptimisation --------- Co-authored-by: PabstMirror Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- .../functions/fnc_canRepackMagazine.sqf | 3 +++ .../functions/fnc_getMagazineChildren.sqf | 10 ++++--- .../framework/magazine-repack-framework.md | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 docs/wiki/framework/magazine-repack-framework.md diff --git a/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf b/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf index d6d8f3b827..2c32ec5727 100644 --- a/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf +++ b/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf @@ -18,6 +18,9 @@ params ["_unit", "_magazine"]; +// Exit if repack is disabled for this magazine. +if (getNumber (configFile >> "CfgMagazines" >> _magazine >> "ace_disableRepacking") == 1) exitWith {false}; + private _maxAmmoCount = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); { diff --git a/addons/magazinerepack/functions/fnc_getMagazineChildren.sqf b/addons/magazinerepack/functions/fnc_getMagazineChildren.sqf index b4cf8b16ef..09d6974fef 100644 --- a/addons/magazinerepack/functions/fnc_getMagazineChildren.sqf +++ b/addons/magazinerepack/functions/fnc_getMagazineChildren.sqf @@ -1,7 +1,7 @@ #include "..\script_component.hpp" /* * Author: PabstMirror, commy2, esteldunedain, Ruthberg - * Gets magazine children for interaciton menu. + * Gets magazine children for interaction menu. * * Arguments: * 0: Target @@ -18,16 +18,20 @@ params ["_target", "_player"]; +private _cfgMagazines = configFile >> "CfgMagazines"; + // get all mags and ammo count private _unitMagazines = []; private _unitMagCounts = []; { _x params ["_xClassname", "_xCount", "_xLoaded", "_xType"]; - private _xFullMagazineCount = getNumber (configFile >> "CfgMagazines" >> _xClassname >> "count"); + private _configMagazine = _cfgMagazines >> _xClassname; + private _xFullMagazineCount = getNumber (_configMagazine >> "count"); + private _isRepackDisabled = getNumber (_configMagazine >> "ace_disableRepacking") == 1; //for every partial magazine, that is either in inventory or can be moved there - if ((_xCount < _xFullMagazineCount) && {_xCount > 0} && {(!_xLoaded) || {GVAR(repackLoadedMagazines) && {[_player, _xClassname] call CBA_fnc_canAddItem}}}) then { + if ((!_isRepackDisabled) && {_xCount < _xFullMagazineCount} && {_xCount > 0} && {(!_xLoaded) || {GVAR(repackLoadedMagazines) && {[_player, _xClassname] call CBA_fnc_canAddItem}}}) then { private _index = _unitMagazines find _xClassname; if (_index == -1) then { _unitMagazines pushBack _xClassname; diff --git a/docs/wiki/framework/magazine-repack-framework.md b/docs/wiki/framework/magazine-repack-framework.md new file mode 100644 index 0000000000..b14272227e --- /dev/null +++ b/docs/wiki/framework/magazine-repack-framework.md @@ -0,0 +1,26 @@ +--- +layout: wiki +title: Magazine Repack Framework +description: Explains how to disable repacking. +group: framework +order: 5 +parent: wiki +mod: ace +version: + major: 3 + minor: 18 + patch: 0 +--- + +## 1. Config Values + +### 1.1 Disable Magazine Repacking + +```cpp +class CfgMagazines { + class MyMagazine { + // Disables the ability to repack this magazine + ace_disableRepacking = 1; + }; +}; +```