Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. private["_item", "_currQty", "_tradeType", "_itemWorth", "_aiItems", "_itemClasses", "_itemQtys", "_qtyIndex", "_tradeTotal", "_tradeQtyTotal", "_errorMsg", "_target", "_sizeOut", "_array", "_makeTrade", "_vehSlot", "_vehicle", "_vehicles", "_display", "_addWeaponToHands", "_type", "_tax"];
  2.  
  3. if (!isNil "EPOCH_TRADE_COMPLETE") exitWith {};
  4. if (!isNil "EPOCH_TRADE_STARTED") exitWith{};
  5. if (!isNull _this) then {
  6.  
  7.  
  8. _config = 'CfgPricing' call EPOCH_returnConfig;
  9.  
  10. _current_crypto = EPOCH_playerCrypto;
  11.  
  12. // _arrayIn = Sell Array
  13. _sizeOut = lbSize 41501;
  14. _arrayIn = [];
  15. if (_sizeOut > 0) then {
  16. for "_i" from 0 to(_sizeOut - 1) do {
  17. _item = lbData[41501, _i];
  18.  
  19. if (isClass (_config >> _item)) then{
  20.  
  21. // test remove items to be sold and add to array
  22. if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then {
  23. if (_item in items player) then {
  24. player removeItem _item;
  25. _arrayIn pushBack _item;
  26. }
  27. else {
  28. if (_item == primaryweapon player) then {
  29. player removeweapon _item;
  30. _arrayIn pushBack _item;
  31. };
  32. };
  33. }
  34. else {
  35. if ([_item, "CfgVehicles"] call EPOCH_fnc_isAny) then {
  36. if (_item == backpack player) then {
  37. removeBackpack player;
  38. _arrayIn pushBack _item;
  39. }
  40. else {
  41. _vehicles = _this nearEntities[[_item], 30];
  42. if (!(_vehicles isEqualTo[])) then {
  43. _vehicle = _vehicles select 0;
  44. if (!isNull _vehicle) then {
  45. if (local _vehicle) then {
  46. _vehSlot = _vehicle getVariable["VEHICLE_SLOT", "ABORT"];
  47. if (_vehSlot != "ABORT") then {
  48. _arrayIn pushBack _item;
  49. // will be removed server side
  50. };
  51. };
  52. };
  53. };
  54. };
  55. }
  56. else {
  57. if (_item in magazines player) then {
  58. player removeMagazine _item;
  59. _arrayIn pushBack _item;
  60. };
  61. };
  62. };
  63. // test
  64.  
  65.  
  66.  
  67. };
  68. };
  69. };
  70.  
  71. // _arrayOut = Purchase Array
  72. _sizeOut = lbSize 41502;
  73. _arrayOut = [];
  74. if (_sizeOut > 0) then {
  75. for "_i" from 0 to(_sizeOut - 1) do {
  76. _item = lbData[41502, _i];
  77.  
  78. if (isClass (_config >> _item)) then{
  79. _itemWorth = getNumber(_config >> "price");
  80. _itemTax = getNumber(_config >> "tax");
  81. _tax = _itemWorth * (EPOCH_taxRate + _itemTax);
  82. _itemWorth = ceil(_itemWorth + _tax);
  83.  
  84. if (_current_crypto >= _itemWorth) then {
  85. _current_crypto = _current_crypto - _itemWorth;
  86. _arrayOut pushBack _item;
  87. };
  88. };
  89. };
  90. };
  91.  
  92. if (!(_arrayIn isEqualTo[]) || !(_arrayOut isEqualTo[])) then {
  93. EPOCH_TRADE_STARTED = true;
  94.  
  95. // make trade
  96. EPOCH_MAKENPCTRADE = [_this, _arrayIn, _arrayOut, player, Epoch_personalToken];
  97. publicVariableServer "EPOCH_MAKENPCTRADE";
  98.  
  99. // close menu
  100. closeDialog 0;
  101.  
  102. [_arrayIn, _arrayOut] spawn{
  103.  
  104. waitUntil{ uiSleep 0.1; !isNil "EPOCH_TRADE_COMPLETE" };
  105.  
  106. // SOLD ITEMS ARRAY
  107. if !((EPOCH_TRADE_COMPLETE select 0) isEqualTo[]) then {
  108. if ((EPOCH_TRADE_COMPLETE select 0) isEqualTo(_this select 0)) then {
  109. _errorMsg = 'Items Sold';
  110. _dt = [format["<t size='0.8' shadow='0' color='#99ffffff'>%1</t>", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;
  111.  
  112. }
  113. else {
  114. _errorMsg = 'Failed To Sell Items';
  115. _dt = [format["<t size='0.8' shadow='0' color='#99ffffff'>%1</t>", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;
  116. };
  117. };
  118.  
  119. // PURCHASED ITEMS ARRAY
  120. if !((EPOCH_TRADE_COMPLETE select 1) isEqualTo[]) then {
  121. if ((EPOCH_TRADE_COMPLETE select 1) isEqualTo(_this select 1)) then {
  122.  
  123. _errorMsg = 'Items Purchased: ';
  124. // add purchased items
  125. {
  126. if ([_x, "CfgWeapons"] call EPOCH_fnc_isAny) then {
  127. _errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgWeapons" >> (_x) >> "displayName")];
  128. _type = getNumber(configfile >> "CfgWeapons" >> (_x) >> "type");
  129. _addWeaponToHands = false;
  130. switch (_type) do {
  131. case 1: {
  132. if (primaryWeapon player == "") then {
  133. _addWeaponToHands = true;
  134. };
  135. };
  136. case 2: {
  137. if (secondaryWeapon player == "") then {
  138. _addWeaponToHands = true;
  139. };
  140. };
  141. case 4: {
  142. if (handgunWeapon player == "") then {
  143. _addWeaponToHands = true;
  144. };
  145. };
  146. };
  147. if (_addWeaponToHands) then {
  148. player addWeapon _x;
  149. }
  150. else {
  151. _x call EPOCH_fnc_addItemOverflow;
  152. };
  153. }
  154. else {
  155. _backpack = ["backpack", _x] call BIS_fnc_inString;
  156. _Assaultpack = ["Assaultpack", _x] call BIS_fnc_inString;
  157. _Assault_Diver = ["Assault_Diver", _x] call BIS_fnc_inString;
  158. _TacticalPack = ["TacticalPack", _x] call BIS_fnc_inString;
  159. _FieldPack = ["FieldPack", _x] call BIS_fnc_inString;
  160. _Carryall = ["Carryall", _x] call BIS_fnc_inString;
  161. _OutdoorPack = ["OutdoorPack", _x] call BIS_fnc_inString;
  162. _Bergen = ["Bergen", _x] call BIS_fnc_inString;
  163. _bag = ["bag", _x] call BIS_fnc_inString;
  164. _parachute = ["Parachute", _x] call BIS_fnc_inString;
  165. if (_backpack || _Assaultpack || _Assault_Diver || _TacticalPack || _FieldPack || _Carryall || _OutdoorPack || _Bergen || _bag || _parachute) then {
  166. if (backpack player == "") then {
  167. player addbackpack _x;
  168. }
  169. else {
  170. _x createvehicle getpos player;
  171. };
  172. }
  173. else {
  174. if ([_x, "CfgMagazines"] call EPOCH_fnc_isAny) then {
  175. _errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgMagazines" >> (_x) >> "displayName")];
  176. _x call EPOCH_fnc_addItemOverflow;
  177. }
  178. else {
  179. _errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgVehicles" >> (_x) >> "displayName")];
  180. };
  181. };
  182. };
  183. } forEach(_this select 1);
  184.  
  185.  
  186. _dt = [format["<t size='0.8' shadow='0' color='#99ffffff'>%1</t>", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;
  187. }
  188. else {
  189. _errorMsg = 'Failed To Purchase Items';
  190. _dt = [format["<t size='0.8' shadow='0' color='#99ffffff'>%1</t>", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;
  191. };
  192. };
  193.  
  194. EPOCH_TRADE_COMPLETE = nil;
  195. EPOCH_TRADE_STARTED = nil;
  196. };
  197. };
  198. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement