Skip to content

Commit

Permalink
Fix - Category, Unpacking & Repacking of IFAK, AFAK & MFAK (#455)
Browse files Browse the repository at this point in the history
- Add IFAK / AFAK / MFAK to medical category
- Adds FAK magazine stays in the same place now instead of moving around
in the inventory when un/repacking.
- Fixes repacking bug:
https://ptb.discord.com/channels/528955370941579265/1187420825066938528
- Fixes wrong FAK being deleted.
  • Loading branch information
MissHeda authored Jan 11, 2024
1 parent cf2a873 commit 22794ef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
1 change: 1 addition & 0 deletions addons/misc/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CfgWeapons
scope = 2;
editorPreview = QPATHTOF(ui\IFAK.paa);
picture = QPATHTOF(ui\IFAK.paa);
ACE_isMedicalItem = 1;
class ItemInfo: CBA_MiscItem_ItemInfo {
mass = 15;
};
Expand Down
40 changes: 20 additions & 20 deletions addons/misc/functions/fnc_FAK_repack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,67 @@ private _fnc_arrayToRemoveInvItem = {
} foreach _array;
};

private _fnc_getContainer = {
params ["_containerType"];

switch (_containerType) do {
case 1: {"uniform"};
case 2: {"vest"};
case 3: {"backpack"};
default {""};
private _fnc_getUnitContainer = {
params ["_container", "_unit"];

switch (_container) do {
case "Uniform": { uniformContainer _unit};
case "Vest": { vestContainer _unit};
case "Backpack": { backpackContainer _unit};
};
};

private _ammoCount = [_unit, _item] call FUNC(getMagazineAmmoCounts);
private _ammoCount = [_unit, _item, true] call FUNC(getMagazineAmmoCounts);
private _slotArray = [];
private _highestAmmoCount = -1;
private _containerFAK = "";

{
private _checkedArray = [_x, _type] call FUNC(FAK_ammoToArray);
private _checkedArray = [(_x select 0), _type] call FUNC(FAK_ammoToArray);

if (!(_checkedArray select (_slot - 1)) && _x > _highestAmmoCount) then { // Get fullest FAK
if (!(_checkedArray select (_slot - 1)) && (_x select 0) > _highestAmmoCount) then { // Get fullest FAK
_slotArray = _checkedArray;
_highestAmmoCount = _x;
_highestAmmoCount = _x select 0;
_containerFAK = _x select 1;
};
} forEach _ammoCount;

if !(_highestAmmoCount > -1) exitWith {};

private _container = "";
private _FAKToAdd = "";
private _itemList = [];
private _max = 0;

switch (_type) do {
case 0: { // IFAK
_FAKToAdd = "kat_IFAK";
_container = [(missionNamespace getVariable [QGVAR(IFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(IFAKContents), []];
_max = 15;
};
case 1: { // AFAK
_FAKToAdd = "kat_AFAK";
_container = [(missionNamespace getVariable [QGVAR(AFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(AFAKContents), []];
_max = 63;
};
default { // MFAK
_FAKToAdd = "kat_MFAK";
_container = [(missionNamespace getVariable [QGVAR(MFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(MFAKContents), []];
_max = 255;
};
};

_unit removeItem _item;
[_unit, _itemList select (_slot - 1)] call _fnc_arrayToRemoveInvItem;

_slotArray set [(_slot - 1), true];

private _amountLeft = [_slotArray] call FUNC(FAK_arrayToAmmo);

private _unitContainer = [_containerFAK, _unit] call _fnc_getUnitContainer;

_unitContainer addMagazineAmmoCargo [_item, -1, _highestAmmoCount];

if (_amountLeft >= _max) then {
[_unit, _FAKToAdd, _container] call ACEFUNC(common,addToInventory);
[_unit, _FAKToAdd, (toLower _containerFAK)] call ACEFUNC(common,addToInventory);
} else {
[_unit, (_FAKToAdd + "_Magazine"), _container, _amountLeft] call ACEFUNC(common,addToInventory);
};
_unitContainer addMagazineAmmoCargo [(_FAKToAdd + "_Magazine"), 1, _amountLeft];
};
29 changes: 22 additions & 7 deletions addons/misc/functions/fnc_FAK_unpack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ private _fnc_getContainer = {
};
};

private _fnc_getUnitContainer = {
params ["_container", "_unit"];

switch (_container) do {
case "Uniform": { uniformContainer _unit};
case "Vest": { vestContainer _unit};
case "Backpack": { backpackContainer _unit};
};
};

private _itemType = _item call BIS_fnc_itemType;
_itemType = _itemType select 0;

Expand Down Expand Up @@ -98,33 +108,38 @@ if (_itemType == "Item") exitWith {

// ----- Handling for magazine -----

private _ammoCount = [_unit, _item] call FUNC(getMagazineAmmoCounts);
_unit removeItem _item;
private _ammoCount = [_unit, _item, true] call FUNC(getMagazineAmmoCounts);
private _lowestAmmoCount = 257;
private _containerFAK = "";
{
private _checkedArray = [_x, _type] call FUNC(FAK_ammoToArray);
private _checkedArray = [(_x select 0), _type] call FUNC(FAK_ammoToArray);

if (_x < _lowestAmmoCount && (_slot == 0 || (_slot > 0 && {_checkedArray select (_slot - 1)}))) then { // Get emptiest FAK
if ((_x select 0) < _lowestAmmoCount && (_slot == 0 || (_slot > 0 && {_checkedArray select (_slot - 1)}))) then { // Get emptiest FAK
_slotArray = _checkedArray;
_lowestAmmoCount = _x;
_lowestAmmoCount = _x select 0;
_containerFAK = _x select 1;
};
} forEach _ammoCount;

if !(_lowestAmmoCount < 257) exitWith {};

private _unitContainer = [_containerFAK, _unit] call _fnc_getUnitContainer;

_unitContainer addMagazineAmmoCargo [_item, -1, _lowestAmmoCount];

if (_slot > 0) then {
_slotArray set [(_slot - 1), false];

private _remaining = [_slotArray] call FUNC(FAK_arrayToAmmo);

if (_remaining > 0 || !_removeOnEmptyCondition) then {
[_unit, _FAKToAdd, "", _remaining] call ACEFUNC(common,addToInventory);
_unitContainer addMagazineAmmoCargo [_FAKToAdd, 1, _remaining];
};

[_unit, (_itemList select (_slot - 1)), _container] call _fnc_arrayToInvItem;
} else {
if !(_removeOnEmptyCondition) then {
[_unit, _FAKToAdd, "", 0] call ACEFUNC(common,addToInventory);
_unitContainer addMagazineAmmoCargo [_FAKToAdd, 1, 0];
};

{
Expand Down

0 comments on commit 22794ef

Please sign in to comment.