player2_dz

Untitled

May 16th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 7.82 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(format["fn_craftAction:Error:Item not string:%1",_item]); };
  48. if (_item == "") exitWith { systemChat("Error with Item Crafting..."); diag_log("fn_craftAction:Error:Item empty string"); };
  49.  
  50. //output
  51. diag_log(format["fn_craftAction:ItemData:%1", _item]);
  52.  
  53. _allMaterial = true;
  54. _itemFilter = lbData[673,(lbCurSel 673)];
  55. _matsNeed = 0;
  56. _config = [_itemFilter] call life_fnc_craftCfg;
  57.  
  58.  
  59. {   if(_item == _x select 0) then {
  60.         _matsNeed = _x select 1;
  61.         _invSize = count _matsNeed;
  62.         for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do {
  63.             _str = [_matsNeed select _i] call life_fnc_varToStr;
  64.             _matsNum = _matsNeed select _i+1;  
  65.                 if((missionNamespace getVariable (_matsNeed select _i)) < _matsNum) exitWith {_allMaterial = false;
  66.         };
  67.     }; 
  68. };
  69.  
  70. } foreach (_config);
  71. if(!_allMaterial) exitWith {hint localize "STR_PM_NoMaterial";
  72. };
  73.  
  74. //declare
  75. _newItem = "";
  76.  
  77. _oldItem = _matsNeed;
  78. _newItem = _item;
  79.  
  80. //Some checks
  81. if((count _matsNeed) == 0) exitWith {};
  82.  
  83. if(_itemFilter == "item") then
  84.     {   _weight = ([_item] call life_fnc_itemWeight);
  85.     };
  86.  
  87. if(_itemFilter == "item" && (life_carryWeight + _weight) > life_maxWeight) exitWith
  88.     {   hint localize "STR_NOTF_NoRoom";
  89.     };
  90.  
  91. if(_itemFilter == "pammunition" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  92.     {   hint localize "STR_NOTF_NoRoom";
  93.     };
  94.  
  95. if(_itemFilter == "rammunition" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  96.     {   hint localize "STR_NOTF_NoRoom";
  97.     };
  98.  
  99. if(_itemFilter == "pweapon" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  100.     {   hint localize "STR_NOTF_NoRoom";
  101.     };
  102.  
  103. if(_itemFilter == "rweapon" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  104.     {   hint localize "STR_NOTF_NoRoom";
  105.     };
  106.  
  107. if(_itemFilter == "attachments" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  108.     {   hint localize "STR_NOTF_NoRoom";
  109.     };
  110.  
  111. if(_itemFilter == "hidden" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  112.     {   hint localize "STR_NOTF_NoRoom";
  113.     };
  114.  
  115. if(_itemFilter == "gang" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  116.     {   hint localize "STR_NOTF_NoRoom";
  117.     };
  118.  
  119. if(_itemFilter == "gangattach" && !(player canAdd _newItem) || currentWeapon player != "") exitWith
  120.     {   hint localize "STR_NOTF_NoRoom";
  121.     };
  122.  
  123.  
  124.  
  125. if(_itemFilter == "item") then
  126.     {   _itemName = [_newItem] call life_fnc_varToStr;} else
  127.         {   _itemInfo = [_newItem] call life_fnc_fetchCfgDetails;
  128.  
  129. _itemName = _itemInfo select 1;
  130.  
  131. };
  132.  
  133. _upp = format["Crafting %1",_itemName];
  134. closeDialog 0;
  135.  
  136. //Setup our progress bar.
  137.  
  138. 5 cutRsc ["life_progress","PLAIN"];
  139. _ui = uiNameSpace getVariable "life_progress";
  140. _progress = _ui displayCtrl 38201;
  141. _pgText = _ui displayCtrl 38202;
  142. _pgText ctrlSetText format["%2 (1%1)...","%",_upp];
  143. _progress progressSetPosition 0.01;
  144. _cP = 0.01;
  145. _removeItemSuccess = true;
  146. _invSize = count _oldItem;
  147.  
  148. for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do
  149.     {   _handledItem = [_oldItem select _i,1] call life_fnc_varHandle;
  150.  
  151. if(!([false,_handledItem,_oldItem select _i+1] call life_fnc_handleInv)) exitWith {_removeItemSuccess = false;};
  152. };
  153.  
  154. if(!_removeItemSuccess) exitWith {5 cutText ["","PLAIN"];
  155. life_is_processing = false;};
  156.  
  157. [] call life_fnc_p_updateMenu;
  158.     life_is_processing = true;while{true} do{
  159.         sleep  0.3;
  160.         _cP = _cP + 0.01;
  161.         _progress progressSetPosition _cP;
  162.         _pgText ctrlSetText format["%3 (%1%2)...",round(_cP * 100),"%",_upp];
  163.         if(_cP >= 1) exitWith {};
  164.     };
  165.  
  166. if(_itemFilter == "backpack") then{ if(backpack player == "") then{     player addBackpack _newItem;
  167.     }else{      hint localize "STR_CRAFT_AR_Backpack"; 
  168. life_is_processing = false; };};
  169.  
  170. if(_itemFilter == "attachments") then {
  171.     if(player canAdd _newItem) then {  
  172.     player addItem _newItem;
  173.     } else {       
  174.         if(currentWeapon player == "") then {
  175.             player addWeapon _newItem;
  176.         } else {
  177.                
  178. 5 cutText ["","PLAIN"];
  179.  
  180. if(_itemFilter == "item")
  181. then{  
  182. _handledItem = [_newItem,1]
  183. call life_fnc_varHandle;
  184. [true,_handledItem,1] call life_fnc_handleInv;};
  185.  
  186.  
  187. if(_itemFilter == "pweapon")
  188. then{  
  189. if(player canAdd _newItem)
  190. then{  
  191. player addItem _newItem;
  192. } else {       
  193. if(currentWeapon player == "")
  194. then{   player addWeapon _newItem;
  195. }else{     
  196. 5 cutText ["","PLAIN"];      
  197.  
  198. if(_itemFilter == "rweapon")
  199. then{  
  200. if(player canAdd _newItem)
  201. then{  
  202. player addItem _newItem;
  203. } else {       
  204. if(currentWeapon player == "")
  205. then{   player addWeapon _newItem;
  206. }else{     
  207. 5 cutText ["","PLAIN"];
  208.  
  209. if(_itemFilter == "rammunition")
  210. then{  
  211. if(player canAdd _newItem)
  212. then{  
  213. player addItem _newItem;
  214. } else {       
  215. if(currentWeapon player == "")
  216. then{   player addWeapon _newItem;
  217. }else{     
  218. 5 cutText ["","PLAIN"];
  219.  
  220. if(_itemFilter == "pammunition")
  221. then{  
  222. if(player canAdd _newItem)
  223. then{  
  224. player addItem _newItem;
  225. } else {       
  226. if(currentWeapon player == "")
  227. then{   player addWeapon _newItem;
  228. }else{     
  229. 5 cutText ["","PLAIN"];      
  230.  
  231. if(_itemFilter == "hidden")
  232. then{  
  233. if(player canAdd _newItem)
  234. then{  
  235. player addItem _newItem;
  236. } else {       
  237. if(currentWeapon player == "")
  238. then{   player addWeapon _newItem;
  239. }else{     
  240. 5 cutText ["","PLAIN"];
  241.  
  242. if(_itemFilter == "gang")
  243. then{  
  244. if(player canAdd _newItem)
  245. then{  
  246. player addItem _newItem;
  247. } else {       
  248. if(currentWeapon player == "")
  249. then{   player addWeapon _newItem;
  250. }else{     
  251. 5 cutText ["","PLAIN"];
  252.  
  253. if(_itemFilter == "gangattach")
  254. then{  
  255. if(player canAdd _newItem)
  256. then{  
  257. player addItem _newItem;
  258. } else {       
  259. if(currentWeapon player == "")
  260. then{   player addWeapon _newItem;
  261. }else{     
  262. 5 cutText ["","PLAIN"];
  263.  
  264.  
  265.  
  266.  
  267. for [{_i=0},{_i<_invSize-1},{_i=_i+2}] do {             _handledItem = [_oldItem select _i,1] call life_fnc_varHandle;
  268. [true,_handledItem,_oldItem select _i+1] call life_fnc_handleInv;
  269. };         
  270. life_is_processing = false;    
  271. };  };
  272. };
  273. 5 cutText ["","PLAIN"];
  274. titleText[format[localize "STR_CRAFT_Process",_itemName],"PLAIN"];
  275. life_is_processing = false;
Add Comment
Please, Sign In to add comment