Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 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 ["_vendor","_type","_itemInfo","_oldItem","_newItemWeight","_newItem","_oldItemWeight","_cost","_upp","_hasLicense","_itemName","_oldVal","_ui","_progress","_pgText","_cP","_materialsRequired","_materialsGiven","_noLicenseCost","_text","_filter","_totalConversions","_minimumConversions","_gendarme"];
  12. _vendor = [_this,0,objNull,[objNull]] call BIS_fnc_param;
  13. _type = [_this,3,"",[""]] call BIS_fnc_param;
  14. //Error check
  15. if (isNull _vendor || _type isEqualTo "" || (player distance _vendor > 10)) exitWith {};
  16. life_action_inUse = true;//Lock out other actions during processing.
  17. _gendarme = west countSide playableUnits;
  18. if (_vendor in [mari_processor,coke_processor,heroin_processor] && _gendarme isEqualTo 0) exitWith {hint "Il n'y a pas assez de gendarmes pour traiter cette ressource."};
  19.  
  20. if (isClass (missionConfigFile >> "ProcessAction" >> _type)) then {
  21. _filter = false;
  22. _materialsRequired = M_CONFIG(getArray,"ProcessAction",_type,"MaterialsReq");
  23. _materialsGiven = M_CONFIG(getArray,"ProcessAction",_type,"MaterialsGive");
  24. _noLicenseCost = M_CONFIG(getNumber,"ProcessAction",_type,"NoLicenseCost");
  25. _text = M_CONFIG(getText,"ProcessAction",_type,"Text");
  26. } else {_filter = true;};
  27.  
  28. if (_filter) exitWith {life_action_inUse = false;};
  29.  
  30. _itemInfo = [_materialsRequired,_materialsGiven,_noLicenseCost,(localize format ["%1",_text])];
  31. if (count _itemInfo isEqualTo 0) exitWith {life_action_inUse = false;};
  32.  
  33. //Setup vars.
  34. _oldItem = _itemInfo select 0;
  35. _newItem = _itemInfo select 1;
  36. _cost = _itemInfo select 2;
  37. _upp = _itemInfo select 3;
  38. _exit = false;
  39. if (count _oldItem isEqualTo 0) exitWith {life_action_inUse = false;};
  40.  
  41. _totalConversions = [];
  42. {
  43. _var = ITEM_VALUE(_x select 0);
  44. if (_var isEqualTo 0) exitWith {_exit = true;};
  45. if (_var < (_x select 1)) exitWith {_exit = true;};
  46. _totalConversions pushBack (floor (_var/(_x select 1)));
  47. } forEach _oldItem;
  48.  
  49. if (_exit) exitWith {life_is_processing = false; hint localize "STR_NOTF_NotEnoughItemProcess"; life_action_inUse = false;};
  50.  
  51. if (_vendor in [mari_processor,coke_processor,heroin_processor]) then {
  52. _hasLicense = true;
  53. } else {
  54. _hasLicense = LICENSE_VALUE(_type,"civ");
  55. };
  56.  
  57. _cost = _cost * (count _oldItem);
  58.  
  59. _minimumConversions = _totalConversions call BIS_fnc_lowestNum;
  60. _oldItemWeight = 0;
  61. {
  62. _weight = ([_x select 0] call life_fnc_itemWeight) * (_x select 1);
  63. _oldItemWeight = _oldItemWeight + _weight;
  64. } count _oldItem;
  65.  
  66. _newItemWeight = 0;
  67. {
  68. _weight = ([_x select 0] call life_fnc_itemWeight) * (_x select 1);
  69. _newItemWeight = _newItemWeight + _weight;
  70. } count _newItem;
  71.  
  72. _exit = false;
  73.  
  74. if (_newItemWeight > _oldItemWeight) then {
  75. _netChange = _newItemWeight - _oldItemWeight;
  76. _freeSpace = life_maxWeight - life_carryWeight;
  77. if (_freeSpace < _netChange) exitWith {_exit = true;};
  78. private _estConversions = floor(_freeSpace / _netChange);
  79. if (_estConversions < _minimumConversions) then {
  80. _minimumConversions = _estConversions;
  81. };
  82. };
  83.  
  84. if (_exit) exitWith {hint localize "STR_Process_Weight"; life_is_processing = false; life_action_inUse = false;};
  85.  
  86. //Setup our progress bar.
  87. disableSerialization;
  88. "progressBar" cutRsc ["life_progress","PLAIN"];
  89. _ui = uiNamespace getVariable "life_progress";
  90. _progress = _ui displayCtrl 38201;
  91. _pgText = _ui displayCtrl 38202;
  92. _pgText ctrlSetText format ["%2 (1%1)...","%",_upp];
  93. _progress progressSetPosition 0.01;
  94. _cP = 0.01;
  95.  
  96. life_is_processing = true;
  97.  
  98. if (_hasLicense) then {
  99. for "_i" from 0 to 1 step 0 do {
  100. uiSleep 0.28;
  101. _cP = _cP + 0.01;
  102. _progress progressSetPosition _cP;
  103. _pgText ctrlSetText format ["%3 (%1%2)...",round(_cP * 100),"%",_upp];
  104. if (_cP >= 1) exitWith {};
  105. if (player distance _vendor > 10) exitWith {};
  106. };
  107. if (player distance _vendor > 10) exitWith {hint localize "STR_Process_Stay"; "progressBar" cutText ["","PLAIN"]; life_is_processing = false; life_action_inUse = false;};
  108.  
  109. {
  110. [false,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  111. } count _oldItem;
  112.  
  113. {
  114. [true,(_x select 0),((_x select 1)*(_minimumConversions))] call life_fnc_handleInv;
  115. } count _newItem;
  116.  
  117. "progressBar" cutText ["","PLAIN"];
  118. if (_minimumConversions isEqualTo (_totalConversions call BIS_fnc_lowestNum)) then {hint localize "STR_NOTF_ItemProcess";} else {hint localize "STR_Process_Partial";};
  119. life_is_processing = false; life_action_inUse = false;
  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;
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement