Advertisement
Guest User

Exemple de code SQF

a guest
Jul 27th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /*
  2.  
  3. Buy [SHORTNAME, AMOUNT, israw, send?]
  4.  
  5. */
  6.  
  7. private["_shortname","_amount","_price","_modifier","_globalprice","_min","_dir","_israw","_arr_resource","_arr_price","_modifier","_send","_relamount","_max"];
  8.  
  9. _shortname = _this select 0;
  10. _amount = _this select 1;
  11. _israw = [_this, 2, false] call BIS_fnc_param;
  12. _send = [_this, 3, true] call BIS_fnc_param;
  13.  
  14. //Get all necessary arrays
  15. _arr_resource = [_shortname] call life_fnc_marketGetRow;
  16. _arr_price = [_shortname] call life_fnc_marketGetPriceRow;
  17.  
  18. //Calculate the new price of the product
  19. _price = _arr_price select 1; //current price
  20. _globalprice = _arr_price select 2; //current change rate
  21.  
  22. _modifier = (_amount * (_arr_resource select 5)); //calculate modifier
  23.  
  24. _price = _price + _modifier;
  25. _globalprice = _globalprice + _modifier;
  26.  
  27. //Check borders
  28. if(_price < 0) then {_price = 0;};
  29.  
  30. _max = _arr_resource select 3;
  31.  
  32. if( _price > _max)then {_price = _max;};
  33.  
  34. //insert into new array
  35. [_shortname, [_shortname,_price,_globalprice,_modifier], false ] call life_fnc_marketSetPriceRow; //dont broadcast!
  36.  
  37.  
  38. /////Change related prices
  39. if(!_israw) then
  40. {
  41. {
  42. _relamount = ceil (_amount * (_x select 1));
  43. if(_relamount < 0) then //INVERTED!
  44. {
  45. _relamount = -(_relamount);
  46. [_x select 0, _relamount, true, false] call life_fnc_marketBuy; //Make prices higher, no broadcast!
  47. }
  48. else
  49. {
  50. [_x select 0, _relamount, true, false] call life_fnc_marketSell; //Make prices higher, no broadcast!
  51. };
  52. }
  53. foreach (_arr_resource select 6); //in change array
  54. };
  55.  
  56. //Broadcast now if can send
  57. if(_send) then {publicVariable "life_market_prices";};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement