/*
 SET_WEAPONS_MENU.SQF © Pumpkin version 1.1 (appel par le "Swap_bpack_weapon.sqf")
 ------------------------------

 Créer une entrée de menu par arme; Rem: nécessité de balayer les armes du joueur, à cause des objets
 (preuves, plaques d'identité,...) considérés comme des armes

*/

if (Pumpkin_menu_primweapon != -1) then { player removeaction Pumpkin_menu_primweapon };
if (Pumpkin_menu_handweapon != -1) then { player removeaction Pumpkin_menu_handweapon };
if (Pumpkin_menu_scndweapon != -1) then { player removeaction Pumpkin_menu_scndweapon };
{
	_wpn = _x;
	_slot = getNumber (configFile >> "cfgWeapons" >> (format ["%1",_wpn]) >> "type");

	Switch (_slot) do {
		// Arme primaire
		case 1: {
			_wpnstored = getText (configFile >> "cfgWeapons" >> (format ["%1",_wpn]) >> "displayName");
			Pumpkin_menu_primweapon = player addAction [format["Arme %1 (sac à dos)",_wpnstored], "plr_respawn\Swap_bpack_weapon.sqf", _wpn, 0, false, true, "", "true"];
		};
		// Arme de poing
		case 2: {
			_wpnstored = getText (configFile >> "cfgWeapons" >> (format ["%1",_wpn]) >> "displayName");
			Pumpkin_menu_handweapon = player addAction [format["Arme %1 (sac à dos)",_wpnstored], "plr_respawn\Swap_bpack_weapon.sqf", _wpn, 0, false, true, "", "true"];
		};
		// Lance-roquette
		case 4: {
			// Retirer le LR
			Pumpkin_BackpackContents = [Pumpkin_BackpackContents select 0, (Pumpkin_BackpackContents select 1) - [_wpn]];

			_newbag = unitBackpack player;
			// Placer le LR sur le joueur
			player addweapon _wpn;
			  //_obj = (nearestObjects [player, ["Bag_Base_EP1"], 10]) select 0;
			  //if (not isnull _obj) then {
			  //	player addbackpack (typeof _obj);
			  //	deleteVehicle _obj;
			  //};
			  //waituntil {not isNull (unitBackpack player)};
			// Le sac à nouveau en place, recréer le contenu du sac à dos, - le LR
			clearMagazineCargo _newbag;
			clearWeaponCargo _newbag;
			_backpackmags = Pumpkin_BackpackContents select 0;
			_backpackwpns = Pumpkin_BackpackContents select 1;
			if (count _backpackmags > 0) then {
				for [{_i = 0},{_i < count _backpackmags},{_i = _i + 1}] do { _newbag addmagazinecargo [(_backpackmags select _i),1] };
			};
			if (count _backpackwpns > 0) then {
				for [{_i = 0},{_i < count _backpackwpns},{_i = _i + 1}] do { _newbag addweaponcargo [(_backpackwpns select _i),1] };
			};
		};
		// Mitrailleuse lourde interdisant (normalement) le sac à dos
		case 5: {
			_wpnstored = getText (configFile >> "cfgWeapons" >> (format ["%1",_wpn]) >> "displayName");
			Pumpkin_menu_primweapon = player addAction [format["Arme %1 (sac à dos)",_wpnstored], "plr_respawn\Swap_bpack_weapon.sqf", _wpn, 0, false, true, "", "true"];
		};
	};

} foreach (Pumpkin_BackpackContents select 1);
