sleep 0.5;
_FA18 = _this;	//name of the unit we are playing with

//this line is used to tel Ui that a rearming script instacne is run, to prevent duplicate scripts run simultainuously
_FA18 animate ["rearming_done_switch",1];

//ok lets clear the aircraft of any possible weps/mags [GLT aswell]
//remove any default loadout weapons and magazines first
_fa18 removeWeapon "js_w_fa18_aim9xLaucher"; 
_fa18 removeWeapon "js_w_fa18_aim120cLaucher"; 
_fa18 removeWeapon "js_w_fa18_GBU12LGBLaucher";
_fa18 removeWeapon "js_w_fa18_Mk82BombLauncher";  
_fa18 removeWeapon "js_w_fa18_MaverickLauncher"; 
_fa18 removeWeapon "js_w_fa18_fueltank_holder"; 
_fa18 removeWeapon "js_w_fa18_HarpoonLauncher";
_fa18 removeWeapon "js_w_fa18_GBU31BombLauncher";
_fa18 removeWeapon "js_w_fa18_GBU32BombLauncher";
_fa18 removeWeapon "js_w_fa18_GBU38BombLauncher";
_fa18 removeWeapon "Laserdesignator_mounted";

_fa18 removeWeapon "GLT_AIM9X_Launcher"; 
_fa18 removeWeapon "GLT_AIM120_Launcher";
_fa18 removeWeapon "GLT_AGM65_Launcher";  
_fa18 removeWeapon "GLT_GBU12_Launcher"; 
_fa18 removeWeapon "GLT_GBU53_Launcher"; 
_fa18 removeWeapon "GLT_AGM84_Launcher";

_fa18 removeMagazines "GLT_2Rnd_AIM9X";
_fa18 removeMagazines "GLT_2Rnd_AIM120"; 
_fa18 removeMagazines "GLT_4Rnd_AIM120"; 
_fa18 removeMagazines "GLT_2Rnd_AGM65"; 
_fa18 removeMagazines "GLT_4Rnd_AGM65"; 
_fa18 removeMagazines "GLT_4Rnd_GBU12";
_fa18 removeMagazines "GLT_2Rnd_GBU53"; 
_fa18 removeMagazines "GLT_4Rnd_GBU53";  
_fa18 removeMagazines "GLT_6Rnd_GBU53";
_fa18 removeMagazines "GLT_2Rnd_AGM84";

_fa18 removeMagazines "js_m_fa18_aim9x_x1";
_fa18 removeMagazines "js_m_fa18_aim9x_x2";
_fa18 removeMagazines "js_m_fa18_aim120c_x1"; 
_fa18 removeMagazines "js_m_fa18_aim120c_x2"; 
_fa18 removeMagazines "js_m_fa18_aim120c_x4"; 
_fa18 removeMagazines "js_m_fa18_bombrack_x1";
_fa18 removeMagazines "js_m_fa18_bombrack_x2"; 
_fa18 removeMagazines "js_m_fa18_GBU12_x1";
_fa18 removeMagazines "js_m_fa18_GBU12_x4";
_fa18 removeMagazines "js_m_fa18_MK82_x1";
_fa18 removeMagazines "js_m_fa18_MK82_x2"; 
_fa18 removeMagazines "js_m_fa18_MK82_x4";
_fa18 removeMagazines "js_m_fa18_GBU38_JDAM_x1";
_fa18 removeMagazines "js_m_fa18_GBU32_JDAM_x1"; 
_fa18 removeMagazines "js_m_fa18_GBU31_JDAM_x1";
_fa18 removeMagazines "js_m_fa18_Maverick_x1";   
_fa18 removeMagazines "js_m_fa18_Maverick_x2"; 
_fa18 removeMagazines "js_m_fa18_Maverick_x4";
_fa18 removeMagazines "js_m_fa18_Harpoon_x1";
_fa18 removeMagazines "js_m_fa18_Harpoon_x2";
_fa18 removeMagazines "js_m_fa18_wing_tank_x1";
_fa18 removeMagazines "js_m_fa18_wing_tank_x2";
_fa18 removeMagazines "js_m_fa18_altflir_pod_x1";  
_fa18 removeMagazines "js_m_fa18_empty"; 
_fa18 removeMagazines "js_m_fa18_fake_empty";
_fa18 removeMagazines "js_m_fa18_buddypod_x1";
_fa18 removeMagazines "Laserbatteries";


//ok here we go lets add new stuff
//in case using other weapons than built in or GLT I cant guarantee it will work properly.
//magazines must be added in correct sequance to fill all weapons proxies properly
//19 stations to use


//Station 1
_FA18 addMagazine "js_m_fa18_aim9x_x1";
//Station 2
_FA18 addMagazine "js_m_fa18_aim9x_x1";
//Station 3
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 4
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 5
_FA18 addMagazine "js_m_fa18_bombrack_x1";
//Station 6
_FA18 addMagazine "js_m_fa18_bombrack_x1";
//Station 7
_FA18 addMagazine "js_m_fa18_GBU31_JDAM_x1";
//Station 8
_FA18 addMagazine "js_m_fa18_GBU31_JDAM_x1";
//Station 9
_FA18 addMagazine "js_m_fa18_aim120c_x1";
//Station 10
_FA18 addMagazine "js_m_fa18_aim120c_x1";
//Station 11
_FA18 addMagazine "js_m_fa18_empty";
//Station 12
_FA18 addMagazine "js_m_fa18_empty";
//Station 13
_FA18 addMagazine "js_m_fa18_empty";
//Station 14
_FA18 addMagazine "js_m_fa18_empty";
//Station 15
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 16
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 17
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 18
_FA18 addMagazine "js_m_fa18_Maverick_x1";
//Station 19
_FA18 addMagazine "js_m_fa18_wing_tank_x1";


