Advertisement
Zupalicious

tradeorig

Jun 2nd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. private ["_part_out","_part_in","_qty_out","_qty_in","_qty","_buy_o_sell","_textPartIn","_textPartOut","_bos","_needed","_started","_finished","_animState","_isMedic","_total_parts_out","_abort","_removed","_activatingPlayer","_traderID","_done"];
  2. // [part_out,part_in, qty_out, qty_in,];
  3.  
  4. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_103") , "PLAIN DOWN"] };
  5. DZE_ActionInProgress = true;
  6.  
  7. _activatingPlayer = player;
  8.  
  9. _part_out = (_this select 3) select 0;
  10. _part_in = (_this select 3) select 1;
  11. _qty_out = (_this select 3) select 2;
  12. _qty_in = (_this select 3) select 3;
  13. _buy_o_sell = (_this select 3) select 4;
  14. _textPartIn = (_this select 3) select 5;
  15. _textPartOut = (_this select 3) select 6;
  16. _traderID = (_this select 3) select 7;
  17.  
  18. _bos = 0;
  19. if(_buy_o_sell == "sell") then {
  20. _bos = 1;
  21. };
  22.  
  23. _abort = false;
  24.  
  25. // perform number of total trades
  26. r_autoTrade = true;
  27. while {r_autoTrade} do {
  28.  
  29. _removed = 0;
  30. cutText [(localize "str_epoch_player_105"), "PLAIN DOWN"];
  31.  
  32. r_interrupt = false;
  33. r_doLoop = true;
  34. _started = false;
  35. _finished = false;
  36.  
  37.  
  38. //////////////
  39.  
  40. _position = getPos player; // gets the position [x,y,z]
  41. _posX = _position select 0; // 1th element -> x
  42. _posY = _position select 1; // 2nd element -> y
  43.  
  44. _counter = 0.0; // animation duration checker
  45.  
  46. while {r_doLoop} do {
  47. _positionCheck = getPos player;
  48. _newX = _positionCheck select 0; // 1th element -> x
  49. _newY = _positionCheck select 1; // 2nd element -> y
  50.  
  51. _counter = _counter + 0.1; // same as the sleep timer: 0.1 sec
  52.  
  53. if (_counter > 1.5) then { // amount of secs the animation takes estimated ? 2 secs?
  54. r_doLoop = false;
  55. _counter = 0.0;
  56. _finished = true;
  57.  
  58. };
  59. if (_newX != _posX || _newY != _posY) then {
  60.  
  61. r_doLoop = false;
  62. };
  63. sleep 0.1;
  64. };
  65. r_doLoop = false;
  66.  
  67. if (!_finished) exitWith {
  68. r_interrupt = false;
  69. if (vehicle player == player) then {
  70. [objNull, player, rSwitchMove,""] call RE;
  71. player playActionNow "stop";
  72. };
  73. cutText [(localize "str_epoch_player_106") , "PLAIN DOWN"];
  74. };
  75.  
  76. if (_finished) then {
  77.  
  78. _canAfford = false;
  79. if(_bos == 1) then {
  80.  
  81. //sell
  82. _qty = {_x == _part_in} count magazines player;
  83. if (_qty >= _qty_in) then {
  84. _part_inClass = configFile >> "CfgMagazines" >> _part_in;
  85. _removed = _removed + ([player,_part_inClass,_qty_in] call BIS_fnc_invRemove);
  86. if (_removed == _qty_in) then {
  87. _canAfford = [[[_part_out,_qty_out]],1] call epoch_returnChange;
  88. };
  89. };
  90.  
  91. } else {
  92.  
  93. //buy
  94. _trade_total = [[_part_in,_qty_in]] call epoch_itemCost;
  95. _total_currency = call epoch_totalCurrency;
  96. _return_change = _total_currency - _trade_total;
  97. if (_return_change >= 0) then {
  98. _canAfford = true;
  99. };
  100. };
  101.  
  102. diag_log format["DEBUG TRADER DONE?: %1", _canAfford];
  103.  
  104. if (_canAfford) then {
  105.  
  106. // Continue with trade.
  107. if (isNil "_part_in") then { _part_in = "Unknown Item" };
  108. if (isNil "inTraderCity") then { inTraderCity = "Unknown Trader City" };
  109. if(_bos == 1) then {
  110. // Selling
  111. PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_in,inTraderCity,_part_out,_qty_out];
  112. } else {
  113. // Buying
  114. PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_out,inTraderCity,_part_in,_qty_in];
  115. };
  116. publicVariableServer "PVDZE_obj_Trade";
  117.  
  118. if(_bos == 0) then {
  119. // only wait for result when buying
  120. waitUntil {!isNil "dayzTradeResult"};
  121. if(dayzTradeResult == "PASS") then {
  122. _done = [[[_part_in,_qty_in]],0] call epoch_returnChange;
  123. if (_done) then {
  124. for "_x" from 1 to _qty_out do {
  125. player addMagazine _part_out;
  126. };
  127. cutText [format[(localize "str_epoch_player_186"),_qty_in,_textPartIn,_qty_out,_textPartOut], "PLAIN DOWN"];
  128. };
  129. } else {
  130. _abort = true;
  131. cutText [format[(localize "str_epoch_player_183"),_textPartOut] , "PLAIN DOWN"];
  132. };
  133. } else {
  134. cutText [format[(localize "str_epoch_player_186"),_qty_in,_textPartIn,_qty_out,_textPartOut], "PLAIN DOWN"];
  135. };
  136. dayzTradeResult = nil;
  137.  
  138. } else {
  139. _qty = {_x == _part_in} count magazines player;
  140. _needed = _qty_in - _qty;
  141. cutText [format[(localize "str_epoch_player_184"),_needed,_textPartIn] , "PLAIN DOWN"];
  142. _abort = true;
  143. };
  144. };
  145. if(_abort) exitWith {r_autoTrade = false};
  146.  
  147. sleep 1;
  148. };
  149.  
  150. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement