Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.06 KB | None | 0 0
  1. #include "..\..\script_macros.hpp"
  2. /*
  3.     File: fn_processAction.sqf
  4.     Author: Bryan "Tonic" Boardwine
  5.     Modified : NiiRoZz
  6.  
  7.     Description:
  8.     Master handling for processing an item.
  9.     NiiRoZz : Added multiprocess
  10. */
  11. private ["_newItemWeight","_oldItemWeight","_hasLicense","_itemName","_oldVal","_ui","_progress","_pgText","_cP","_materialsRequired","_materialsGiven","_noLicenseCost","_text","_filter","_totalConversions","_minimumConversions"];
  12. params [
  13.     ["_vendor",objNull,[objNull]],
  14.     "",
  15.     "",
  16.     ["_type","",[""]]
  17. ];
  18. //Error check
  19. if (isNull _vendor || _type isEqualTo "" || (player distance _vendor > 10)) exitWith {};
  20. life_action_inUse = true;//Lock out other actions during processing.
  21.  
  22. if (isClass (missionConfigFile >> "ProcessAction" >> _type)) then {
  23.     _filter = false;
  24.     _materialsRequired = M_CONFIG(getArray,"ProcessAction",_type,"MaterialsReq");
  25.     _materialsGiven = M_CONFIG(getArray,"ProcessAction",_type,"MaterialsGive");
  26.     _noLicenseCost = M_CONFIG(getNumber,"ProcessAction",_type,"NoLicenseCost");
  27.     _text = M_CONFIG(getText,"ProcessAction",_type,"Text");
  28. } else {_filter = true;};
  29.  
  30. if (_filter) exitWith {life_action_inUse = false;};
  31.  
  32. _itemInfo = [_materialsRequired,_materialsGiven,_noLicenseCost,(localize format ["%1",_text])];
  33. if (count _itemInfo isEqualTo 0) exitWith {life_action_inUse = false;};
  34.  
  35. //Setup vars.
  36. _itemInfo params ["_oldItem","_newItem","_cost","_upp"];
  37. _exit = false;
  38. if (count _oldItem isEqualTo 0) exitWith {life_action_inUse = false;};
  39.  
  40. _totalConversions = [];
  41. {
  42.     _var = ITEM_VALUE(_x select 0);
  43.     if (_var isEqualTo 0) exitWith {_exit = true;};
  44.     if (_var < (_x select 1)) exitWith {_exit = true;};
  45.     _totalConversions pushBack (floor (_var/(_x select 1)));
  46. } forEach _oldItem;
  47.  
  48. if (_exit) exitWith {life_is_processing = false; hint localize "STR_NOTF_NotEnoughItemProcess"; life_action_inUse = false;};
  49.  
  50. if (_vendor in [mari_processor,coke_processor,heroin_processor]) then {
  51.     _hasLicense = true;
  52. } else {
  53.     _hasLicense = LICENSE_VALUE(_type,"civ");
  54. };
  55.  
  56. _cost = _cost * (count _oldItem);
  57.  
  58. _minimumConversions = _totalConversions call BIS_fnc_lowestNum;
  59. _oldItemWeight = 0;
  60. {
  61.     _weight = ([_x select 0] call life_fnc_itemWeight) * (_x select 1);
  62.     _oldItemWeight = _oldItemWeight + _weight;
  63. } count _oldItem;
  64.  
  65. _newItemWeight = 0;
  66. {
  67.     _weight = ([_x select 0] call life_fnc_itemWeight) * (_x select 1);
  68.     _newItemWeight = _newItemWeight + _weight;
  69. } count _newItem;
  70.  
  71. _exit = false;
  72.  
  73. if (_newItemWeight > _oldItemWeight) then {
  74.     _netChange = _newItemWeight - _oldItemWeight;
  75.     _freeSpace = life_maxWeight - life_carryWeight;
  76.     if (_freeSpace < _netChange) exitWith {_exit = true;};
  77.     private _estConversions = floor(_freeSpace / _netChange);
  78.     if (_estConversions < _minimumConversions) then {
  79.         _minimumConversions = _estConversions;
  80.     };
  81. };
  82.  
  83. if (_exit) exitWith {hint localize "STR_Process_Weight"; life_is_processing = false; life_action_inUse = false;};
  84.  
  85. //Setup our progress bar.
  86. disableSerialization;
  87. "progressBar" cutRsc ["life_progress","PLAIN"];
  88. _ui = uiNamespace getVariable "life_progress";
  89. _progress = _ui displayCtrl 38201;
  90. _pgText = _ui displayCtrl 38202;
  91. _pgText ctrlSetText format ["%2 (1%1)...","%",_upp];
  92. _progress progressSetPosition 0.01;
  93. _cP = 0.01;
  94.  
  95. life_is_processing = true;
  96.  
  97. if (_hasLicense) then {
  98.     for "_i" from 0 to 1 step 0 do {
  99.         uiSleep  0.28;
  100.         _cP = _cP + (0.01 * (missionNamespace getVariable ["mav_ttm_var_processMultiplier", 1]));
  101.         _progress progressSetPosition _cP;
  102.         _pgText ctrlSetText format ["%3 (%1%2)...",round(_cP * 100),"%",_upp];
  103.         if (_cP >= 1) exitWith {};
  104.         if (player distance _vendor > 10) exitWith {};
  105.     };
  106.     if (player distance _vendor > 10) exitWith {hint localize "STR_Process_Stay"; "progressBar" cutText ["","PLAIN"]; life_is_processing = false; life_action_inUse = false;};
  107.  
  108.     {
  109.         [false,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  110.     } count _oldItem;
  111.  
  112.     {
  113.         [true,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  114.     } count _newItem;
  115.  
  116.     "progressBar" cutText ["","PLAIN"];
  117.     if (_minimumConversions isEqualTo (_totalConversions call BIS_fnc_lowestNum)) then {hint localize "STR_NOTF_ItemProcess";} else {hint localize "STR_Process_Partial";};
  118.     life_is_processing = false; life_action_inUse = false;
  119.     ["ItemProcessed"] spawn mav_ttm_fnc_addExp;
  120. } else {
  121.     if (CASH < _cost) exitWith {hint format [localize "STR_Process_License",[_cost] call life_fnc_numberText]; "progressBar" cutText ["","PLAIN"]; life_is_processing = false; life_action_inUse = false;};
  122.  
  123.     for "_i" from 0 to 1 step 0 do {
  124.         uiSleep  0.9;
  125.         _cP = _cP + (0.01 * (missionNamespace getVariable ["mav_ttm_var_processMultiplier", 1]));
  126.         _progress progressSetPosition _cP;
  127.         _pgText ctrlSetText format ["%3 (%1%2)...",round(_cP * 100),"%",_upp];
  128.         if (_cP >= 1) exitWith {};
  129.         if (player distance _vendor > 10) exitWith {};
  130.     };
  131.  
  132.     if (player distance _vendor > 10) exitWith {hint localize "STR_Process_Stay"; "progressBar" cutText ["","PLAIN"]; life_is_processing = false; life_action_inUse = false;};
  133.     if (CASH < _cost) exitWith {hint format [localize "STR_Process_License",[_cost] call life_fnc_numberText]; "progressBar" cutText ["","PLAIN"]; life_is_processing = false; life_action_inUse = false;};
  134.  
  135.     {
  136.         [false,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  137.     } count _oldItem;
  138.  
  139.     {
  140.         [true,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  141.     } count _newItem;
  142.  
  143.     "progressBar" cutText ["","PLAIN"];
  144.     if (_minimumConversions isEqualTo (_totalConversions call BIS_fnc_lowestNum)) then {hint localize "STR_NOTF_ItemProcess";} else {hint localize "STR_Process_Partial";};
  145.     CASH = CASH - _cost;
  146.     [0] call SOCK_fnc_updatePartial;
  147.     life_is_processing = false;
  148.     life_action_inUse = false;
  149.     ["ItemProcessed"] spawn mav_ttm_fnc_addExp;
  150. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement