Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 1.75 KB | None | 0 0
  1. span class="re5"> params [["_container",0],["_unit",player]];
  2.  
  3. if(_container < 3 || _container > 5) exitWith {[]};
  4.  
  5. _items = (((getUnitLoadout _unit) select _container) select 1);
  6.  
  7. _newItems = [];
  8. _exit = false;
  9.  
  10. _count = count _items;
  11. while {_count != (count _newItems)} do {
  12.  
  13.     _i = _items findIf {count _x == 2 && (_x select 0) isEqualType []}; // Check if its a weapon, if so do special things
  14.     if(_i != -1) then { // is Weapon
  15.         _wepArray = _items select _i;
  16.         _newI = _newItems findIf {_x select 0 isEqualTo (_wepArray select 0)}; // check if the same weapon array already exist in _newItems array
  17.         if(_newI != -1) then { // getUnitLoadout doesn't return the weapons in right order always. Because of this we need to check if a stacked weapon exist in the array
  18.             _newItems set [_newI,[((_wepArray) select 0),(((_newItems select _i) select 1) + (_wepArray select 1))]]; // Add more weapon(s) to array (works in setUnitLoadout)
  19.         } else {
  20.             _newItems pushBack _wepArray;
  21.         };
  22.         _items deleteAt _i;
  23.     } else {
  24.         _i = _items findIf {count _x == 2 && (_x select 1) isEqualType 0};
  25.         if(_i != -1) then { // is Item
  26.             _newItems pushBack (_items select _i);
  27.             _items deleteAt _i;
  28.         } else {
  29.             _i = _items findIf {count _x == 3};
  30.             if(_i != -1) then { // is Magazine
  31.                 _newItems pushBack (_items select _i);
  32.                 _items deleteAt _i;
  33.             } else { // Should be backpack but lets still make sure!
  34.                 _i = _items findIf {count _x == 2 && (_x select 1) isEqualType true};
  35.                 if(_i != -1) then { // is Backpack
  36.                     _newItems pushBack (_items select _i);
  37.                     _items deleteAt _i;
  38.                 } else {
  39.                     _exit = true; // R.I.P
  40.                 };
  41.             };
  42.         };
  43.     };
  44.     if(_exit) exitWith {diag_log format ["ERROR: ITEM'S INVALID: %1  --- _newItems: %2",_items,_newItems]};
  45. };
  46.  
  47. _newItems;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement