Guest User

dynamicAtmConfig

a guest
Aug 28th, 2020
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define CODETOSTR(code) (code call {_this = str _this;_this select [1,(count _this) - 2]})
  2. #define STRTOCODE(code) (compile code)
  3.  
  4. /*
  5.     File: fn_dynamicAtmConfig.sqf
  6.     Function: win_fnc_dynamicAtmConfig
  7.     Author: Winter
  8.    
  9.     Description:
  10.         dynamic config for ATM menu
  11.  
  12.         _command
  13.             MenuList
  14.             Money
  15.             Open
  16.             Close
  17.  
  18.     Warning if you are not sure:
  19.         Please don't change the name of the variables
  20.         Follow the structures presented in the examples to avoid any issues.
  21. */
  22.  
  23. params [
  24.     ["_command","",[""]]
  25. ];
  26.  
  27. private _result = [];
  28.  
  29. if(_command isEqualTo "") exitWith {_result};
  30.  
  31. /*
  32.     Example
  33.         private _generalCfg = [
  34.             [
  35.                 "Bank name" - String        - element name
  36.                 [1,0,0,1]   - Array         - element border color
  37.                 {true}      - Code          - condition for viewing, return value boolean
  38.                 {hint "1"}  - Code          - run code after click element
  39.                 {hint "2"}  - Code          - run code after click "Accept" button
  40.             ],
  41.  
  42.             //Or after a clcik on an element, we need to return a list of other elements
  43.             [
  44.                 "Bank name" - String        - element name
  45.                 [1,0,0,1]   - Array         - element border color
  46.                 {true}      - Code          - condition for viewing, return value boolean
  47.                 {hint "1"}  - Code          - run code after click element
  48.                 "[
  49.                     [
  50.                         "Bank name" - String        - element name
  51.                         [1,0,0,1]   - Array         - element border color
  52.                         {true}      - Code          - condition for viewing, return value boolean
  53.                         {hint "1"}  - Code          - run code after click element
  54.                         {hint "2"}  - Code          - run code after click "Accept" button
  55.                     ],
  56.                     [...],
  57.                     [...]
  58.                 ]"                  - String code   - the returning value is an array that consists of elements that as per the first example
  59.  
  60.             ],
  61.             [...],
  62.             [...],
  63.             [...]
  64.         ];     
  65. */
  66.  
  67. // Your money variables
  68. private _bankMoney = "life_atmbank";
  69. private _cashMoney = "life_cash";
  70.  
  71. //-----------Example Code for Cfg------------
  72. private _codeForWithdrawMoney = format["
  73.     private _value = atmCurrentPadNum;
  74.     if (_value <= 0) exitWith {};
  75.     if (_value > %1) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
  76.     %2 = %2 + _value;
  77.     %1 = %1 - _value;
  78.    
  79.     [6] call SOCK_fnc_updatePartial;
  80.     hint format [localize 'STR_ATM_WithdrawSuccess',_value toFixed 0];
  81. ",_bankMoney,_cashMoney];
  82.  
  83. private _codeForDepositMoney = format["
  84.     private _value = atmCurrentPadNum;
  85.     if (_value <= 0) exitWith {};
  86.     if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughCash'};
  87.  
  88.     %2 = %2 - _value;
  89.     %1 = %1 + _value;
  90.  
  91.     [6] call SOCK_fnc_updatePartial;
  92.     hint format [localize 'STR_ATM_DepositSuccess',_value toFixed 0];
  93. ",_bankMoney,_cashMoney];
  94.  
  95. private _codeForTransferMoney = format["
  96.     private _value = atmCurrentPadNum;
  97.     if (_value <= 0) exitWith {};
  98.     if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
  99.     private _tax = _value * getNumber(missionConfigFile >> 'Life_Settings' >> 'bank_transferTax');
  100.     if ((_value + _tax) > %2) exitWith {hint format [localize 'STR_ATM_SentMoneyFail',_value,_tax]};
  101.  
  102.     %2 = %2 - (_value + _tax);
  103.     private _unit = objectFromNetId '%1';
  104.     [_value,profileName] remoteExecCall ['life_fnc_wireTransfer',_unit];
  105.  
  106.     [1] call SOCK_fnc_updatePartial;
  107.     hint format [localize 'STR_ATM_SentMoneySuccess',_value toFixed 0,_unit getVariable ['realname',name _unit],_tax toFixed 0];
  108. ","%1",_bankMoney];
  109.  
  110. private _getSideColor = {
  111.     private _unitSide = side _this;
  112.  
  113.     if(_unitSide isEqualTo west) exitWith {[0,0,0.8,0.6]};
  114.     if(_unitSide isEqualTo east) exitWith {[0.8,0,0,0.6]};
  115.     if(_unitSide isEqualTo resistance) exitWith {[0,0.8,0,0.6]};
  116.     if(_unitSide isEqualTo civilian) exitWith {[0.5,0,0.8,0.6]};
  117.  
  118.     [0.5,0.5,0.5,0.6];
  119. };
  120.  
  121. private _playersList = {
  122.     private _unitsArr = playableUnits - [];
  123.     private _listDataArr = _unitsArr apply {
  124.         // Формируем код для конкретного игрока
  125.         private _tempDataCode = format[_codeForTransferMoney,netId _x];
  126.         [
  127.             (_x getVariable ['realname',name _x]),
  128.             _x call _getSideColor,
  129.             {true},
  130.             {true},
  131.             // Трансформируем с помощью макроса в код
  132.             STRTOCODE(_tempDataCode)
  133.         ]
  134.     };
  135.    
  136.     _listDataArr
  137. };
  138.  
  139. private _codeForTransferToGang = format["
  140.     private _value = atmCurrentPadNum;
  141.     if (_value <= 0) exitWith {};
  142.     if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
  143.  
  144.     %2 = %2 - _value;
  145.  
  146.     private _gangGroup = groupFromNetId = '%1';
  147.     private _gangName = _gangGroup getVariable ['gang_name',''];
  148.     private _gangMoney = _gangGroup getVariable ['gang_bank',0];
  149.  
  150.     _gangGroup setVariable ['gang_bank',(_gangMoney + _value),true];
  151.  
  152.     hint ('You have transferred ' + str _gangName + ' for the amount of ' + (_value toFixed 0));
  153.     [6] call SOCK_fnc_updatePartial;
  154.     [0,_gangGroup] remoteExecCall ['TON_fnc_updateGang',2];
  155. ","%1",_bankMoney];
  156.  
  157. private _groupList = {
  158.     private _unitsArr = allGroups;
  159.     private _listDataArr = [];
  160.     {
  161.         if((_x getVariable ["gang_id",-1]) > 0) then {
  162.             private _tempDataCode = format[_codeForTransferToGang,netId _x];
  163.             _listDataArr pushBack [
  164.                 (_x getVariable ['gang_name','UNKNOWN']),
  165.                 _x call _getSideColor,
  166.                 {true},
  167.                 {true},
  168.                 STRTOCODE(_tempDataCode)
  169.             ];
  170.         };
  171.     } forEach _unitsArr;
  172.    
  173.     _listDataArr
  174. };
  175. //--------------------END--------------------
  176.  
  177. private _generalCfg = [
  178.     ["WITHDRAW",[0,0.8,0,0.6],{true},{},STRTOCODE(_codeForWithdrawMoney)],
  179.     ["DEPOSIT",[0.8,0,0,0.6],{true},{},STRTOCODE(_codeForDepositMoney)],
  180.     // Example
  181.     [
  182.         "TRANSFER",
  183.         [0.8,0.8,0,0.6],
  184.         {true},
  185.         {},
  186.         // This construction is required, so that all fucntions are within the same scope.
  187.         // After each click, this code will be executed. This is necessary in order to dynamically update the information.
  188.         // The given string code will retun the included array
  189.         format["
  190.             private _codeForTransferMoney = %1;
  191.             private _getSideColor = %2;
  192.             call %3;
  193.         ",str _codeForTransferMoney,_getSideColor,_playersList]
  194.  
  195.         /* This is how it will look in the compiled version.
  196.             "[
  197.                 [
  198.                     'Winter',
  199.                     [0,0,0.8,0.6],
  200.                     {true},
  201.                     {},
  202.                     {
  203.                         private _value = atmCurrentPadNum;
  204.                         if (_value <= 0) exitWith {};
  205.                         if (_value > life_atmbank) exitWith {
  206.                             hint localize 'STR_ATM_NotEnoughFunds'
  207.                         };
  208.                         private _tax = _value * getNumber(missionConfigFile >> 'Life_Settings' >> 'bank_transferTax');
  209.                         if ((_value + _tax) > life_atmbank) exitWith {
  210.                             hint format[localize 'STR_ATM_SentMoneyFail', _value, _tax]
  211.                         };
  212.  
  213.                         life_atmbank = life_atmbank - (_value + _tax);
  214.                         private _unit = objectFromNetId '2:762';
  215.                         [_value, profileName] remoteExecCall['life_fnc_wireTransfer', _unit];
  216.  
  217.                         [1] call SOCK_fnc_updatePartial;
  218.                         hint format[localize 'STR_ATM_SentMoneySuccess', _value toFixed 0, _unit getVariable['realname', name _unit], _tax toFixed 0];
  219.                     }
  220.                 ]
  221.             ]"
  222.         */
  223.     ],
  224.     [
  225.         "TO GANG",
  226.         [0.6,0.6,0.6,0.6],
  227.         {true},
  228.         {},
  229.         format["
  230.             private _codeForTransferToGang = %1;
  231.             private _getSideColor = %2;
  232.             call %3;
  233.         ",str _codeForTransferToGang,_getSideColor,_groupList]
  234.     ]
  235. ];
  236.  
  237. // The condition that will be checked prior to opening the menu, the return value must be boolean
  238. private _conditionForOpenAtm = {
  239.     private _return = false;
  240.     if(getNumber(missionConfigFile >> "Life_Settings" >> "global_ATM") isEqualTo 1) then {
  241.         if((call life_fnc_nearATM) && {!dialog}) then {
  242.             _return = true;
  243.         };
  244.     };
  245.  
  246.     _return
  247. };
  248.  
  249. // The code that will be executed after closing the menu
  250. // Example {[6] call SOCK_fnc_updatePartial;}
  251. private _closeButtonCode = {};
  252.  
  253.  
  254. comment "DONT KNOW DONT TOUCH";
  255. call {
  256.     if(_command isEqualTo "MenuList") exitWith {
  257.         _result = _generalCfg;
  258.     };
  259.  
  260.     if(_command isEqualTo "Money") exitWith {
  261.         _result = [STRTOCODE(_cashMoney),STRTOCODE(_bankMoney)];
  262.     };
  263.  
  264.     if(_command isEqualTo "Open") exitWith {
  265.         _result = _conditionForOpenAtm;
  266.     };
  267.  
  268.     if(_command isEqualTo "Close") exitWith {
  269.         _result = _closeButtonCode;
  270.     };
  271. };
  272.  
  273. _result
RAW Paste Data