Guest User

Untitled

a guest
Oct 19th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.33 KB | None | 0 0
  1. /*
  2. Author: Karel Moricky
  3.  
  4. Description:
  5. Add config defined inventory to an unit
  6.  
  7. Parameter(s):
  8. 0: OBJECT - object which will receive the loadout
  9. 1:
  10. CONFIG - link to CfgVehicles soldier or to CfgRespawnInventory
  11. ARRAY in format [NAMESPACE or GROUP or OBJECT,STRING] - inventory saved using BIS_fnc_saveInventory
  12. 2: ARRAY of STRINGs - config entries to be ignored (e.g. "weapons", "uniform", ...)
  13.  
  14. Returns:
  15. BOOL
  16. */
  17.  
  18. #define DEFAULT_SLOT 0
  19. #define MUZZLE_SLOT 101
  20. #define OPTICS_SLOT 201
  21. #define FLASHLIGHT_SLOT 301
  22. #define FIRSTAIDKIT_SLOT 401
  23. #define FINS_SLOT 501
  24. #define BREATHINGBOMB_SLOT 601
  25. #define NVG_SLOT 602
  26. #define GOGGLE_SLOT 603
  27. #define SCUBA_SLOT 604
  28. #define HEADGEAR_SLOT 605
  29. #define UNIFORM_SLOT 801// just for DEBUG
  30. #define FACTOR_SLOT 607
  31.  
  32. #define HMD_SLOT 616
  33. #define BINOCULAR_SLOT 617
  34. #define MEDIKIT_SLOT 619
  35. #define RADIO_SLOT 611
  36.  
  37. #define VEST_SLOT 701
  38. #define BACKPACK_SLOT 901
  39.  
  40. scopename _fnc_scriptName;
  41. private ["_cfg","_inventory","_isCfg","_blacklist"];
  42. _object = _this param [0,objnull,[objnull]];
  43.  
  44. _cfg = _this param [1,configfile,[configfile,"",[]]];
  45. _inventory = [];
  46. switch (typename _cfg) do {
  47. case (typename ""): {
  48. _cfg = configfile >> "cfgvehicles" >> _cfg;
  49. };
  50. case (typename []): {
  51. if ({typename _x != typename ""} count _cfg == 0) then {
  52. _cfg = [_cfg,configfile] call bis_fnc_configpath;
  53. } else {
  54. if (count _cfg == 1) then {
  55. _inventory = _cfg select 0;
  56. } else {
  57. private ["_namespace","_name","_data","_nameID"];
  58. _namespace = _cfg param [0,missionnamespace,[missionnamespace,grpnull,objnull]];
  59. _name = _cfg param [1,"",[""]];
  60. _data = _namespace getvariable ["bis_fnc_saveInventory_data",[]];
  61. _nameID = _data find _name;
  62. if (_nameID >= 0) then {
  63. _inventory = _data select (_nameID + 1);
  64. _cfg = [_inventory];
  65. } else {
  66. ["Inventory '%1' not found",_name] call bis_fnc_error; breakout _fnc_scriptName;
  67. };
  68. };
  69. };
  70. };
  71. };
  72. _isCfg = count _inventory == 0;
  73.  
  74. _blacklist = _this param [2,[],[[]]];
  75. {_blacklist set [_foreachindex,tolower _x];} foreach _blacklist;
  76.  
  77. //--- Send to where the object is local (weapons can be changed only locally)
  78. if !(local _object) exitwith {[[_object,_cfg,_blacklist],_fnc_scriptName,_object] call bis_fnc_mp; false};
  79.  
  80. //--- Process items
  81. private ["_items","_linkedItemsMisc","_vest","_headgear","_goggles"];
  82. _items = [];
  83. _linkedItemsMisc = [];
  84. _vest = "";
  85. _headgear = ""; //--- Added as assigned item
  86. _goggles = ""; //--- Added as assigned item
  87. if (_isCfg) then {
  88. _items = getarray (_cfg >> "items");
  89. _linkedItems = getarray (_cfg >> "linkedItems");
  90. _linkedItemsMisc = [];
  91. {
  92. _item = _x;
  93. if (typename _item == typename []) then {_item = _item call bis_fnc_selectrandom;};
  94.  
  95. if (isclass (configfile >> "cfgglasses" >> _item)) then {
  96. _goggles = _item;
  97. } else {
  98. private ["_type"];
  99. _type = getnumber (configfile >> "cfgweapons" >> _item >> "iteminfo" >> "type");
  100. switch _type do {
  101. case VEST_SLOT: {_vest = _item;};
  102. case HEADGEAR_SLOT: {_headgear = _item;};
  103. //case GOGGLE_SLOT: {_goggles = _item;};
  104. default {_linkedItemsMisc set [count _linkedItemsMisc,_item];};
  105. };
  106. };
  107. } foreach _linkedItems;
  108. } else {
  109. _vest = _inventory select 1 select 0;
  110. _headgear = _inventory select 3;
  111. _goggles = _inventory select 4;
  112. //_linkedItemsMisc = (_inventory select 9) + (_inventory select 6 select 1) + (_inventory select 7 select 1) + (_inventory select 8 select 1);
  113. //--- Do isNil check because weaponAccessories command can return nil
  114. _linkedItemsMisc = (_inventory select 9);
  115. if (!isnil {_inventory select 6 select 1}) then {_linkedItemsMisc = _linkedItemsMisc + (_inventory select 6 select 1)} else {_linkedItemsMisc = _linkedItemsMisc + ["","",""];};
  116. if (!isnil {_inventory select 7 select 1}) then {_linkedItemsMisc = _linkedItemsMisc + (_inventory select 7 select 1)} else {_linkedItemsMisc = _linkedItemsMisc + ["","",""];};
  117. if (!isnil {_inventory select 8 select 1}) then {_linkedItemsMisc = _linkedItemsMisc + (_inventory select 8 select 1)} else {_linkedItemsMisc = _linkedItemsMisc + ["","",""];};
  118. };
  119.  
  120. //--- Remove
  121. if !("uniform" in _blacklist) then {
  122. removeuniform _object;
  123. };
  124. if !("vest" in _blacklist) then {
  125. removevest _object;
  126. };
  127. if !("headgear" in _blacklist) then {
  128. removeheadgear _object;
  129. };
  130. if !("goggles" in _blacklist) then {
  131. removegoggles _object;
  132. };
  133. if !("backpack" in _blacklist) then {
  134. removebackpack _object;
  135. };
  136. if !("items" in _blacklist) then {
  137. removeallitems _object;
  138. };
  139. if !("linkeditems" in _blacklist) then
  140. {
  141. private["_headgear","_goggles"];
  142.  
  143. //store headgear & goggles to prevent uncontrolled removal
  144. _headgear = headgear _object;
  145. _goggles = goggles _object;
  146.  
  147. removeallassigneditems _object;
  148.  
  149. //re-store headgear & goggles
  150. if (_headgear != "") then
  151. {
  152. _object addheadgear _headgear;
  153. };
  154. if (_goggles != "") then
  155. {
  156. _object addgoggles _goggles;
  157. };
  158. };
  159. if !("weapons" in _blacklist) then {
  160. removeallweapons _object;
  161. };
  162. if !("transportMagazines" in _blacklist) then {
  163. if (count (getmagazinecargo _object select 0) > 0) then {clearmagazinecargoglobal _object;};
  164. };
  165. if !("transportWeapons" in _blacklist) then {
  166. if (count (getweaponcargo _object select 0) > 0) then {clearweaponcargoglobal _object;};
  167. };
  168. if !("transportItems" in _blacklist) then {
  169. if (count (getitemcargo _object select 0) > 0) then {clearitemcargoglobal _object;};
  170. };
  171.  
  172. //--- Add
  173. if !("uniform" in _blacklist) then {
  174. private ["_uniform"];
  175. _uniform = "";
  176. if (_isCfg) then {
  177. _uniform = _cfg >> "uniformClass";
  178. _uniform = if (isarray _uniform) then {(getarray _uniform) call bis_fnc_selectrandom} else {gettext _uniform};
  179. } else {
  180. _uniform = _inventory select 0 select 0;
  181. };
  182. if (_uniform != "") then {
  183. if (isclass (configfile >> "cfgWeapons" >> _uniform)) then {
  184. _object forceadduniform _uniform;
  185. } else {
  186. ["Uniform '%1' does not exist in CfgWeapons",_uniform] call bis_fnc_error;
  187. };
  188. };
  189. };
  190. if !("vest" in _blacklist) then {
  191. if (_vest != "") then {
  192. if (isclass (configfile >> "cfgWeapons" >> _vest)) then {
  193. _object addvest _vest;
  194. } else {
  195. ["Vest '%1' does not exist in CfgWeapons",_vest] call bis_fnc_error;
  196. };
  197. };
  198. };
  199. if !("headgear" in _blacklist) then {
  200. if (_headgear != "") then {
  201. if (isclass (configfile >> "cfgWeapons" >> _headgear)) then {
  202. _object addheadgear _headgear;
  203. } else {
  204. ["Headgear '%1' does not exist in CfgWeapons",_headgear] call bis_fnc_error;
  205. };
  206. };
  207. };
  208. if !("goggles" in _blacklist) then {
  209. if (_goggles != "") then {
  210. if (isclass (configfile >> "cfgGlasses" >> _goggles)) then {
  211. _object addgoggles _goggles;
  212. } else {
  213. ["Goggles '%1' does not exist in CfgGlasses",_goggles] call bis_fnc_error;
  214. };
  215. };
  216. };
  217. if !("backpack" in _blacklist) then {
  218. private ["_backpack"];
  219. _backpack = "";
  220. if (_isCfg) then {
  221. _backpack = _cfg >> "backpack";
  222. _backpack = if (isarray _backpack) then {(getarray _backpack) call bis_fnc_selectrandom} else {gettext _backpack};
  223. } else {
  224. _backpack = _inventory select 2 select 0;
  225. };
  226. if (_backpack == "") then {
  227. // Unit has no backpack
  228. removeBackpack _object;
  229. } else {
  230. if (isclass (configfile >> "cfgVehicles" >> _backpack)) then {
  231. _object addbackpack _backpack;
  232.  
  233. // Default backpacks have default loadouts. Must be cleared if not loaded from config.
  234. if (!(_isCfg)) then {clearAllItemsFromBackpack _object};
  235. } else {
  236. ["Backpack '%1' does not exist in CfgVehicles",_backpack] call bis_fnc_error;
  237. };
  238. };
  239. };
  240. if !("magazines" in _blacklist) then {
  241. if (_isCfg) then {
  242. private ["_magazines"];
  243. _magazines = getarray (_cfg >> "magazines");
  244. {
  245. if (_x != "") then {
  246. _magazine = _x;
  247. if (typename _magazine == typename []) then {_magazine = _magazine call bis_fnc_selectrandom;};
  248. _object addmagazine _magazine;
  249. };
  250. } foreach _magazines;
  251. } else {
  252. //--- Add magazines to be loaded in weapons by default
  253. if ({!isnil "_x"} count (_inventory select 6) > 2) then {
  254. {
  255. if (_x != "") then {_object addmagazine _x;};
  256. } foreach [_inventory select 6 select 2,_inventory select 7 select 2,_inventory select 8 select 2];
  257. };
  258. };
  259. };
  260. if !("weapons" in _blacklist) then {
  261. private ["_weapons"];
  262. _weapons = if (_isCfg) then {getarray (_cfg >> "weapons")} else {[_inventory select 5,_inventory select 6 select 0,_inventory select 7 select 0,_inventory select 8 select 0]};
  263. {
  264. if (_x != "") then {
  265. _weapon = _x;
  266. if (typename _weapon == typename []) then {_weapon = _weapon call bis_fnc_selectrandom;};
  267. _object addweapon _weapon;
  268. };
  269. } foreach _weapons;
  270. };
  271. if !(_isCfg) then {
  272. //--- Add container items (only after weapons were added together with their default magazines)
  273. if !("uniform" in _blacklist) then {{_object additemtouniform _x;} foreach (_inventory select 0 select 1);};
  274. if !("vest" in _blacklist) then {{_object additemtovest _x;} foreach (_inventory select 1 select 1);};
  275. if !("backpack" in _blacklist) then {{_object additemtobackpack _x;} foreach (_inventory select 2 select 1);};
  276. };
  277. if !("transportMagazines" in _blacklist) then {
  278. if (_isCfg) then {
  279. private ["_transportMagazines"];
  280. _transportMagazines = [];
  281. {
  282. _transportMagazines set [count _transportMagazines,[gettext (_x >> "magazine"),getnumber (_x >> "count")]];
  283. } foreach ([_cfg >> "transportMagazines"] call bis_fnc_subclasses);
  284. {
  285. if ((_x select 0) != "") then {
  286. _object addmagazinecargoglobal _x;
  287. };
  288. } foreach _transportMagazines;
  289. };
  290. };
  291. if !("items" in _blacklist) then {
  292. {
  293. if (_x != "") then {
  294. _object additem _x;
  295. };
  296. } foreach _items;
  297. };
  298. if !("linkeditems" in _blacklist) then {
  299. {
  300. if (_x != "") then {
  301. _object linkitem _x;
  302. _object addPrimaryWeaponItem _x;
  303. _object addSecondaryWeaponItem _x;
  304. _object addHandgunItem _x;
  305. };
  306. } foreach _linkedItemsMisc;
  307. };
  308. if !("transportWeapons" in _blacklist) then {
  309. if (_isCfg) then {
  310. private ["_transportWeapons"];
  311. _transportWeapons = [];
  312. {
  313. _transportWeapons set [count _transportWeapons,[gettext (_x >> "weapon"),getnumber (_x >> "count")]];
  314. } foreach ([_cfg >> "transportWeapons"] call bis_fnc_subclasses);
  315. {
  316. if ((_x select 0) != "") then {
  317. _object addweaponcargoglobal _x;
  318. };
  319. } foreach _transportWeapons;
  320. };
  321. };
  322. if !("transportItems" in _blacklist) then {
  323. if (_isCfg) then {
  324. private ["_transportItems"];
  325. _transportItems = [];
  326. {
  327. _transportItems set [count _transportItems,[gettext (_x >> "name"),getnumber (_x >> "count")]];
  328. } foreach ([_cfg >> "transportItems"] call bis_fnc_subclasses);
  329. {
  330. if ((_x select 0) != "") then {
  331. _object additemcargoglobal _x;
  332. };
  333. } foreach _transportItems;
  334. };
  335. };
  336. true
Add Comment
Please, Sign In to add comment