fn_respawnMenuInventory.sqf 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //Tweaked by Rarek [AW] to enable role assignment
  2. //TO-DO: Make selected value check show status before assigning role
  3. disableserialization;
  4. _unit = [_this,0,objnull,[objnull]] call bis_fnc_param;
  5. _respawnDelay = [_this,3,0,[0]] call bis_fnc_param;
  6. if (!alive _unit) then {
  7. if (playerrespawntime < 1 || !isplayer _unit) exitwith {};
  8. if (simulationenabled _unit) then {
  9. if (playerrespawntime < 3) then {setplayerrespawntime (playerrespawntime + 3);};
  10. sleep 1.9;
  11. cutText ["","black out",0.5];
  12. sleep 1;
  13. cutText ["","black in"];
  14. };
  15. ///////////////////////////////////////////////////////////////////////////////////////////
  16. //--- onPlayerKilled
  17. ///////////////////////////////////////////////////////////////////////////////////////////
  18. [
  19. "Select Loadout",
  20. {
  21. scriptname "BIS_fnc_respawnMenuInventory";
  22. _fnc_scriptName = "BIS_fnc_respawnMenuInventory";
  23. disableserialization;
  24. _mode = _this select 0;
  25. _ctrlListBackground = _this select 1;
  26. _ctrlList = _this select 2;
  27. _ctrlContentBackground = _this select 3;
  28. _ctrlContentGroup = _this select 4;
  29. _ctrlContent = _this select 5;
  30. _ctrlMap = _this select 6;
  31. switch _mode do {
  32. case "init": {
  33. _ctrlMap ctrlsetfade 1;
  34. _ctrlMap ctrlcommit 0;
  35. BIS_fnc_respawnMenuPosition_inventories = [];
  36. };
  37. case "select": {
  38. if (lbsize _ctrlList == 0) exitwith {};
  39. _selected = _ctrlList lbdata lbcursel _ctrlList;
  40. if (_selected == missionnamespace getvariable ["BIS_fnc_respawnMenuInventory_selected",""]) exitwith {};
  41. if (_selected == "") then {
  42. _text = "<t size='3' shadow='0' color='#33ffffff'> ? </t>???<t align='right'>?</t><br />";
  43. _ctrlContent ctrlsetstructuredtext parsetext (_text + _text + _text + _text + _text);
  44. _ctrlContent call bis_fnc_ctrlFitToTextHeight;
  45. } else {
  46. _varName = "BIS_fnc_respawnMenuInventory_" + _selected;
  47. _var = missionnamespace getvariable _varName;
  48. if !(isnil {_var}) then {
  49. _text = _var select 2;
  50. _ctrlContent ctrlsetstructuredtext _text;
  51. _ctrlContent call bis_fnc_ctrlFitToTextHeight;
  52. };
  53. };
  54. BIS_fnc_respawnMenuInventory_selected = _selected;
  55. };
  56. case "update": {
  57. _selected = _ctrlList lbdata lbcursel _ctrlList;
  58. if (_selected == "") then {_selected = missionnamespace getvariable ["BIS_fnc_respawnMenuInventory_selected",""];};
  59. _respawnInventories = player call bis_fnc_getRespawnInventories;
  60. //--- Exit if the array didn't change
  61. if (str _respawnInventories == str (missionnamespace getvariable ["BIS_fnc_respawnMenuPosition_inventories",[]])) exitwith {};
  62. BIS_fnc_respawnMenuPosition_inventories = _respawnInventories;
  63. if (count _respawnInventories > 0) then {
  64. lbclear _ctrlList;
  65. if (count _respawnInventories > 1) then {
  66. _lbAdd = _ctrlList lbAdd format ["<%1>",localize "STR_A3_BIS_fnc_respawnMenuInventory_random"];
  67. _ctrlList lbsetdata [_lbAdd,""];
  68. };
  69. _cursel = 0;
  70. {
  71. _cfg = missionconfigfile >> "cfgrespawninventory" >> _x;
  72. if (isclass _cfg) then {
  73. _varName = "BIS_fnc_respawnMenuInventory_" + _x;
  74. _var = missionnamespace getvariable _varName;
  75. if (isnil {_var}) then {
  76. //--- Create loadout preview
  77. _displayName = gettext (_cfg >> "displayName");
  78. _icon = gettext (_cfg >> "icon");
  79. //--- Get CfgVehicles class
  80. _vehicle = gettext (_cfg >> "vehicle");
  81. if (_vehicle != "") then {
  82. _cfg = configfile >> "cfgvehicles" >> _vehicle;
  83. if (_displayName == "") then {_displayName = _cfg call bis_fnc_displayName;};
  84. if (_icon == "") then {_icon = gettext (_cfg >> "icon");};
  85. };
  86. //--- Load icon
  87. _icon = _icon call bis_fnc_textureVehicleIcon;
  88. if (_icon == "") then {_icon = "#(argb,8,8,3)color(0,0,0,0)";};
  89. //--- Parse description
  90. _cfgWeapons = configfile >> "CfgWeapons";
  91. _cfgMagazines = configfile >> "CfgMagazines";
  92. _cfgVehicles = configfile >> "CfgVehicles";
  93. _cfgGoggles = configfile >> "CfgGoggles";
  94. _itemData = {
  95. _itemCfg = _this select 0;
  96. _itemCount = _this select 1;
  97. if (isclass _itemCfg) then {
  98. _itemName = _itemCfg call bis_fnc_displayName;
  99. _picture = gettext (_itemCfg >> "picture");
  100. _text = _text + format [
  101. "<img image='%1' size='3' shadow='0' /> %2<t align='right'>%3</t><br />",
  102. _picture,
  103. _itemName,
  104. _itemCount
  105. ];
  106. };
  107. };
  108. _drawCategory = {
  109. _text = _text + "<br /><br />";
  110. };
  111. _weaponData = {
  112. _cfgWeapon = _cfgWeapons >> (_this select 0);
  113. if (isclass _cfgWeapon) then {
  114. [_cfgWeapon,1] call _itemData;
  115. {
  116. [_cfgWeapons >> _x,1] call _itemData;
  117. } foreach (_this select 1);
  118. {
  119. _magazineID = _magazineTypes find (tolower _x);
  120. if (_magazineID >= 0) then {
  121. [_cfgMagazines >> _x,_magazineCounts select _magazineID] call _itemData;
  122. _magazineTypes set [_magazineID,""];
  123. };
  124. } foreach getarray (_cfgWeapon >> "magazines");
  125. [] call _drawCategory;
  126. };
  127. };
  128. _filterArray = {
  129. _input = _this select 0;
  130. _outputTypes = _this select 1;
  131. _outputCounts = _this select 2;
  132. while {count _input > 0} do {
  133. _item = _input select 0;
  134. _outputTypes set [count _outputTypes,tolower _item];
  135. _outputCounts set [count _outputCounts,{_item == _x} count _input];
  136. _input = _input - [_item];
  137. };
  138. _input
  139. };
  140. _text = "";
  141. _previewObject = (typeof player) createvehiclelocal [10,10,10];
  142. [_previewObject,_cfg] call bis_fnc_loadInventory;
  143. _magazines = getarray (_cfg >> "magazines");
  144. _magazineTypes = [];
  145. _magazineCounts = [];
  146. [_magazines,_magazineTypes,_magazineCounts] call _filterArray;
  147. [primaryweapon _previewObject,primaryweaponitems _previewObject] call _weaponData;
  148. [secondaryweapon _previewObject,secondaryweaponitems _previewObject] call _weaponData;
  149. [handgunweapon _previewObject,handgunitems _previewObject] call _weaponData;
  150. {
  151. [_cfgMagazines >> _x,_magazineCounts select _foreachindex] call _itemData;
  152. } foreach _magazineTypes;
  153. [] call _drawCategory;
  154. [_cfgWeapons >> uniform _previewObject,1] call _itemData;
  155. [_cfgWeapons >> vest _previewObject,1] call _itemData;
  156. [_cfgVehicles >> backpack _previewObject,1] call _itemData;
  157. [_cfgWeapons >> headgear _previewObject,1] call _itemData;
  158. [_cfgGoggles >> goggles _previewObject,1] call _itemData;
  159. [] call _drawCategory;
  160. _assignedItems = assignedItems _previewObject;
  161. _assignedItems = _assignedItems - [headgear _previewObject,goggles _previewObject];
  162. _assignedItemsTypes = [];
  163. _assignedItemsCounts = [];
  164. [_assignedItems,_assignedItemsTypes,_assignedItemsCounts] call _filterArray;
  165. {
  166. [_cfgWeapons >> _x,_assignedItemsCounts select _foreachindex] call _itemData;
  167. } foreach _assignedItemsTypes;
  168. _items = items _previewObject;
  169. _items = _items - _magazines;
  170. _itemsTypes = [];
  171. _itemsCounts = [];
  172. [_items,_itemsTypes,_itemsCounts] call _filterArray;
  173. {
  174. [_cfgWeapons >> _x,_itemsCounts select _foreachindex] call _itemData;
  175. } foreach _itemsTypes;
  176. _var = [_displayName,_icon,parsetext _text];
  177. missionnamespace setvariable [_varName,_var];
  178. };
  179. _displayName = _var select 0;
  180. _icon = _var select 1;
  181. _lbAdd = _ctrlList lbadd _displayName;
  182. _ctrlList lbsetpicture [_lbAdd,_icon];
  183. _ctrlList lbsetdata [_lbAdd,_x];
  184. if (_x == _selected) then {_cursel = _lbAdd;};
  185. };
  186. } foreach _respawnInventories;
  187. if (_cursel != lbcursel _ctrlList) then {
  188. BIS_fnc_respawnMenuInventory_selected = "";
  189. _ctrlList lbsetcursel _cursel;
  190. };
  191. } else {
  192. ["No respawn inventories found"] call bis_fnc_error;
  193. };
  194. };
  195. };
  196. }
  197. ] call bis_fnc_showRespawnMenu;
  198. } else {
  199. ///////////////////////////////////////////////////////////////////////////////////////////
  200. //--- onPlayerRespawn
  201. ///////////////////////////////////////////////////////////////////////////////////////////
  202. //--- Player - assign selected inventory
  203. _selected = if (isplayer _unit) then {missionnamespace getvariable ["BIS_fnc_respawnMenuInventory_selected",""]} else {""};
  204. if (_selected == "") then {
  205. _respawnInventories = (_unit call bis_fnc_getRespawnInventories);
  206. _selected = if (count _respawnInventories > 0) then {
  207. _respawnInventories call bis_fnc_selectrandom
  208. } else {
  209. ["No respawn inventories found"] call bis_fnc_error;
  210. ""
  211. };
  212. };
  213. _cfg = missionconfigfile >> "cfgrespawninventory" >> _selected;
  214. if (isclass _cfg) then {
  215. _vehicle = gettext (_cfg >> "vehicle");
  216. if (_vehicle != "") then {_cfg = _vehicle;};
  217. [_unit,_cfg] call bis_fnc_loadInventory;
  218. if (vehicle _unit == _unit) then {_unit switchmove "";};
  219. _unit setVariable ["role", _selected, true];
  220. };
  221. //--- Reset the respawn delay
  222. if (isplayer _unit) then {
  223. setplayerrespawntime _respawnDelay;
  224. };
  225. };