Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CODETOSTR(code) (code call {_this = str _this;_this select [1,(count _this) - 2]})
- #define STRTOCODE(code) (compile code)
- /*
- File: fn_dynamicAtmConfig.sqf
- Function: win_fnc_dynamicAtmConfig
- Author: Winter
- Description:
- dynamic config for ATM menu
- _command
- MenuList
- Money
- Open
- Close
- Warning if you are not sure:
- Please don't change the name of the variables
- Follow the structures presented in the examples to avoid any issues.
- */
- params [
- ["_command","",[""]]
- ];
- private _result = [];
- if(_command isEqualTo "") exitWith {_result};
- /*
- Example
- private _generalCfg = [
- [
- "Bank name" - String - element name
- [1,0,0,1] - Array - element border color
- {true} - Code - condition for viewing, return value boolean
- {hint "1"} - Code - run code after click element
- {hint "2"} - Code - run code after click "Accept" button
- ],
- //Or after a clcik on an element, we need to return a list of other elements
- [
- "Bank name" - String - element name
- [1,0,0,1] - Array - element border color
- {true} - Code - condition for viewing, return value boolean
- {hint "1"} - Code - run code after click element
- "[
- [
- "Bank name" - String - element name
- [1,0,0,1] - Array - element border color
- {true} - Code - condition for viewing, return value boolean
- {hint "1"} - Code - run code after click element
- {hint "2"} - Code - run code after click "Accept" button
- ],
- [...],
- [...]
- ]" - String code - the returning value is an array that consists of elements that as per the first example
- ],
- [...],
- [...],
- [...]
- ];
- */
- // Your money variables
- private _bankMoney = "life_atmbank";
- private _cashMoney = "life_cash";
- //-----------Example Code for Cfg------------
- private _codeForWithdrawMoney = format["
- private _value = atmCurrentPadNum;
- if (_value <= 0) exitWith {};
- if (_value > %1) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
- %2 = %2 + _value;
- %1 = %1 - _value;
- [6] call SOCK_fnc_updatePartial;
- hint format [localize 'STR_ATM_WithdrawSuccess',_value toFixed 0];
- ",_bankMoney,_cashMoney];
- private _codeForDepositMoney = format["
- private _value = atmCurrentPadNum;
- if (_value <= 0) exitWith {};
- if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughCash'};
- %2 = %2 - _value;
- %1 = %1 + _value;
- [6] call SOCK_fnc_updatePartial;
- hint format [localize 'STR_ATM_DepositSuccess',_value toFixed 0];
- ",_bankMoney,_cashMoney];
- private _codeForTransferMoney = format["
- private _value = atmCurrentPadNum;
- if (_value <= 0) exitWith {};
- if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
- private _tax = _value * getNumber(missionConfigFile >> 'Life_Settings' >> 'bank_transferTax');
- if ((_value + _tax) > %2) exitWith {hint format [localize 'STR_ATM_SentMoneyFail',_value,_tax]};
- %2 = %2 - (_value + _tax);
- private _unit = objectFromNetId '%1';
- [_value,profileName] remoteExecCall ['life_fnc_wireTransfer',_unit];
- [1] call SOCK_fnc_updatePartial;
- hint format [localize 'STR_ATM_SentMoneySuccess',_value toFixed 0,_unit getVariable ['realname',name _unit],_tax toFixed 0];
- ","%1",_bankMoney];
- private _getSideColor = {
- private _unitSide = side _this;
- if(_unitSide isEqualTo west) exitWith {[0,0,0.8,0.6]};
- if(_unitSide isEqualTo east) exitWith {[0.8,0,0,0.6]};
- if(_unitSide isEqualTo resistance) exitWith {[0,0.8,0,0.6]};
- if(_unitSide isEqualTo civilian) exitWith {[0.5,0,0.8,0.6]};
- [0.5,0.5,0.5,0.6];
- };
- private _playersList = {
- private _unitsArr = playableUnits - [];
- private _listDataArr = _unitsArr apply {
- // Формируем код для конкретного игрока
- private _tempDataCode = format[_codeForTransferMoney,netId _x];
- [
- (_x getVariable ['realname',name _x]),
- _x call _getSideColor,
- {true},
- {true},
- // Трансформируем с помощью макроса в код
- STRTOCODE(_tempDataCode)
- ]
- };
- _listDataArr
- };
- private _codeForTransferToGang = format["
- private _value = atmCurrentPadNum;
- if (_value <= 0) exitWith {};
- if (_value > %2) exitWith {hint localize 'STR_ATM_NotEnoughFunds'};
- %2 = %2 - _value;
- private _gangGroup = groupFromNetId = '%1';
- private _gangName = _gangGroup getVariable ['gang_name',''];
- private _gangMoney = _gangGroup getVariable ['gang_bank',0];
- _gangGroup setVariable ['gang_bank',(_gangMoney + _value),true];
- hint ('You have transferred ' + str _gangName + ' for the amount of ' + (_value toFixed 0));
- [6] call SOCK_fnc_updatePartial;
- [0,_gangGroup] remoteExecCall ['TON_fnc_updateGang',2];
- ","%1",_bankMoney];
- private _groupList = {
- private _unitsArr = allGroups;
- private _listDataArr = [];
- {
- if((_x getVariable ["gang_id",-1]) > 0) then {
- private _tempDataCode = format[_codeForTransferToGang,netId _x];
- _listDataArr pushBack [
- (_x getVariable ['gang_name','UNKNOWN']),
- _x call _getSideColor,
- {true},
- {true},
- STRTOCODE(_tempDataCode)
- ];
- };
- } forEach _unitsArr;
- _listDataArr
- };
- //--------------------END--------------------
- private _generalCfg = [
- ["WITHDRAW",[0,0.8,0,0.6],{true},{},STRTOCODE(_codeForWithdrawMoney)],
- ["DEPOSIT",[0.8,0,0,0.6],{true},{},STRTOCODE(_codeForDepositMoney)],
- // Example
- [
- "TRANSFER",
- [0.8,0.8,0,0.6],
- {true},
- {},
- // This construction is required, so that all fucntions are within the same scope.
- // After each click, this code will be executed. This is necessary in order to dynamically update the information.
- // The given string code will retun the included array
- format["
- private _codeForTransferMoney = %1;
- private _getSideColor = %2;
- call %3;
- ",str _codeForTransferMoney,_getSideColor,_playersList]
- /* This is how it will look in the compiled version.
- "[
- [
- 'Winter',
- [0,0,0.8,0.6],
- {true},
- {},
- {
- private _value = atmCurrentPadNum;
- if (_value <= 0) exitWith {};
- if (_value > life_atmbank) exitWith {
- hint localize 'STR_ATM_NotEnoughFunds'
- };
- private _tax = _value * getNumber(missionConfigFile >> 'Life_Settings' >> 'bank_transferTax');
- if ((_value + _tax) > life_atmbank) exitWith {
- hint format[localize 'STR_ATM_SentMoneyFail', _value, _tax]
- };
- life_atmbank = life_atmbank - (_value + _tax);
- private _unit = objectFromNetId '2:762';
- [_value, profileName] remoteExecCall['life_fnc_wireTransfer', _unit];
- [1] call SOCK_fnc_updatePartial;
- hint format[localize 'STR_ATM_SentMoneySuccess', _value toFixed 0, _unit getVariable['realname', name _unit], _tax toFixed 0];
- }
- ]
- ]"
- */
- ],
- [
- "TO GANG",
- [0.6,0.6,0.6,0.6],
- {true},
- {},
- format["
- private _codeForTransferToGang = %1;
- private _getSideColor = %2;
- call %3;
- ",str _codeForTransferToGang,_getSideColor,_groupList]
- ]
- ];
- // The condition that will be checked prior to opening the menu, the return value must be boolean
- private _conditionForOpenAtm = {
- private _return = false;
- if(getNumber(missionConfigFile >> "Life_Settings" >> "global_ATM") isEqualTo 1) then {
- if((call life_fnc_nearATM) && {!dialog}) then {
- _return = true;
- };
- };
- _return
- };
- // The code that will be executed after closing the menu
- // Example {[6] call SOCK_fnc_updatePartial;}
- private _closeButtonCode = {};
- comment "DONT KNOW DONT TOUCH";
- call {
- if(_command isEqualTo "MenuList") exitWith {
- _result = _generalCfg;
- };
- if(_command isEqualTo "Money") exitWith {
- _result = [STRTOCODE(_cashMoney),STRTOCODE(_bankMoney)];
- };
- if(_command isEqualTo "Open") exitWith {
- _result = _conditionForOpenAtm;
- };
- if(_command isEqualTo "Close") exitWith {
- _result = _closeButtonCode;
- };
- };
- _result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement