Skip to content

Commit d1dea67

Browse files
Better preserve state on switch (#20)
Utilise CBA extended loadout functions for loadout changes Keep NVG state consistent
1 parent c559ce2 commit d1dea67

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

addons/main/functions/fnc_actionOnBack.sqf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ private _chestpack = [_unit] call FUNC(chestpack);
2020
private _chestpackLoadout = [_unit] call FUNC(chestpackLoadout);
2121
private _chestpackVariables = [_unit] call FUNC(chestpackVariables);
2222

23+
private _shouldSwitchNVGs = currentVisionMode _unit != 0;
24+
2325
//make sure the player has a chestpack and no backpack
2426
if ((_chestpack isEqualTo "") or !(backpack _unit isEqualTo "")) exitWith {};
2527

2628
//add items
27-
private _loadout = getUnitLoadout _unit;
28-
_loadout set [5, [_chestpack, _chestpackLoadout]];
29-
_unit setUnitLoadout _loadout;
29+
private _loadout = [_unit] call CBA_fnc_getLoadout;
30+
(_loadout select 0) set [5, [_chestpack, _chestpackLoadout]];
31+
[_unit, _loadout] call CBA_fnc_setLoadout;
32+
if (_shouldSwitchNVGs) then {
33+
_unit action ["NVGoggles", _unit];
34+
};
3035
//prefilled versions of backpacks (ammo bearer, engineer, explosives, medic, repair, etc)
3136
//can be emptied and placed in unit's backpack
3237
//they must each be emptied when added

addons/main/functions/fnc_actionSwap.sqf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ private _chestpack = [_unit] call FUNC(chestpack);
2525
private _chestpackLoadout = [_unit] call FUNC(chestpackLoadout);
2626
private _chestpackVariables = [_unit] call FUNC(chestpackVariables);
2727

28+
private _shouldSwitchNVGs = currentVisionMode _unit != 0;
29+
2830
//make sure the player has chest-pack and backpack
2931
if ((_backpack isEqualTo "") or ([_unit] call FUNC(chestpack)) isEqualTo "") exitWith {};
3032

@@ -39,9 +41,12 @@ if ((_backpack isEqualTo "") or ([_unit] call FUNC(chestpack)) isEqualTo "") exi
3941
removeBackpackGlobal _unit;
4042

4143
//add backpack loadout
42-
private _loadout = getUnitLoadout _unit;
43-
_loadout set [5, [_chestpack, _chestpackLoadout]];
44-
_unit setUnitLoadout _loadout;
44+
private _loadout = [_unit] call CBA_fnc_getLoadout;
45+
(_loadout select 0) set [5, [_chestpack, _chestpackLoadout]];
46+
[_unit, _loadout] call CBA_fnc_setLoadout;
47+
if (_shouldSwitchNVGs) then {
48+
_unit action ["NVGoggles", _unit];
49+
};
4550

4651
//add backpack variables
4752
private _backpackNew = backpackContainer _unit;

0 commit comments

Comments
 (0)