Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. private ["_item","_index","_itemCount","_itemOfferCount","_config","_name","_picture","_type","_vehicles","_sizeOut","_offerArray","_itemName","_itemIcon","_qty","_items","_qtys","_aiItems","_filterArray","_filterWeapons","_filterMagazines","_filterItems","_filterVehicle","_slot","_control","_isPlayerFilter"];
  2.  
  3. disableSerialization;
  4.  
  5. if !(isNull EPOCH_lastNPCtradeTarget) then {
  6.  
  7. _slot = EPOCH_lastNPCtradeTarget getVariable["AI_SLOT", -1];
  8.  
  9. _control = _this select 0;
  10.  
  11. _isPlayerFilter = (ctrlIDC _control == 42100);
  12.  
  13. _index = _this select 1;
  14.  
  15. if (_slot != -1) then {
  16.  
  17. _filterArray = [
  18. [true,true,true,true], // all
  19. // [true,false,false,false], // weapons only
  20. [false,true,false,false], // mags only
  21. [false,false,true,false], // items only
  22. [false,false,false,true] // vehicles only
  23. ];
  24.  
  25. //_filterWeapons = ((_filterArray select _index) select 0);
  26. _filterMagazines = ((_filterArray select _index) select 1);
  27. _filterItems = ((_filterArray select _index) select 2);
  28. _filterVehicle = ((_filterArray select _index) select 3);
  29.  
  30. if (_isPlayerFilter) then {
  31.  
  32. _sizeOut = lbSize 41501;
  33. _offerArray = [];
  34. if (_sizeOut > 0) then {
  35. for "_i" from 0 to (_sizeOut - 1) do {
  36. _item = lbData [41501, _i];
  37. _offerArray pushBack _item;
  38. };
  39. };
  40.  
  41. lbClear 41500;
  42.  
  43. if (_filterMagazines) then {
  44. {
  45. // make sure this exceeds the item count already offered
  46. _item = _x;
  47. _itemCount = {_x == _item} count magazines player;
  48. _itemOfferCount = {_x == _item} count _offerArray;
  49. if (_itemCount > _itemOfferCount) then {
  50. _offerArray pushBack _item;
  51. _index = lbAdd [41500, _x call EPOCH_itemDisplayName];
  52. lbSetData [41500, _index, _x];
  53. lbSetPicture [41500, _index, _x call EPOCH_itemPicture];
  54. };
  55. } forEach magazines player;
  56. };
  57.  
  58. /* not used currently
  59. if (_filterWeapons) then {
  60. };
  61. */
  62.  
  63. if (_filterItems) then {
  64. {
  65. _item = _x;
  66. _itemCount = {_x == _item} count items player;
  67. _itemOfferCount = {_x == _item} count _offerArray;
  68. if (_itemCount > _itemOfferCount) then {
  69. _offerArray pushBack _item;
  70. _index = lbAdd [41500, _x call EPOCH_itemDisplayName];
  71. lbSetData [41500, _index, _x];
  72. lbSetPicture [41500, _index, _x call EPOCH_itemPicture];
  73. };
  74. } forEach items player;
  75. if (primaryWeapon player != "") then {
  76. _wpn = primaryWeapon player;
  77. _offerArray pushback _wpn;
  78. _index = lbAdd [41500, _wpn call EPOCH_itemDisplayName];
  79. lbSetData [41500, _index, _wpn];
  80. lbSetPicture [41500, _index, _wpn call EPOCH_itemPicture];
  81. };
  82. if (count backpackItems player == 0 && count backpackmagazines player == 0 && backpack player != "") then {
  83. _bpck = Backpack player;
  84. _offerArray pushback _bpck;
  85. _index = lbAdd [41500, _bpck call EPOCH_itemDisplayName];
  86. lbSetData [41500, _index, _bpck];
  87. lbSetPicture [41500, _index, _bpck call EPOCH_itemPicture];
  88. };
  89. };
  90.  
  91. if (_filterVehicle) then {
  92. _vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
  93. {
  94. if (local _x) then {
  95. _type = typeOf _x;
  96. _itemCount = { typeOf _x == _type } count _vehicles;
  97. _itemOfferCount = { _x == _type } count _offerArray;
  98. if (_itemCount > _itemOfferCount) then {
  99. _offerArray pushBack _type;
  100.  
  101. _config = configFile >> "CfgVehicles" >> _type;
  102.  
  103. _name = getText(_config >> "displayName");
  104. _picture = getText(_config >> "picture");
  105.  
  106. _index = lbAdd[41500, _name];
  107. lbSetData[41500, _index, _type];
  108. lbSetPicture[41500, _index, _picture];
  109. };
  110. };
  111. } forEach _vehicles;
  112. };
  113.  
  114. } else {
  115.  
  116. lbClear 41503;
  117.  
  118. _sizeOut = lbSize 41502;
  119. _offerArray = [];
  120. if (_sizeOut > 0) then {
  121. for "_i" from 0 to (_sizeOut - 1) do {
  122. _item = lbData [41502, _i];
  123. _offerArray pushBack _item;
  124. };
  125. };
  126. _aiItems = EPOCH_lastNPCtradeTarget getVariable["AI_ITEMS", []];
  127. if ((count _aiItems) == 2) then {
  128. _items = _aiItems select 0;
  129. _qtys = _aiItems select 1;
  130. {
  131.  
  132. _item = _x;
  133. _itemName = "";
  134. _itemIcon = "";
  135. if ([_item, "CfgVehicles"] call EPOCH_fnc_isAny) then {
  136. if (_filterVehicle) then {
  137. _itemName = getText(configfile >> "CfgVehicles" >> _item >> "DisplayName");
  138. _itemIcon = getText(configfile >> "CfgVehicles" >> _item >> "picture");
  139. };
  140. } else {
  141. if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then {
  142. if (_filterItems) then {
  143. _itemName = getText(configfile >> "CfgWeapons" >> _item >> "DisplayName");
  144. _itemIcon = getText(configfile >> "CfgWeapons" >> _item >> "picture");
  145. };
  146. } else {
  147. if ([_item, "CfgMagazines"] call EPOCH_fnc_isAny) then {
  148. if (_filterMagazines) then {
  149. _itemName = getText(configfile >> "CfgMagazines" >> _item >> "DisplayName");
  150. _itemIcon = getText(configfile >> "CfgMagazines" >> _item >> "picture");
  151. };
  152. };
  153. };
  154. };
  155. if (_itemName != "") then {
  156.  
  157. _qty = ((_qtys select _forEachIndex) - ({_x == _item} count _offerArray));
  158. if (_qty > 0) then {
  159.  
  160. // _offerArray pushBack _item;
  161. _index = lnbAddRow[41503, ["", str(_qty), _itemName]];
  162. lnbSetData [41503, [_index,0], _item];
  163. lnbSetValue [41503, [_index,0], _qty];
  164. lnbSetPicture [41503, [_index,0], _itemIcon];
  165. };
  166. };
  167.  
  168. } forEach _items;
  169. };
  170. };
  171. };
  172. } else {
  173. closeDialog 0;
  174. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement