Advertisement
Guest User

fn_virt_buy

a guest
Feb 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include "..\..\script_macros.hpp"
  2. /*
  3. File: fn_virt_buy.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Description:
  7. Buy a virtual item from the store.
  8. */
  9. private ["_type","_price","_amount","_diff","_name","_hideout"];
  10. if ((lbCurSel 2401) isEqualTo -1) exitWith {hint localize "STR_Shop_Virt_Nothing"};
  11. _type = lbData[2401,(lbCurSel 2401)];
  12. _price = lbValue[2401,(lbCurSel 2401)];
  13. _amount = ctrlText 2404;
  14.  
  15. if (!([_amount] call TON_fnc_isnumber)) exitWith {hint localize "STR_Shop_Virt_NoNum";};
  16. _diff = [_type,parseNumber(_amount),life_carryWeight,life_maxWeight] call life_fnc_calWeightDiff;
  17. _amount = parseNumber(_amount);
  18.  
  19. if(_amount > 50) exitWith {hint "Amounts cannot be more than 50";};
  20.  
  21. if (_diff <= 0) exitWith {hint localize "STR_NOTF_NoSpace"};
  22. _amount = _diff;
  23. private _altisArray = ["Land_u_Barracks_V2_F","Land_i_Barracks_V2_F"];
  24. private _tanoaArray = ["Land_School_01_F","Land_Warehouse_03_F","Land_House_Small_02_F"];
  25. private _stratisArray = ["Land_Barracks_01_camo_F","Land_u_Barracks_V2_F","Land_i_Barracks_V2_F","Land_Cargo_HQ_V2_F"];
  26. private _hideoutObjs = [[["Altis", _altisArray], ["Tanoa", _tanoaArray], ["Stratis", _stratisArray]]] call TON_fnc_terrainSort;
  27. _hideout = (nearestObjects[getPosATL player,_hideoutObjs,25]) select 0;
  28. if ((_price * _amount) > CASH && {!isNil "_hideout" && {!isNil {group player getVariable "gang_bank"}} && {(group player getVariable "gang_bank") <= _price * _amount}}) exitWith {hint localize "STR_NOTF_NotEnoughMoney"};
  29. if ((time - life_action_delay) < 0.2) exitWith {hint localize "STR_NOTF_ActionDelay";};
  30. life_action_delay = time;
  31.  
  32. _name = M_CONFIG(getText,"VirtualItems",_type,"displayName");
  33. if ([true,_type,_amount] call life_fnc_handleInv) then {
  34. if (!isNil "_hideout" && {!isNil {group player getVariable "gang_bank"}} && {(group player getVariable "gang_bank") >= _price}) then {
  35. _action = [
  36. format [(localize "STR_Shop_Virt_Gang_FundsMSG")+ "<br/><br/>" +(localize "STR_Shop_Virt_Gang_Funds")+ " <t color='#8cff9b'>$%1</t><br/>" +(localize "STR_Shop_Virt_YourFunds")+ " <t color='#8cff9b'>$%2</t>",
  37. [(group player getVariable "gang_bank")] call life_fnc_numberText,
  38. [CASH] call life_fnc_numberText
  39. ],
  40. localize "STR_Shop_Virt_YourorGang",
  41. localize "STR_Shop_Virt_UI_GangFunds",
  42. localize "STR_Shop_Virt_UI_YourCash"
  43. ] call BIS_fnc_guiMessage;
  44. if (_action) then {
  45. hint format [localize "STR_Shop_Virt_BoughtGang",_amount,(localize _name),[(_price * _amount)] call life_fnc_numberText];
  46. _funds = group player getVariable "gang_bank";
  47. _funds = _funds - (_price * _amount);
  48. group player setVariable ["gang_bank",_funds,true];
  49.  
  50. if (life_HC_isActive) then {
  51. [1,group player] remoteExecCall ["HC_fnc_updateGang",HC_Life];
  52. } else {
  53. [1,group player] remoteExecCall ["TON_fnc_updateGang",RSERV];
  54. };
  55.  
  56. } else {
  57. if ((_price * _amount) > CASH) exitWith {[false,_type,_amount] call life_fnc_handleInv; hint localize "STR_NOTF_NotEnoughMoney";};
  58. hint format [localize "STR_Shop_Virt_BoughtItem",_amount,(localize _name),[(_price * _amount)] call life_fnc_numberText];
  59. CASH = CASH - _price * _amount;
  60. };
  61. } else {
  62. if ((_price * _amount) > CASH) exitWith {hint localize "STR_NOTF_NotEnoughMoney"; [false,_type,_amount] call life_fnc_handleInv;};
  63. hint format [localize "STR_Shop_Virt_BoughtItem",_amount,(localize _name),[(_price * _amount)] call life_fnc_numberText];
  64. CASH = CASH - _price * _amount;
  65. };
  66. [] call life_fnc_virt_update;
  67. };
  68. [0] call SOCK_fnc_updatePartial;
  69. [3] call SOCK_fnc_updatePartial;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement