@@ -17,8 +17,9 @@ sleep 5;
1717
1818private _combinedItems = OT_allItems + OT_allBackpacks + OT_Resources;
1919private _total = 0 ;
20+
2021{
21- _x params [" _cls" , " _num " ];
22+ _x params [" _cls" , " _qty " ];
2223 private _count = 0 ;
2324 if ((_doillegal || _cls in _combinedItems ) && ! (_cls in OT_allClothing)) then {
2425 private _baseprice = [OT_nation,_cls ,0 ] call OT_fnc_getSellPrice ;
@@ -30,28 +31,58 @@ private _total = 0;
3031 _costprice = round (_baseprice * 0.3 );
3132 };
3233
33- _total = _total + (_costprice * _num );
34- [_target , _cls , _num ] call {
35- params [" _target" , " _cls" , " _num" ];
36- if (_cls isKindOf [" Rifle" ,configFile >> " CfgWeapons" ]) exitWith {
37- [_target , _cls , _num ] call CBA_fnc_removeWeaponCargo ;
38- };
39- if (_cls isKindOf [" Launcher" ,configFile >> " CfgWeapons" ]) exitWith {
40- [_target , _cls , _num ] call CBA_fnc_removeWeaponCargo ;
41- };
42- if (_cls isKindOf [" Pistol" ,configFile >> " CfgWeapons" ]) exitWith {
43- [_target , _cls , _num ] call CBA_fnc_removeWeaponCargo ;
44- };
45- if (_cls isKindOf [" Default" ,configFile >> " CfgMagazines" ]) exitWith {
46- [_target , _cls , _num ] call CBA_fnc_removeMagazineCargo ;
47- };
48- if (_cls isKindOf " Bag_Base" ) exitWith {
49- [_target , _cls , _num ] call CBA_fnc_removeBackpackCargo ;
34+ _total = _total + (_costprice * _qty );
35+
36+ private _noncontaineritems = ((weaponCargo _target ) + (itemCargo _target ) + (magazineCargo _target ) + (backpackCargo _target )) call BIS_fnc_consolidateArray ;
37+ private _ncqty = 0 ;
38+ {
39+ _x params [" _thiscls" ," _thisqty" ];
40+ if (_thiscls isEqualTo _cls ) exitWith {
41+ _ncqty = _thisqty ;
5042 };
51- if ! ([_target , _cls , _num ] call CBA_fnc_removeItemCargo ) then {
52- [_target , _cls , _num ] call CBA_fnc_removeWeaponCargo ;
43+ }foreach (_noncontaineritems );
44+ if (_ncqty > 0 ) then {
45+ if ! ([_target , _cls , _ncqty ] call CBA_fnc_removeItemCargo ) then {
46+ if ! ([_target , _cls , _ncqty ] call CBA_fnc_removeWeaponCargo ) then {
47+ if ! ([_target , _cls , _ncqty ] call CBA_fnc_removeMagazineCargo ) then {
48+ if ! ([_target , _cls , _ncqty ] call CBA_fnc_removeBackpackCargo ) then {
49+ };
50+ };
51+ };
5352 };
5453 };
54+ _qty = _qty - _ncqty ;
55+ if (_qty > 0 ) then {
56+ // still need to find more items in backpacks, uniforms etc
57+ {
58+ _x params [" _itemcls" ," _item" ];
59+ {
60+ _x params [" _c" ," _q" ];
61+ if (_c isEqualTo _sellcls ) exitWith {
62+ [_item , _cls , _q ] call CBA_fnc_removeItemCargo ;
63+ _qty = _qty - _q ;
64+ };
65+ }foreach ((itemCargo _item ) call BIS_fnc_consolidateArray );
66+ if (_qty > 0 ) then {
67+ {
68+ _x params [" _c" ," _q" ];
69+ if (_c isEqualTo _sellcls ) exitWith {
70+ [_item , _cls , _q ] call CBA_fnc_removeWeaponCargo ;
71+ _qty = _qty - _q ;
72+ };
73+ }foreach ((weaponCargo _item ) call BIS_fnc_consolidateArray );
74+ };
75+ if (_qty > 0 ) then {
76+ {
77+ _x params [" _c" ," _q" ];
78+ if (_c isEqualTo _sellcls ) exitWith {
79+ [_item , _cls , _q ] call CBA_fnc_removeMagazineCargo ;
80+ _qty = _qty - _q ;
81+ };
82+ }foreach ((magazineCargo _item ) call BIS_fnc_consolidateArray );
83+ };
84+ }foreach (everyContainer _target );
85+ };
5586 };
5687}foreach (_target call OT_fnc_unitStock );
5788
0 commit comments