player2_dz

Untitled

May 16th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 7.73 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. Filename: fn_craftAction.sqf
  3. Author: George Thurston & TheOnlyLupo
  4. Description: The main handler for crafting items within the crafting system.
  5. ---------------------------------------------------------------------------*/
  6. /*---------------------------------------------------------------------------
  7. RPT Issue Reported:
  8.  
  9. 19:10:01 Error in expression <ter == "pammunition" && !(player canAdd _newItem) || currentWeapon player != "")>
  10. 19:10:01   Error position: <_newItem) || currentWeapon player != "")>
  11. 19:10:01   Error Undefined variable in expression: _newitem
  12.  
  13.  
  14.     So since it is undefined variable expression, we have to assume that somehow _newItem is being set to NIL
  15.     So how to fix this? We handle it.
  16.     We make sure the data we are using is validated.
  17.     How do we validate data? If statements galore.
  18.     Watch and learn boi, look for the //validate comments
  19.  
  20.     Okay also for safe practice we should declare our variables first as empty/default
  21.     look for the //declare comments
  22. ---------------------------------------------------------------------------*/
  23.  
  24. private["_dialog","_item","_itemInfo","_oldItem","_newItem","_upp","_itemName","_ui","_progress","_pgText","_cP","_allMaterial","_matsNeed","_invSize","_handledItem","_itemFilter","_backpackOldItems","_weight"];
  25. disableSerialization;
  26.  
  27. //declare
  28. _dialog = displayNull;
  29.  
  30. //get
  31. _dialog = findDisplay 666;
  32.  
  33. //validate
  34. if (isNull _dialog) exitWith { systemChat("Error with Item Crafting..."); diag_log("fn_craftAction:Error:Dialog Null"); };
  35. if((lbCurSel 669) == -1) exitWith
  36.     {hint localize "STR_ISTR_SelectItemFirst";
  37. };
  38.  
  39. //declare
  40. _item = "";
  41.  
  42. //get
  43. _item = lbData[669,(lbCurSel 669)];
  44.  
  45. //validate
  46. if (isNil '_item') exitWith { systemChat("Error with Item Crafting..."); diag_log("fn_craftAction:Error:Item Nil"); };
  47. if (typeName _item != typeName "plyr2") exitWith { systemChat("Error with Item Crafting..."); diag_log("fn_craftAction:Error:Item not string"); };
  48. if (_item == "") exitWith { systemChat("Error with Item Crafting..."); diag_log("fn_craftAction:Error:Item empty string"); };
  49.  
  50. _allMaterial = true;
  51. _itemFilter = lbData[673,(lbCurSel 673)];
  52. _matsNeed = 0;
  53. _config = [_itemFilter] call life_fnc_craftCfg;
  54.  
  55.  
  56. {   if(_item == _x select 0) then {
  57.         _matsNeed = _x select 1;
  58.         _invSize = count _matsNeed;
  59.         for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do {
  60.             _str = [_matsNeed select _i] call life_fnc_varToStr;
  61.             _matsNum = _matsNeed select _i+1;  
  62.                 if((missionNamespace getVariable (_matsNeed select _i)) < _matsNum) exitWith {_allMaterial = false;
  63.         };
  64.     }; 
  65. };
  66.  
  67. } foreach (_config);
  68. if(!_allMaterial) exitWith {hint localize "STR_PM_NoMaterial";
  69. };
  70.  
  71. //declare
  72. _newItem = "";
  73.  
  74. _oldItem = _matsNeed;
  75. _newItem = _item;
  76.  
  77. //Some checks
  78. if((count _matsNeed) == 0) exitWith {};
  79.  
  80. if(_itemFilter == "item") then
  81.     {   _weight = ([_item] call life_fnc_itemWeight);
  82.     };
  83.  
  84. if(_itemFilter == "item" && (life_carryWeight + _weight) > life_maxWeight) exitWith
  85.     {   hint localize "STR_NOTF_NoRoom";
  86.     };
  87.  
  88. if(_itemFilter == "pammunition" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  89.     {   hint localize "STR_NOTF_NoRoom";
  90.     };
  91.  
  92. if(_itemFilter == "rammunition" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  93.     {   hint localize "STR_NOTF_NoRoom";
  94.     };
  95.  
  96. if(_itemFilter == "pweapon" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  97.     {   hint localize "STR_NOTF_NoRoom";
  98.     };
  99.  
  100. if(_itemFilter == "rweapon" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  101.     {   hint localize "STR_NOTF_NoRoom";
  102.     };
  103.  
  104. if(_itemFilter == "attachments" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  105.     {   hint localize "STR_NOTF_NoRoom";
  106.     };
  107.  
  108. if(_itemFilter == "hidden" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  109.     {   hint localize "STR_NOTF_NoRoom";
  110.     };
  111.  
  112. if(_itemFilter == "gang" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  113.     {   hint localize "STR_NOTF_NoRoom";
  114.     };
  115.  
  116. if(_itemFilter == "gangattach" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  117.     {   hint localize "STR_NOTF_NoRoom";
  118.     };
  119.  
  120.  
  121.  
  122. if(_itemFilter == "item") then
  123.     {   _itemName = [_newItem] call life_fnc_varToStr;} else
  124.         {   _itemInfo = [_newItem] call life_fnc_fetchCfgDetails;
  125.  
  126. _itemName = _itemInfo select 1;
  127.  
  128. };
  129.  
  130. _upp = format["Crafting %1",_itemName];
  131. closeDialog 0;
  132.  
  133. //Setup our progress bar.
  134.  
  135. 5 cutRsc ["life_progress","PLAIN"];
  136. _ui = uiNameSpace getVariable "life_progress";
  137. _progress = _ui displayCtrl 38201;
  138. _pgText = _ui displayCtrl 38202;
  139. _pgText ctrlSetText format["%2 (1%1)...","%",_upp];
  140. _progress progressSetPosition 0.01;
  141. _cP = 0.01;
  142. _removeItemSuccess = true;
  143. _invSize = count _oldItem;
  144.  
  145. for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do
  146.     {   _handledItem = [_oldItem select _i,1] call life_fnc_varHandle;
  147.  
  148. if(!([false,_handledItem,_oldItem select _i+1] call life_fnc_handleInv)) exitWith {_removeItemSuccess = false;};
  149. };
  150.  
  151. if(!_removeItemSuccess) exitWith {5 cutText ["","PLAIN"];
  152. life_is_processing = false;};
  153.  
  154. [] call life_fnc_p_updateMenu;
  155.     life_is_processing = true;while{true} do{
  156.         sleep  0.3;
  157.         _cP = _cP + 0.01;
  158.         _progress progressSetPosition _cP;
  159.         _pgText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_upp];
  160.         if(_cP >= 1) exitWith {};
  161.     };
  162.  
  163. if(_itemFilter == "backpack") then{ if(backpack player == "") then{     player addBackpack _newItem;
  164.     }else{      hint localize "STR_CRAFT_AR_Backpack"; 
  165. life_is_processing = false; };};
  166.  
  167. if(_itemFilter == "attachments") then {
  168.     if(player canAdd _newItem) then {  
  169.     player addItem _newItem;
  170.     } else {       
  171.         if(currentWeapon player == "") then {
  172.             player addWeapon _newItem;
  173.         } else {
  174.                
  175. 5 cutText ["","PLAIN"];
  176.  
  177. if(_itemFilter == "item")
  178. then{  
  179. _handledItem = [_newItem,1]
  180. call life_fnc_varHandle;
  181. [true,_handledItem,1] call life_fnc_handleInv;};
  182.  
  183.  
  184. if(_itemFilter == "pweapon")
  185. then{  
  186. if(player canAdd _newItem)
  187. then{  
  188. player addItem _newItem;
  189. } else {       
  190. if(currentWeapon player == "")
  191. then{   player addWeapon _newItem;
  192. }else{     
  193. 5 cutText ["","PLAIN"];      
  194.  
  195. if(_itemFilter == "rweapon")
  196. then{  
  197. if(player canAdd _newItem)
  198. then{  
  199. player addItem _newItem;
  200. } else {       
  201. if(currentWeapon player == "")
  202. then{   player addWeapon _newItem;
  203. }else{     
  204. 5 cutText ["","PLAIN"];
  205.  
  206. if(_itemFilter == "rammunition")
  207. then{  
  208. if(player canAdd _newItem)
  209. then{  
  210. player addItem _newItem;
  211. } else {       
  212. if(currentWeapon player == "")
  213. then{   player addWeapon _newItem;
  214. }else{     
  215. 5 cutText ["","PLAIN"];
  216.  
  217. if(_itemFilter == "pammunition")
  218. then{  
  219. if(player canAdd _newItem)
  220. then{  
  221. player addItem _newItem;
  222. } else {       
  223. if(currentWeapon player == "")
  224. then{   player addWeapon _newItem;
  225. }else{     
  226. 5 cutText ["","PLAIN"];      
  227.  
  228. if(_itemFilter == "hidden")
  229. then{  
  230. if(player canAdd _newItem)
  231. then{  
  232. player addItem _newItem;
  233. } else {       
  234. if(currentWeapon player == "")
  235. then{   player addWeapon _newItem;
  236. }else{     
  237. 5 cutText ["","PLAIN"];
  238.  
  239. if(_itemFilter == "gang")
  240. then{  
  241. if(player canAdd _newItem)
  242. then{  
  243. player addItem _newItem;
  244. } else {       
  245. if(currentWeapon player == "")
  246. then{   player addWeapon _newItem;
  247. }else{     
  248. 5 cutText ["","PLAIN"];
  249.  
  250. if(_itemFilter == "gangattach")
  251. then{  
  252. if(player canAdd _newItem)
  253. then{  
  254. player addItem _newItem;
  255. } else {       
  256. if(currentWeapon player == "")
  257. then{   player addWeapon _newItem;
  258. }else{     
  259. 5 cutText ["","PLAIN"];
  260.  
  261.  
  262.  
  263.  
  264. for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do {             _handledItem = [_oldItem select _i,1] call life_fnc_varHandle;
  265. [true,_handledItem,_oldItem select _i+1] call life_fnc_handleInv;
  266. };         
  267. life_is_processing = false;    
  268. };  };
  269. };
  270. 5 cutText ["","PLAIN"];
  271. titleText[format[localize "STR_CRAFT_Process",_itemName],"PLAIN"];
  272. life_is_processing = false;
Advertisement
Add Comment
Please, Sign In to add comment