//add new weapons depending on selected loadout
//or delete this code block and manualy add needed weapons
_loadout = magazines _FA18;
sleep 0.5;
if (("js_m_fa18_aim9x_x1" in _loadout) or ("js_m_fa18_aim9x_x2" in _loadout)) then {_FA18 addWeapon "js_w_fa18_aim9xLaucher";};
if (("js_m_fa18_aim120c_x1" in _loadout) or ("js_m_fa18_aim120c_x2" in _loadout) or ("js_m_fa18_aim120c_x4" in _loadout)) then {_FA18 addWeapon "js_w_fa18_aim120cLaucher";};
if (("js_m_fa18_GBU12_x1" in _loadout) or ("js_m_fa18_GBU12_x4" in _loadout)) then {_FA18 addWeapon "js_w_fa18_GBU12LGBLaucher";};
if (("js_m_fa18_MK82_x1" in _loadout) or ("js_m_fa18_MK82_x2" in _loadout) or ("js_m_fa18_MK82_x4" in _loadout)) then {_FA18 addWeapon "js_w_fa18_Mk82BombLauncher";};
if (("js_m_fa18_GBU38_JDAM_x1" in _loadout)) then {_FA18 addWeapon "js_w_fa18_GBU38BombLauncher";};
if (("js_m_fa18_GBU32_JDAM_x1" in _loadout)) then {_FA18 addWeapon "js_w_fa18_GBU32BombLauncher";};
if (("js_m_fa18_GBU31_JDAM_x1" in _loadout)) then {_FA18 addWeapon "js_w_fa18_GBU31BombLauncher";};
if (("js_m_fa18_Maverick_x1" in _loadout) or ("js_m_fa18_Maverick_x2" in _loadout) or ("js_m_fa18_Maverick_x4" in _loadout)) then {_FA18 addWeapon "js_w_fa18_MaverickLauncher";};
if (("js_m_fa18_Harpoon_x1" in _loadout) or ("js_m_fa18_Harpoon_x2" in _loadout)) then {_FA18 addWeapon "js_w_fa18_HarpoonLauncher";};
if (("js_m_fa18_wing_tank_x1" in _loadout) or ("js_m_fa18_wing_tank_x2" in _loadout)) then {_FA18 addWeapon "js_w_fa18_fueltank_holder";};
if (("js_m_fa18_altflir_pod_x1" in _loadout)) then {_FA18 addWeapon "Laserdesignator_mounted"; _FA18 addMagazine "Laserbatteries"};


//setting canon and flares back to max
_FA18 setVehicleAmmo 1;

//this is needed to corrtly calculate fuel if any external tanks are equiped and you wish a fuel drop sequence to work [only with js_m_fa18_wing_tank_x1 as a magazine]

_Fuel_tank_count = {_x == "js_m_fa18_wing_tank_x1"} count magazines _FA18;

If (_Fuel_tank_count < 1) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	_FA18 animate ["auxtank_switch",0];
};

If (_Fuel_tank_count == 1) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	If ((_External_fuel < 0.2)) Then 
	{
		_FA18 animate ["auxtank_switch",(_External_fuel + (0.2 - _External_fuel))];
	};
	If ((_External_fuel > 0.2)) Then 
	{
		_FA18 animate ["auxtank_switch",0.2];
	};
};

If (_Fuel_tank_count == 2) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	If ((_External_fuel < 0.4)) Then 
	{
		_FA18 animate ["auxtank_switch",(_External_fuel + (0.4 - _External_fuel))];
	};
	If ((_External_fuel > 0.4)) Then 
	{
		_FA18 animate ["auxtank_switch",0.4];
	};
};

If (_Fuel_tank_count == 3) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	If ((_External_fuel < 0.6)) Then 
	{
		_FA18 animate ["auxtank_switch",(_External_fuel + (0.6 - _External_fuel))];
	};
	If ((_External_fuel > 0.6)) Then 
	{
		_FA18 animate ["auxtank_switch",0.6];
	};
};

If (_Fuel_tank_count == 4) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	If ((_External_fuel < 0.8)) Then 
	{
		_FA18 animate ["auxtank_switch",(_External_fuel + (0.8 - _External_fuel))];
	};
	If ((_External_fuel > 0.8)) Then 
	{
		_FA18 animate ["auxtank_switch",0.8];
	};
};

If (_Fuel_tank_count == 5) Then 
{	
	_External_fuel = _FA18 animationPhase "auxtank_switch";
	If ((_External_fuel < 0.99)) Then 
	{
		_FA18 animate ["auxtank_switch",(_External_fuel + (1.0 - _External_fuel))];
	};
	If ((_External_fuel >= 1.0)) Then 
	{
		_FA18 animate ["auxtank_switch",1.0];
	};
};

sleep 0.05;
_External_fuel = _FA18 animationPhase "auxtank_switch";

If (("js_m_fa18_buddypod_x1" in _loadout)) Then 
{	
	
	If (_Fuel_tank_count > 1) Then 
	{	
		_FA18 animate ["auxtank_switch",(_External_fuel + 0.2)];
	};
	If (_Fuel_tank_count < 1) Then 
	{	
		_FA18 animate ["auxtank_switch",0.2];
	};

};

//setting "SAFE" as a default weapon
_FA18 selectWeapon "js_w_master_arms_safe";
//this is to tell UI that rearming is compleate and next instance of script can be run for UI
_FA18 animate ["rearming_done_switch",1];
Exit;