#include maps\mp\_utility;

init()
{
	switch(game["allies"])
	{
	case "american":
		
		precacheItem("frag_grenade_american_mp");	
		if(game["am_frag_grenades_type"] == "am_cooked") 		precacheItem("frag_grenade_american_mp");		
		if(game["am_frag_grenades_type"] == "am_cooked_slow") 	precacheItem("slow_frag_grenade_american_mp");		
		if(game["am_frag_grenades_type"] == "original") 		precacheItem("original_frag_grenade_american_mp");		
		if(game["am_frag_grenades_type"] == "original_slow") 	precacheItem("original_slow_frag_grenade_american_mp");		
				
		if(game["am_enabled"] == 0 || (game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 0)) precacheItem("smoke_grenade_american_mp");
		precacheItem("colt_mp");
		precacheItem("m1carbine_mp");
		precacheItem("m1garand_mp");
		precacheItem("thompson_mp");
		precacheItem("bar_mp");
		precacheItem("springfield_mp");
		precacheItem("greasegun_mp");
		precacheItem("shotgun_mp");
		//precacheItem("30cal_mp");
		//precacheItem("M9_Bazooka");	
		precacheItem("enfield_mp");
		break;

	case "british":
		
		precacheItem("frag_grenade_british_mp");	
		if(game["am_frag_grenades_type"] == "am_cooked") 		precacheItem("frag_grenade_british_mp");		
		if(game["am_frag_grenades_type"] == "am_cooked_slow") 	precacheItem("slow_frag_grenade_british_mp");		
		if(game["am_frag_grenades_type"] == "original") 		precacheItem("original_frag_grenade_british_mp");		
		if(game["am_frag_grenades_type"] == "original_slow") 	precacheItem("original_slow_frag_grenade_british_mp");		
		
		if(game["am_enabled"] == 0 || (game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 0)) precacheItem("smoke_grenade_british_mp");
		precacheItem("webley_mp");
		precacheItem("enfield_mp");
		precacheItem("sten_mp");
		precacheItem("bren_mp");
		precacheItem("enfield_scope_mp");
		precacheItem("m1garand_mp");
		precacheItem("thompson_mp");
		precacheItem("shotgun_mp");
		//precacheItem("30cal_mp");
		//precacheItem("M9_Bazooka");
		break;

	case "russian":
		
		precacheItem("frag_grenade_russian_mp");	
		if(game["am_frag_grenades_type"] == "am_cooked") 		precacheItem("frag_grenade_russian_mp");		
		if(game["am_frag_grenades_type"] == "am_cooked_slow") 	precacheItem("slow_frag_grenade_russian_mp");		
		if(game["am_frag_grenades_type"] == "original") 		precacheItem("original_frag_grenade_russian_mp");		
		if(game["am_frag_grenades_type"] == "original_slow") 	precacheItem("original_slow_frag_grenade_russian_mp");		
		
		if(game["am_enabled"] == 0 || (game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 0)) precacheItem("smoke_grenade_russian_mp");
		precacheItem("TT30_mp");
		precacheItem("mosin_nagant_mp");
		precacheItem("SVT40_mp");
		precacheItem("PPS42_mp");
		precacheItem("ppsh_mp");
		precacheItem("mosin_nagant_sniper_mp");
		precacheItem("shotgun_mp");
		//precacheItem("dp28_mp");
		//precacheItem("M9_Bazooka");
		precacheItem("thompson_mp");
		precacheItem("enfield_mp");
		break;
	}

	precacheItem("frag_grenade_german_mp");
	if(game["am_frag_grenades_type"] == "am_cooked") 		precacheItem("frag_grenade_german_mp");		
	if(game["am_frag_grenades_type"] == "am_cooked_slow") 	precacheItem("slow_frag_grenade_german_mp");		
	if(game["am_frag_grenades_type"] == "original") 		precacheItem("original_frag_grenade_german_mp");		
	if(game["am_frag_grenades_type"] == "original_slow") 	precacheItem("original_slow_frag_grenade_german_mp");		

	if(game["am_enabled"] == 0 || (game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 0)) precacheItem("smoke_grenade_german_mp");
	precacheItem("luger_mp");
	precacheItem("kar98k_mp");
	precacheItem("g43_mp");
	precacheItem("mp40_mp");
	precacheItem("mp44_mp");
	precacheItem("kar98k_sniper_mp");
	precacheItem("shotgun_mp");
	//precacheItem("dp28_mp");
	precacheItem("binoculars_mp");

	precacheItem("panzerschreck_mp");




	if(game["am_only_rifles"] == 1) {

		switch(game["allies"])	{

			case "american":

				precacheItem("kar98k_mp");
				precacheItem("mosin_nagant_mp");
				precacheItem("enfield_mp");
				break;

			case "russian":

				precacheItem("kar98k_mp");
				precacheItem("mosin_nagant_mp");
				precacheItem("enfield_mp");
				break;

			case "british":

				precacheItem("kar98k_mp");
				precacheItem("mosin_nagant_mp");
				precacheItem("enfield_mp");
				break;
		}
	}

	if(game["am_only_snipers"] == 1) {

		switch(game["allies"])	{

			case "american":

				precacheItem("kar98k_sniper_mp");
				precacheItem("mosin_nagant_sniper_mp");
				precacheItem("enfield_scope_mp");
				precacheItem("springfield_mp");
				break;

			case "russian":

				precacheItem("kar98k_sniper_mp");
				precacheItem("mosin_nagant_sniper_mp");
				precacheItem("enfield_scope_mp");
				precacheItem("springfield_mp");
				break;

			case "british":

				precacheItem("kar98k_sniper_mp");
				precacheItem("mosin_nagant_sniper_mp");
				precacheItem("enfield_scope_mp");
				precacheItem("springfield_mp");
				break;
		}
	}

	
	if(game["am_gametype"] == "mm") {

		precacheItem("automatic_mp");
 		precacheItem("rifle_mp");
		precacheItem("sniper_mp");
		precacheItem("shotgun_mp");	
	}
	

	
	// * Kill-Icons *
	precacheItem("artillery_mp");


	level.weaponnames = [];
	level.weaponnames[0] = "greasegun_mp";
	level.weaponnames[1] = "m1carbine_mp";
	level.weaponnames[2] = "m1garand_mp";
	level.weaponnames[3] = "springfield_mp";
	level.weaponnames[4] = "thompson_mp";
	level.weaponnames[5] = "bar_mp";
	level.weaponnames[6] = "sten_mp";
	level.weaponnames[7] = "enfield_mp";
	level.weaponnames[8] = "enfield_scope_mp";
	level.weaponnames[9] = "bren_mp";
	level.weaponnames[10] = "PPS42_mp";
	level.weaponnames[11] = "mosin_nagant_mp";
	level.weaponnames[12] = "SVT40_mp";
	level.weaponnames[13] = "mosin_nagant_sniper_mp";
	level.weaponnames[14] = "ppsh_mp";
	level.weaponnames[15] = "mp40_mp";
	level.weaponnames[16] = "kar98k_mp";
	level.weaponnames[17] = "g43_mp";
	level.weaponnames[18] = "kar98k_sniper_mp";
	level.weaponnames[19] = "mp44_mp";
	level.weaponnames[20] = "shotgun_mp";
	level.weaponnames[21] = "fraggrenade";
	level.weaponnames[22] = "smokegrenade";
	level.weaponnames[23] = "colt_mp";
	level.weaponnames[24] = "luger_mp";
	level.weaponnames[25] = "webley_mp";
	level.weaponnames[26] = "TT30_mp";
	
	level.weaponnames[27] = "panzerschreck_mp";	
	level.weaponnames[28] = "mortar_cannon_walk_mp";	

	if(game["am_enable_mobile_mg"]) {
	
		level.weaponnames[29] = "30cal_walk_mp";
		level.weaponnames[30] = "mg42_bipod_walk_mp";
	}



	level.weapons = [];
	level.weapons["greasegun_mp"] = spawnstruct();
	level.weapons["greasegun_mp"].server_allowcvar = "scr_allow_greasegun";
	level.weapons["greasegun_mp"].client_allowcvar = "ui_allow_greasegun";
	level.weapons["greasegun_mp"].weapontype = "small_mg";
	level.weapons["greasegun_mp"].allow_default = 1;

	level.weapons["m1carbine_mp"] = spawnstruct();
	level.weapons["m1carbine_mp"].server_allowcvar = "scr_allow_m1carbine";
	level.weapons["m1carbine_mp"].client_allowcvar = "ui_allow_m1carbine";
	level.weapons["m1carbine_mp"].weapontype = "automatic_rifle";
	level.weapons["m1carbine_mp"].allow_default = 1;

	level.weapons["m1garand_mp"] = spawnstruct();
	level.weapons["m1garand_mp"].server_allowcvar = "scr_allow_m1garand";
	level.weapons["m1garand_mp"].client_allowcvar = "ui_allow_m1garand";
	level.weapons["m1garand_mp"].weapontype = "automatic_rifle";
	level.weapons["m1garand_mp"].allow_default = 1;

	level.weapons["springfield_mp"] = spawnstruct();
	level.weapons["springfield_mp"].server_allowcvar = "scr_allow_springfield";
	level.weapons["springfield_mp"].client_allowcvar = "ui_allow_springfield";
	level.weapons["springfield_mp"].weapontype = "sniper";
	level.weapons["springfield_mp"].allow_default = 1;

	level.weapons["thompson_mp"] = spawnstruct();
	level.weapons["thompson_mp"].server_allowcvar = "scr_allow_thompson";
	level.weapons["thompson_mp"].client_allowcvar = "ui_allow_thompson";
	level.weapons["thompson_mp"].weapontype = "small_mg";
	level.weapons["thompson_mp"].allow_default = 1;

	level.weapons["bar_mp"] = spawnstruct();
	level.weapons["bar_mp"].server_allowcvar = "scr_allow_bar";
	level.weapons["bar_mp"].client_allowcvar = "ui_allow_bar";
	level.weapons["bar_mp"].weapontype = "mg";
	level.weapons["bar_mp"].allow_default = 1;

	level.weapons["sten_mp"] = spawnstruct();
	level.weapons["sten_mp"].server_allowcvar = "scr_allow_sten";
	level.weapons["sten_mp"].client_allowcvar = "ui_allow_sten";
	level.weapons["sten_mp"].weapontype = "small_mg";
	level.weapons["sten_mp"].allow_default = 1;

	level.weapons["enfield_mp"] = spawnstruct();
	level.weapons["enfield_mp"].server_allowcvar = "scr_allow_enfield";
	level.weapons["enfield_mp"].client_allowcvar = "ui_allow_enfield";
	level.weapons["enfield_mp"].weapontype = "rifle";
	level.weapons["enfield_mp"].allow_default = 1;

	level.weapons["enfield_scope_mp"] = spawnstruct();
	level.weapons["enfield_scope_mp"].server_allowcvar = "scr_allow_enfieldsniper";
	level.weapons["enfield_scope_mp"].client_allowcvar = "ui_allow_enfieldsniper";
	level.weapons["enfield_scope_mp"].weapontype = "sniper";
	level.weapons["enfield_scope_mp"].allow_default = 1;

	level.weapons["bren_mp"] = spawnstruct();
	level.weapons["bren_mp"].server_allowcvar = "scr_allow_bren";
	level.weapons["bren_mp"].client_allowcvar = "ui_allow_bren";
	level.weapons["bren_mp"].weapontype = "mg";
	level.weapons["bren_mp"].allow_default = 1;

	level.weapons["PPS42_mp"] = spawnstruct();
	level.weapons["PPS42_mp"].server_allowcvar = "scr_allow_pps42";
	level.weapons["PPS42_mp"].client_allowcvar = "ui_allow_pps42";
	level.weapons["PPS42_mp"].weapontype = "small_mg";
	level.weapons["PPS42_mp"].allow_default = 1;

	level.weapons["mosin_nagant_mp"] = spawnstruct();
	level.weapons["mosin_nagant_mp"].server_allowcvar = "scr_allow_nagant";
	level.weapons["mosin_nagant_mp"].client_allowcvar = "ui_allow_nagant";
	level.weapons["mosin_nagant_mp"].weapontype = "rifle";
	level.weapons["mosin_nagant_mp"].allow_default = 1;

	level.weapons["SVT40_mp"] = spawnstruct();
	level.weapons["SVT40_mp"].server_allowcvar = "scr_allow_svt40";
	level.weapons["SVT40_mp"].client_allowcvar = "ui_allow_svt40";
	level.weapons["SVT40_mp"].weapontype = "automatic_rifle";
	level.weapons["SVT40_mp"].allow_default = 1;

	level.weapons["mosin_nagant_sniper_mp"] = spawnstruct();
	level.weapons["mosin_nagant_sniper_mp"].server_allowcvar = "scr_allow_nagantsniper";
	level.weapons["mosin_nagant_sniper_mp"].client_allowcvar = "ui_allow_nagantsniper";
	level.weapons["mosin_nagant_sniper_mp"].weapontype = "sniper";
	level.weapons["mosin_nagant_sniper_mp"].allow_default = 1;

	level.weapons["ppsh_mp"] = spawnstruct();
	level.weapons["ppsh_mp"].server_allowcvar = "scr_allow_ppsh";
	level.weapons["ppsh_mp"].client_allowcvar = "ui_allow_ppsh";
	level.weapons["ppsh_mp"].weapontype = "small_mg";
	level.weapons["ppsh_mp"].allow_default = 1;

	level.weapons["mp40_mp"] = spawnstruct();
	level.weapons["mp40_mp"].server_allowcvar = "scr_allow_mp40";
	level.weapons["mp40_mp"].client_allowcvar = "ui_allow_mp40";
	level.weapons["mp40_mp"].weapontype = "small_mg";
	level.weapons["mp40_mp"].allow_default = 1;

	level.weapons["kar98k_mp"] = spawnstruct();
	level.weapons["kar98k_mp"].server_allowcvar = "scr_allow_kar98k";
	level.weapons["kar98k_mp"].client_allowcvar = "ui_allow_kar98k";
	level.weapons["kar98k_mp"].weapontype = "rifle";
	level.weapons["kar98k_mp"].allow_default = 1;

	level.weapons["g43_mp"] = spawnstruct();
	level.weapons["g43_mp"].server_allowcvar = "scr_allow_g43";
	level.weapons["g43_mp"].client_allowcvar = "ui_allow_g43";
	level.weapons["g43_mp"].weapontype = "automatic_rifle";
	level.weapons["g43_mp"].allow_default = 1;

	level.weapons["kar98k_sniper_mp"] = spawnstruct();
	level.weapons["kar98k_sniper_mp"].server_allowcvar = "scr_allow_kar98ksniper";
	level.weapons["kar98k_sniper_mp"].client_allowcvar = "ui_allow_kar98ksniper";
	level.weapons["kar98k_sniper_mp"].weapontype = "sniper";
	level.weapons["kar98k_sniper_mp"].allow_default = 1;

	level.weapons["mp44_mp"] = spawnstruct();
	level.weapons["mp44_mp"].server_allowcvar = "scr_allow_mp44";
	level.weapons["mp44_mp"].client_allowcvar = "ui_allow_mp44";
	level.weapons["mp44_mp"].weapontype = "mg";
	level.weapons["mp44_mp"].allow_default = 1;

	level.weapons["shotgun_mp"] = spawnstruct();
	level.weapons["shotgun_mp"].server_allowcvar = "scr_allow_shotgun";
	level.weapons["shotgun_mp"].client_allowcvar = "ui_allow_shotgun";
	level.weapons["shotgun_mp"].weapontype = "shotgun";
	level.weapons["shotgun_mp"].allow_default = 1;

	level.weapons["fraggrenade"] = spawnstruct();
	level.weapons["fraggrenade"].server_allowcvar = "scr_allow_fraggrenades";
	level.weapons["fraggrenade"].client_allowcvar = "ui_allow_fraggrenades";
	level.weapons["fraggrenade"].weapontype = "nade";
	level.weapons["fraggrenade"].allow_default = 1;

	level.weapons["smokegrenade"] = spawnstruct();
	level.weapons["smokegrenade"].server_allowcvar = "scr_allow_smokegrenades";
	level.weapons["smokegrenade"].client_allowcvar = "ui_allow_smokegrenades";
	level.weapons["smokegrenade"].weapontype = "smoke";
	level.weapons["smokegrenade"].allow_default = 1;

	level.weapons["colt_mp"] = spawnstruct();
	level.weapons["colt_mp"].server_allowcvar = "scr_allow_colt";
	level.weapons["colt_mp"].client_allowcvar = "ui_allow_colt";
	level.weapons["colt_mp"].weapontype = "pistol";
	level.weapons["colt_mp"].allow_default = 1;

	level.weapons["luger_mp"] = spawnstruct();
	level.weapons["luger_mp"].server_allowcvar = "scr_allow_luger";
	level.weapons["luger_mp"].client_allowcvar = "ui_allow_luger";
	level.weapons["luger_mp"].weapontype = "pistol";
	level.weapons["luger_mp"].allow_default = 1;
	
	level.weapons["webley_mp"] = spawnstruct();
	level.weapons["webley_mp"].server_allowcvar = "scr_allow_webley";
	level.weapons["webley_mp"].client_allowcvar = "ui_allow_webley";
	level.weapons["webley_mp"].weapontype = "pistol";
	level.weapons["webley_mp"].allow_default = 1;
	
	level.weapons["TT30_mp"] = spawnstruct();
	level.weapons["TT30_mp"].server_allowcvar = "scr_allow_TT30";
	level.weapons["TT30_mp"].client_allowcvar = "ui_allow_TT30";
	level.weapons["TT30_mp"].weapontype = "pistol";
	level.weapons["TT30_mp"].allow_default = 1;



	level.weapons["panzerschreck_mp"] = spawnstruct();
	level.weapons["panzerschreck_mp"].server_allowcvar = "scr_allow_panzerschreck";
	level.weapons["panzerschreck_mp"].client_allowcvar = "ui_allow_panzerschreck";
	level.weapons["panzerschreck_mp"].weapontype = "mobiles";
	level.weapons["panzerschreck_mp"].allow_default = 1;

	level.weapons["30cal_walk_mp"] = spawnstruct();
	level.weapons["30cal_walk_mp"].server_allowcvar = "scr_allow_30cal";
	level.weapons["30cal_walk_mp"].client_allowcvar = "ui_allow_30cal";
	level.weapons["30cal_walk_mp"].weapontype = "mobiles";
	level.weapons["30cal_walk_mp"].allow_default = 1;

	level.weapons["mg42_bipod_walk_mp"] = spawnstruct();
	level.weapons["mg42_bipod_walk_mp"].server_allowcvar = "scr_allow_mg42";
	level.weapons["mg42_bipod_walk_mp"].client_allowcvar = "ui_allow_mg42";
	level.weapons["mg42_bipod_walk_mp"].weapontype = "mobiles";
	level.weapons["mg42_bipod_walk_mp"].allow_default = 1;

	level.weapons["mortar_cannon_walk_mp"] = spawnstruct();
	level.weapons["mortar_cannon_walk_mp"].server_allowcvar = "scr_allow_mortar_cannon";
	level.weapons["mortar_cannon_walk_mp"].client_allowcvar = "ui_allow_mortar_cannon";
	level.weapons["mortar_cannon_walk_mp"].weapontype = "mobiles";
	level.weapons["mortar_cannon_walk_mp"].allow_default = 1;
	

	for(i = 0; i < level.weaponnames.size; i++)
	{
		weaponname = level.weaponnames[i];

		if(!isDefined(weaponname)) continue;

		if(getCvar(level.weapons[weaponname].server_allowcvar) == "")
		{
			level.weapons[weaponname].allow = level.weapons[weaponname].allow_default;
			setCvar(level.weapons[weaponname].server_allowcvar, level.weapons[weaponname].allow);
		}
		else
			level.weapons[weaponname].allow = getCvarInt(level.weapons[weaponname].server_allowcvar);
	}



	if(game["am_enabled"] == 0 || game["am_enable_mobile_mg"] == 0) {
	
		level.weapons["30cal_walk_mp"].allow = 0;
		level.weapons["mg42_bipod_walk_mp"].allow = 0;
		setCvar(level.weapons["30cal_walk_mp"].server_allowcvar, 0);
		setCvar(level.weapons["mg42_bipod_walk_mp"].server_allowcvar, 0);
		setCvar(level.weapons["30cal_walk_mp"].client_allowcvar, 0);
		setCvar(level.weapons["mg42_bipod_walk_mp"].client_allowcvar, 0);
	}





	level thread deleteRestrictedWeapons();
	level thread onPlayerConnect();

	for(;;)
	{
		wait 45; // * Damit nicht sofort beim connecten der Server an alle Player Commands sendet *
		updateAllowed();		
	}
}

onPlayerConnect()
{
	for(;;)
	{
		level waittill("connecting", player);

		player.usedweapons = false;

		player thread updateAllAllowedSingleClient();
		player thread onPlayerSpawned();
	}
}

onPlayerSpawned()
{
	self endon("disconnect");

	for(;;)
	{
		self waittill("spawned_player");

		self thread watchWeaponUsage();
	}
}

deleteRestrictedWeapons()
{
	for(i = 0; i < level.weaponnames.size; i++)
	{
		weaponname = level.weaponnames[i];

		//if(level.weapons[weaponname].allow != 1)
			//deletePlacedEntity(level.weapons[weaponname].radiant_name);
	}

	// Need to not automatically give these to players if I allow restricting them
	// colt_mp
	// webley_mp
	// TT30_mp
	// luger_mp
	// fraggrenade_mp
	// mk1britishfrag_mp
	// rgd-33russianfrag_mp
	// stielhandgranate_mp
}

givePistol()
{

	self endon("disconnect");


	// * AdmiralMOD *
	// * Wenn als Primary-Weapon eine Pistole ausgewählt wurde, dann nicht noch auf PrimaryB eine legen *
	if(game["am_enabled"] == 1 && isPistol(self.pers["weapon"])) return;



	weapon2 = self getweaponslotweapon("primaryb");
	if(weapon2 == "none")
	{
		if(self.pers["team"] == "allies")
		{
			switch(game["allies"])
			{
			case "american":
				pistoltype = "colt_mp";
				break;

			case "british":
				pistoltype = "webley_mp";
				break;

			default:
				assert(game["allies"] == "russian");
				pistoltype = "TT30_mp";
				break;
			}
		}
		else
		{
			assert(self.pers["team"] == "axis");
			switch(game["axis"])
			{
			default:
				assert(game["axis"] == "german");
				pistoltype = "luger_mp";
				break;
			}
		}

		self takeWeapon("colt_mp");
		self takeWeapon("webley_mp");
		self takeWeapon("TT30_mp");
		self takeWeapon("luger_mp");

		//self giveWeapon(pistoltype);
		self setWeaponSlotWeapon("primaryb", pistoltype);
		self giveMaxAmmo(pistoltype);	
	}
}

getPistolType()
{

	self endon("disconnect");


	if(self.pers["team"] == "allies")
	{
		switch(game["allies"])
		{
		case "american":
			pistoltype = "colt_mp";
			break;

		case "british":
			pistoltype = "webley_mp";
			break;

		default:
			pistoltype = "TT30_mp";
			break;
		}
	}
	else
	{		
		switch(game["axis"])
		{
		default:			
			pistoltype = "luger_mp";
			break;
		}
	}

	return pistoltype;
}


giveGrenades()
{
	self endon("disconnect");

	if(game["am_hud_style"] == 1) 	{
	
		self setClientCvar("am_ui_show_special_weapon", "");
		self.pers["am_ui_show_special_weapon"] = "";
	}
	if(game["am_hud_style"] == 2) 	{
	
		self setClientCvar("am_ui_show_special_weapon", "10");
		self.pers["am_ui_show_special_weapon"] = "10";
	}

	// * Wenn farbige Rauchgranaten *	
	if(game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 1) {	
	

		smokegrenadetype = "green_smoke_grenade_mp";	

		f = randomint(3);
	
		if(f == 0) smokegrenadetype = "red_smoke_grenade_mp";	
		if(f == 1) smokegrenadetype = "blue_smoke_grenade_mp";	
		if(f == 2) smokegrenadetype = "green_smoke_grenade_mp";	
		
		
		// * Dann noch nur den Granatentyp festlegen *
		if(self.pers["team"] == "allies")
		{
			switch(game["allies"])
			{
			case "american":
				grenadetype = "frag_grenade_american_mp";
				
				if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_american_mp"; 	
				if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_american_mp"; 		
				if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_american_mp";		
				if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_american_mp";		
								
				break;

			case "british":
				grenadetype = "frag_grenade_british_mp";
				
				if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_british_mp"; 	
				if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_british_mp"; 		
				if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_british_mp";		
				if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_british_mp";		
								
				break;

			default:
				assert(game["allies"] == "russian");
				grenadetype = "frag_grenade_russian_mp";
				
				if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_russian_mp"; 	
				if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_russian_mp"; 		
				if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_russian_mp";		
				if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_russian_mp";		
								
				break;
			}
		}
		else
		{
			assert(self.pers["team"] == "axis");
			switch(game["axis"])
			{
			default:
				assert(game["axis"] == "german");
				grenadetype = "frag_grenade_german_mp";
				
				if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_german_mp"; 	
				if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_german_mp"; 		
				if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_german_mp";		
				if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_german_mp";		
								
				break;
			}
		}
		
	}
	else {


		if(self.pers["team"] == "allies")
		{
			switch(game["allies"])
			{
				case "american":
					grenadetype = "frag_grenade_american_mp";

					if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_american_mp"; 	
					if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_american_mp"; 		
					if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_american_mp";		
					if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_american_mp";		

					smokegrenadetype = "smoke_grenade_american_mp";
					break;

				case "british":
					grenadetype = "frag_grenade_british_mp";
				
					if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_british_mp"; 	
					if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_british_mp"; 		
					if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_british_mp";		
					if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_british_mp";		
								
					smokegrenadetype = "smoke_grenade_british_mp";
					break;

				default:
					assert(game["allies"] == "russian");
					grenadetype = "frag_grenade_russian_mp";
				
					if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_russian_mp"; 	
					if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_russian_mp"; 		
					if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_russian_mp";		
					if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_russian_mp";		
								
					smokegrenadetype = "smoke_grenade_russian_mp";
					break;
			}
		}
		else
		{
			assert(self.pers["team"] == "axis");
			switch(game["axis"])
			{
			default:
				assert(game["axis"] == "german");
				grenadetype = "frag_grenade_german_mp";
				
				if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_german_mp"; 	
				if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_german_mp"; 		
				if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_german_mp";		
				if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_german_mp";		
								
				smokegrenadetype = "smoke_grenade_german_mp";
				break;
			}
		}
	}	
	
	
	self takeWeapon("frag_grenade_american_mp");
	self takeWeapon("frag_grenade_british_mp");
	self takeWeapon("frag_grenade_russian_mp");
	self takeWeapon("frag_grenade_german_mp");

	
	if(game["am_frag_grenades_type"] == "am_cooked") {
	
		self takeWeapon("frag_grenade_american_mp");
		self takeWeapon("frag_grenade_british_mp");
		self takeWeapon("frag_grenade_russian_mp");
		self takeWeapon("frag_grenade_german_mp");
	}
	if(game["am_frag_grenades_type"] == "am_cooked_slow") {
	
		self takeWeapon("slow_frag_grenade_american_mp");
		self takeWeapon("slow_frag_grenade_british_mp");
		self takeWeapon("slow_frag_grenade_russian_mp");
		self takeWeapon("slow_frag_grenade_german_mp");
	}
	if(game["am_frag_grenades_type"] == "original") {
	
		self takeWeapon("original_frag_grenade_american_mp");
		self takeWeapon("original_frag_grenade_british_mp");
		self takeWeapon("original_frag_grenade_russian_mp");
		self takeWeapon("original_frag_grenade_german_mp");
	}
	if(game["am_frag_grenades_type"] == "original_slow") {
	
		self takeWeapon("original_slow_frag_grenade_american_mp");
		self takeWeapon("original_slow_frag_grenade_british_mp");
		self takeWeapon("original_slow_frag_grenade_russian_mp");
		self takeWeapon("original_slow_frag_grenade_german_mp");
	}




	// * Wenn farbige Rauchgranaten *	
	if(game["am_enabled"] == 1 && game["am_use_colored_smokegrenades"] == 1) {	
	
		self takeWeapon("red_smoke_grenade_mp");
		self takeWeapon("blue_smoke_grenade_mp");
		self takeWeapon("green_smoke_grenade_mp");
	}
	else {

		self takeWeapon("smoke_grenade_american_mp");
		self takeWeapon("smoke_grenade_british_mp");
		self takeWeapon("smoke_grenade_russian_mp");
		self takeWeapon("smoke_grenade_german_mp");
	}





	fraggrenadecount 	= getWeaponBasedGrenadeCount(self.pers["weapon"]);
	smokegrenadecount 	= getWeaponBasedSmokeGrenadeCount(self.pers["weapon"]);	


	if(game["am_frag_grenade_count"] > -1) 	fraggrenadecount 	= game["am_frag_grenade_count"];
	if(game["am_smoke_grenade_count"] > -1) smokegrenadecount 	= game["am_smoke_grenade_count"];
	
	
	
	addfrag 	= 0;
	addsmoke 	= 0;
	
	if(game["am_enable_player_rank"] == 1) {

		if(isDefined(self.pers["rank"])) {

			switch(self.pers["rank"]) {

				case 1:
					addfrag		= game["am_if_rank_1_add_fraggrenades"];
					addsmoke 	= game["am_if_rank_1_add_smokegrenades"];
					break;
				case 2:
					addfrag		= game["am_if_rank_2_add_fraggrenades"];
					addsmoke 	= game["am_if_rank_2_add_smokegrenades"];
					break;
				case 3:
					addfrag		= game["am_if_rank_3_add_fraggrenades"];
					addsmoke 	= game["am_if_rank_3_add_smokegrenades"];
					break;
				case 4:
					addfrag		= game["am_if_rank_4_add_fraggrenades"];
					addsmoke 	= game["am_if_rank_4_add_smokegrenades"];
					break;
				case 5:
					addfrag		= game["am_if_rank_5_add_fraggrenades"];
					addsmoke 	= game["am_if_rank_5_add_smokegrenades"];
					break;
			}
		}
	}


	
	
	
	// * Fire und Gas bei bestimmter Class ... *

	if(game["am_enabled"] == 1 && game["am_use_player_class_system"] == 1) {

		self takeWeapon("fire_grenade_mp");
		self takeWeapon("gas_grenade_mp");


		if(self.pers["team"] == "allies") {
		
			if(self.pers["player_class"] == game["am_gas_grenade_has_allies_class"]) {

				smokegrenadecount = 1 + addsmoke;
				smokegrenadetype = "gas_grenade_mp";
		
				if(game["am_hud_style"] == 1) {
				
					self setClientCvar("am_ui_show_special_weapon", "1");				
					self.pers["am_ui_show_special_weapon"] = "1";
				}
				if(game["am_hud_style"] == 2) {
				
					self setClientCvar("am_ui_show_special_weapon", "11");		
					self.pers["am_ui_show_special_weapon"] = "11";
				}
				self giveWeapon(smokegrenadetype);
				self setWeaponClipAmmo(smokegrenadetype, smokegrenadecount);
			}
			else if(self.pers["player_class"] == game["am_fire_grenade_has_allies_class"]) {

				smokegrenadecount = 1 + addsmoke;
				smokegrenadetype = "fire_grenade_mp";
								
				if(game["am_hud_style"] == 1)  {
				
					self setClientCvar("am_ui_show_special_weapon", "2");					
					self.pers["am_ui_show_special_weapon"] = "2";
				}
				if(game["am_hud_style"] == 2)  {
				
					self setClientCvar("am_ui_show_special_weapon", "12");					
					self.pers["am_ui_show_special_weapon"] = "12";
				}
				self giveWeapon(smokegrenadetype);
				self setWeaponClipAmmo(smokegrenadetype, smokegrenadecount);	
			}
		}
		
		if(self.pers["team"] == "axis") {
		
			if(self.pers["player_class"] == game["am_gas_grenade_has_axis_class"]) {

				smokegrenadecount = 1 + addsmoke;
				smokegrenadetype = "gas_grenade_mp";
		
				if(game["am_hud_style"] == 1) {
					
					self setClientCvar("am_ui_show_special_weapon", "1");				
					self.pers["am_ui_show_special_weapon"] = "1";
				}
				if(game["am_hud_style"] == 2) {
				
					self setClientCvar("am_ui_show_special_weapon", "11");				
					self.pers["am_ui_show_special_weapon"] = "11";
				}
				self giveWeapon(smokegrenadetype);
				self setWeaponClipAmmo(smokegrenadetype, smokegrenadecount);
			}
			else if(self.pers["player_class"] == game["am_fire_grenade_has_axis_class"]) {

				smokegrenadecount = 1 + addsmoke;
				smokegrenadetype = "fire_grenade_mp";
					
				if(game["am_hud_style"] == 1) {
				
					self setClientCvar("am_ui_show_special_weapon", "2");					
					self.pers["am_ui_show_special_weapon"] = "2";
				}
				if(game["am_hud_style"] == 2) {
				
					self setClientCvar("am_ui_show_special_weapon", "12");					
					self.pers["am_ui_show_special_weapon"] = "12";
				}
				self giveWeapon(smokegrenadetype);
				self setWeaponClipAmmo(smokegrenadetype, smokegrenadecount);	
			}
		}		
	}
	
	if(smokegrenadecount < 1)  self.pers["smoke_grenade_text"] = " ";
	else {
	
		if(smokegrenadetype == "gas_grenade_mp")		self.pers["smoke_grenade_text"] = "@AM_MP_LNG_GAS";
		else if(smokegrenadetype == "fire_grenade_mp")	self.pers["smoke_grenade_text"] = "@AM_MP_LNG_FIRE";		
		else 											self.pers["smoke_grenade_text"] = "@AM_MP_LNG_SMOKE";
	}

	
	if(getcvarint("scr_allow_fraggrenades"))
	{
		if(fraggrenadecount)
		{
			self giveWeapon(grenadetype);
			self setWeaponClipAmmo(grenadetype, fraggrenadecount + addfrag);
		}
	}

	if(getcvarint("scr_allow_smokegrenades") && smokegrenadetype != "gas_grenade_mp" && smokegrenadetype != "fire_grenade_mp")
	{		
		if(smokegrenadecount)
		{
			self giveWeapon(smokegrenadetype);
			self setWeaponClipAmmo(smokegrenadetype, smokegrenadecount + addsmoke);
		}	
	}
		
	
	self switchtooffhand(grenadetype);
}

giveBinoculars()
{
	self endon("disconnect");

	self giveWeapon("binoculars_mp");
}


checkFreeSlotA() {

	self endon("disconnect");

	weapon = self getweaponslotweapon("primary");
	
	if(weapon == "none" || weapon == "") return true;
	
	return false;
}

checkFreeSlotB() {

	self endon("disconnect");

	weapon = self getweaponslotweapon("primaryb");

	if(weapon == "none" || weapon == "") return true;
	
	return false;
}


dropWeapon()
{
	self endon("disconnect");


	current = self getcurrentweapon();
	
	
	// * Nur wenn existierende und erlaubte Waffe *
	wp = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(current);
	
	if((!isPistol(wp) && !isMainWeapon(wp)) || wp == "sprintnoweapon_mp") 	current = "none";	
	if(game["am_allow_sniper_weapon_drop"] == 0 && isSniperWeapon(wp)) 		current = "none"; 
	if(game["am_allow_shotgun_weapon_drop"] == 0 && isShotgunWeapon(wp)) 	current = "none"; 
	
	
	if(current != "none") {
	

		weapon1 = self getweaponslotweapon("primary");
		weapon2 = self getweaponslotweapon("primaryb");

		if(current == weapon1)	currentslot = "primary";
		else					currentslot = "primaryb";
		

		clipsize 	= self getweaponslotclipammo(currentslot);
		reservesize = self getweaponslotammo(currentslot);

		
		// * mögliche Sprintwaffen Erweiterung "am_" entfernen *
		if(game["am_enabled"] == 1 && maps\mp\gametypes\_admiral_mod_utils::subStr(current,0,3) == "am_") {
				
			clipammo_count 	= self getweaponslotclipammo(currentslot);
			ammo_count 		= self getweaponslotammo(currentslot);

			current = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(current);

			self setWeaponSlotWeapon(currentslot, current);			
			self setWeaponSlotClipAmmo(currentslot, clipammo_count);
			self setWeaponSlotAmmo(currentslot, ammo_count);
			wait 0.1;
			self switchToWeapon(current);
			wait 0.1;			
			
		}


		// * Wenn Frag oder Smoke, dann keine Waffe und auch nicht weiter, sonst gibt es mit dem Pickup Probleme *
		if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(current, "frag_grenade") > -1) return;
		if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(current, "smoke_grenade") > -1) return;
		
		// * Damit nicht so viel Waffen rumliegen und der Gamestate-Error begrenzt wird *
		if(game["am_enabled"] == 1) {
		
			level thread maps\mp\gametypes\_admiral_mod_weapons::WeaponDrop("slot",current, clipsize, reservesize, self.origin, game["am_delete_dropped_weapon_time"]);
			self setWeaponSlotWeapon(currentslot, "none");	
		}
		else self dropItem(current);	
			
	}
}

dropOffhand()
{
	self endon("disconnect");

	current = self getcurrentoffhand();
	
	
	// * Wenn Frag Drop nicht erlaubt, dann nicht droppen *	
	if(isFragGrenade(current) && game["am_allow_nade_weapon_drop"] == 0) return;
	
		
	if(current != "none")
	{
		ammosize = self getammocount(current);

		if(ammosize) {
		
			// * Damit nicht so viel Waffen rumliegen und der Gamestate-Error begrenzt wird *
			if(game["am_enabled"] == 1) level thread maps\mp\gametypes\_admiral_mod_weapons::WeaponDrop("offhand",current, ammosize, 0, self.origin, game["am_delete_dropped_weapon_time"]);
			else 						self dropItem(current);
		
		}
	}
}

getWeaponBasedGrenadeCount(weapon)
{
	if(!isDefined(weapon)) return 0;

	
	nades = 0;

	switch(weapon)
	{
		case "springfield_mp":
		case "enfield_scope_mp":
		case "mosin_nagant_sniper_mp":
		case "kar98k_sniper_mp":
		case "enfield_mp":
		case "mosin_nagant_mp":
		case "kar98k_mp":
			nades = 3;
			break;
		case "m1carbine_mp":
		case "m1garand_mp":
		case "SVT40_mp":
		case "g43_mp":
		case "bar_mp":
		case "bren_mp":
		case "mp44_mp":
			nades = 2;
			break;
		case "panzerschreck_mp":
		case "30cal_walk_mp":
		case "mg42_bipod_walk_mp":
		case "mortar_cannon_walk_mp":
			nades = 0;
			break;
		default:
		case "thompson_mp":
		case "sten_mp":
		case "ppsh_mp":
		case "mp40_mp":
		case "PPS42_mp":
		case "shotgun_mp":
		case "greasegun_mp":
			nades = 1;
			break;
	}
	
	
	if(game["am_enabled"] == 1 && game["am_tournament_mode"] == 1 && isDefined(game["am_nades"]) && isDefined(level.weapons[weapon]) && isDefined(game["am_nades"][level.weapons[weapon].weapontype]) && game["am_nades"][level.weapons[weapon].weapontype] > -1) {
	
		nades = game["am_nades"][level.weapons[weapon].weapontype];
	}
		
	
	return nades;
	
}

getWeaponBasedSmokeGrenadeCount(weapon)
{

	if(!isDefined(weapon)) return 0;

	smokes = 0;

	switch(weapon)
	{
		case "thompson_mp":
		case "sten_mp":
		case "ppsh_mp":
		case "mp40_mp":
		case "PPS42_mp":
		case "shotgun_mp":
		case "greasegun_mp":
			smokes = 1;
			break;
		case "m1carbine_mp":
		case "m1garand_mp":
		case "enfield_mp":
		case "mosin_nagant_mp":
		case "SVT40_mp":
		case "kar98k_mp":
		case "g43_mp":
		case "bar_mp":
		case "bren_mp":
		case "mp44_mp":
		case "springfield_mp":
		case "enfield_scope_mp":
		case "mosin_nagant_sniper_mp":
		case "kar98k_sniper_mp":
		case "panzerschreck_mp":
		case "30cal_walk_mp":
		case "mg42_bipod_walk_mp":
		case "mortar_cannon_walk_mp":
		default:
			smokes = 0;
			break;
	}


	if(game["am_enabled"] == 1 && game["am_tournament_mode"] == 1 && isDefined(game["am_smokes"]) && isDefined(level.weapons[weapon]) && isDefined(game["am_smokes"][level.weapons[weapon].weapontype])) {
	
		smokes = game["am_smokes"][level.weapons[weapon].weapontype];
	}
	
	
	return smokes;

}






getFragGrenadeCount()
{
	if(self.pers["team"] == "allies") {
		grenadetype = "frag_grenade_" + game["allies"] + "_mp";
		
		if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_" + game["allies"] + "_mp"; 	
		if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_" + game["allies"] + "_mp"; 	
		if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_" + game["allies"] + "_mp";		
		if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_" + game["allies"] + "_mp";	
	}
	else {
	
		assert(self.pers["team"] == "axis");
		grenadetype = "frag_grenade_" + game["axis"] + "_mp";
		
		if(game["am_frag_grenades_type"] == "am_cooked") 		grenadetype = "frag_grenade_" + game["axis"] + "_mp"; 	
		if(game["am_frag_grenades_type"] == "am_cooked_slow") 	grenadetype = "slow_frag_grenade_" + game["axis"] + "_mp"; 	
		if(game["am_frag_grenades_type"] == "original") 		grenadetype = "original_frag_grenade_" + game["axis"] + "_mp";		
		if(game["am_frag_grenades_type"] == "original_slow") 	grenadetype = "original_slow_frag_grenade_" + game["axis"] + "_mp";	
	}

	count = self getammocount(grenadetype);
	return count;
}

getSmokeGrenadeCount()
{
	if(self.pers["team"] == "allies")
		grenadetype = "smoke_grenade_" + game["allies"] + "_mp";
	else
	{
		assert(self.pers["team"] == "axis");
		grenadetype = "smoke_grenade_" + game["axis"] + "_mp";
	}

	count = self getammocount(grenadetype);
	return count;
}

isPistol(weapon)
{
	if(!isDefined(weapon)) return false;

	switch(weapon)
	{
	case "colt_mp":
	case "webley_mp":
	case "luger_mp":
	case "TT30_mp":
		return true;
	default:
		return false;
	}
}

isMainWeapon(weapon)
{
	// Include any main weapons that can be picked up

	switch(weapon)
	{
		case "greasegun_mp":
		case "m1carbine_mp":
		case "m1garand_mp":
		case "thompson_mp":
		case "bar_mp":
		case "springfield_mp":
		case "sten_mp":
		case "enfield_mp":
		case "bren_mp":
		case "enfield_scope_mp":
		case "mosin_nagant_mp":
		case "SVT40_mp":
		case "PPS42_mp":
		case "ppsh_mp":
		case "mosin_nagant_sniper_mp":
		case "kar98k_mp":
		case "g43_mp":
		case "mp40_mp":
		case "mp44_mp":
		case "kar98k_sniper_mp":
		case "shotgun_mp":
		case "panzerschreck_mp":	
		case "30cal_walk_mp":
		case "mg42_bipod_walk_mp":	
		case "mortar_cannon_walk_mp":
		case "sprintnoweapon_mp":
			return true;
		default:
			return false;
	}
}


isSniperWeapon(weapon)
{
	// Include any main weapons that can be picked up

	switch(weapon)
	{
		case "springfield_mp":
		case "enfield_scope_mp":
		case "mosin_nagant_sniper_mp":
		case "kar98k_sniper_mp":
			return true;
		default:
			return false;
	}
}

isRifleWeapon(weapon)
{
	// Include any main weapons that can be picked up

	switch(weapon)
	{
		case "m1carbine_mp":
		case "m1garand_mp":
		case "enfield_mp":
		case "mosin_nagant_mp":
		case "SVT40_mp":
		case "kar98k_mp":
		case "g43_mp":
			return true;
		default:
			return false;
	}
}

isNormalWeapon(weapon)
{
	// Include any main weapons that can be picked up

	switch(weapon)
	{
		case "greasegun_mp":
		case "thompson_mp":
		case "bar_mp":
		case "sten_mp":
		case "bren_mp":
		case "PPS42_mp":
		case "ppsh_mp":
		case "mp40_mp":
		case "mp44_mp":
			return true;
		default:
			return false;
	}
}

isShotgunWeapon(weapon)
{
	// Include any main weapons that can be picked up

	switch(weapon)
	{		
		case "shotgun_mp":		
			return true;
		default:
			return false;
	}
}


isFragGrenade(weapon)
{

	switch(weapon)
	{		
		case "frag_grenade_american_mp":		
			return true;
		case "frag_grenade_british_mp":		
			return true;
		case "frag_grenade_russian_mp":		
			return true;
		case "frag_grenade_german_mp":		
			return true;
		case "slow_frag_grenade_american_mp":		
			return true;
		case "slow_frag_grenade_british_mp":		
			return true;
		case "slow_frag_grenade_russian_mp":		
			return true;
		case "slow_frag_grenade_german_mp":		
			return true;		
	}
	
	return false;
}



isNoSprintWeapon(weapon)
{

	switch(weapon)
	{
		case "panzerschreck_mp":
		case "mg42_bipod_walk_mp":
		case "30cal_walk_mp":
		case "mortar_cannon_walk_mp":
			return true;
		default:
			return false;
	}
}  	
    	
    	
restrictWeaponByServerCvars(response)
{
	switch(response)
	{
	// American
	case "m1carbine_mp":
		if(!getcvarint("scr_allow_m1carbine"))
		{
			//self iprintln(&"MP_M1A1_CARBINE_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "m1garand_mp":
		if(!getcvarint("scr_allow_m1garand"))
		{
			//self iprintln(&"MP_M1_GARAND_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "thompson_mp":
		if(!getcvarint("scr_allow_thompson"))
		{
			//self iprintln(&"MP_THOMPSON_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "bar_mp":
		if(!getcvarint("scr_allow_bar"))
		{
			//self iprintln(&"MP_BAR_IS_A_RESTRICTED_WEAPON");
			response = "restricted";
		}
		break;

	case "springfield_mp":
		if(!getcvarint("scr_allow_springfield"))
		{
			//self iprintln(&"MP_SPRINGFIELD_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "greasegun_mp":
		if(!getcvarint("scr_allow_greasegun"))
		{
			//self iprintln(&"MP_GREASEGUN_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "shotgun_mp":
		if(!getcvarint("scr_allow_shotgun"))
		{
			//self iprintln(&"MP_SHOTGUN_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	// British
	case "enfield_mp":
		if(!getcvarint("scr_allow_enfield"))
		{
			//self iprintln(&"MP_LEEENFIELD_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "sten_mp":
		if(!getcvarint("scr_allow_sten"))
		{
			//self iprintln(&"MP_STEN_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "bren_mp":
		if(!getcvarint("scr_allow_bren"))
		{
			//self iprintln(&"MP_BREN_LMG_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "enfield_scope_mp":
		if(!getcvarint("scr_allow_enfieldsniper"))
		{
			//self iprintln(&"MP_BREN_LMG_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	// Russian
	case "mosin_nagant_mp":
		if(!getcvarint("scr_allow_nagant"))
		{
			//self iprintln(&"MP_MOSINNAGANT_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "SVT40_mp":
		if(!getcvarint("scr_allow_svt40"))
		{
			//self iprintln(&"MP_MOSINNAGANT_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "PPS42_mp":
		if(!getcvarint("scr_allow_pps42"))
		{
			//self iprintln(&"MP_PPSH_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "ppsh_mp":
		if(!getcvarint("scr_allow_ppsh"))
		{
			//self iprintln(&"MP_PPSH_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "mosin_nagant_sniper_mp":
		if(!getcvarint("scr_allow_nagantsniper"))
		{
			//self iprintln(&"MP_SCOPED_MOSINNAGANT_IS");
			response = "restricted";
		}
		break;

	// German
	case "kar98k_mp":
		if(!getcvarint("scr_allow_kar98k"))
		{
			//self iprintln(&"MP_KAR98K_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "g43_mp":
		if(!getcvarint("scr_allow_g43"))
		{
			//self iprintln(&"MP_KAR98K_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "mp40_mp":
		if(!getcvarint("scr_allow_mp40"))
		{
			//self iprintln(&"MP_MP40_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "mp44_mp":
		if(!getcvarint("scr_allow_mp44"))
		{
			//self iprintln(&"MP_MP44_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "kar98k_sniper_mp":
		if(!getcvarint("scr_allow_kar98ksniper"))
		{
			//self iprintln(&"MP_SCOPED_KAR98K_IS_A_RESTRICTED");
			response = "restricted";
		}
		break;

	case "fraggrenade":
		if(!getcvarint("scr_allow_fraggrenades"))
		{
			//self iprintln("Frag grenades are restricted");
			response = "restricted";
		}
		break;

	case "smokegrenade":
		if(!getcvarint("scr_allow_smokegrenades"))
		{
			//self iprintln("Smoke grenades are restricted");
			response = "restricted";
		}
		break;
	
	case "panzerschreck_mp":
		if(!getcvarint("scr_allow_panzerschreck"))
		{
			//self iprintln("Panzerschreck is restricted");
			response = "restricted";
		}
		break;
	
	case "30cal_walk_mp":
		if(!getcvarint("scr_allow_30cal"))
		{
			//self iprintln("30cal is restricted");
			response = "restricted";
		}
		break;

	case "mg42_bipod_walk_mp":
		if(!getcvarint("scr_allow_mg42"))
		{
			//self iprintln("MG42 is restricted");
			response = "restricted";
		}
		break;
	
	case "mortar_cannon_walk_mp":
		if(!getcvarint("scr_allow_mortar_cannon"))
		{
			//self iprintln("Mortar Cannon is restricted");
			response = "restricted";
		}
		break;


	case "colt_mp":
		break;

	case "webley_mp":
		break;

	case "TT30_mp":
		break;

	case "luger_mp":
		break;
		
		
			
	default:
		//self iprintln(&"MP_UNKNOWN_WEAPON_SELECTED");
		response = "restricted";
		break;
		
	}

	return response;
}

// TODO: This doesn't handle offhands
watchWeaponUsage()
{
	self endon("spawned_player");
	self endon("disconnect");

	self.usedweapons = false;

	while(self attackButtonPressed())
		wait .1;

	while(!(self attackButtonPressed()))
		wait .1;

	self.usedweapons = true;
}

getWeaponName(weapon)
{
	switch(weapon)
	{
	// American
	case "m1carbine_mp":
		weaponname = &"WEAPON_M1A1CARBINE";
		break;

	case "m1garand_mp":
		weaponname = &"WEAPON_M1GARAND";
		break;

	case "thompson_mp":
		weaponname = &"WEAPON_THOMPSON";
		break;

	case "bar_mp":
		weaponname = &"WEAPON_BAR";
		break;

	case "springfield_mp":
		weaponname = &"WEAPON_SPRINGFIELD";
		break;

	case "greasegun_mp":
		weaponname = &"WEAPON_GREASEGUN";
		break;

	case "shotgun_mp":
		weaponname = &"WEAPON_SHOTGUN";
		break;

//	case "30cal_mp":
//		weaponname = &"PI_WEAPON_MP_30CAL";
//		break;

//	case "M9_Bazooka":
//		weaponname = &"PI_WEAPON_MP_BAZOOKA";
//		break;

	// British
	case "enfield_mp":
		weaponname = &"WEAPON_LEEENFIELD";
		break;

	case "sten_mp":
		weaponname = &"WEAPON_STEN";
		break;

	case "bren_mp":
		weaponname = &"WEAPON_BREN";
		break;

	case "enfield_scope_mp":
		weaponname = &"WEAPON_SCOPEDLEEENFIELD";
		break;

	// Russian
	case "mosin_nagant_mp":
		weaponname = &"WEAPON_MOSINNAGANT";
		break;

	case "SVT40_mp":
		weaponname = &"WEAPON_SVT40";
		break;

	case "PPS42_mp":
		weaponname = &"WEAPON_PPS42";
		break;

	case "ppsh_mp":
		weaponname = &"WEAPON_PPSH";
		break;

	case "mosin_nagant_sniper_mp":
		weaponname = &"WEAPON_SCOPEDMOSINNAGANT";
		break;

	//German
	case "kar98k_mp":
		weaponname = &"WEAPON_KAR98K";
		break;

	case "g43_mp":
		weaponname = &"WEAPON_G43";
		break;

	case "mp40_mp":
		weaponname = &"WEAPON_MP40";
		break;

	case "mp44_mp":
		weaponname = &"WEAPON_MP44";
		break;

	case "kar98k_sniper_mp":
		weaponname = &"WEAPON_SCOPEDKAR98K";
		break;

	case "colt_mp":
		weaponname = &"WEAPON_COLT45";
		break;

	case "webley_mp":
		weaponname = &"WEAPON_WEBLEY";
		break;

	case "TT30_mp":
		weaponname = &"WEAPON_TT30";
		break;

	case "luger_mp":
		weaponname = &"WEAPON_LUGER";
		break;

	case "panzerschreck_mp":
		weaponname = &"AM_MP_WEAPON_PANZERSCHRECK";
		break;

	case "30cal_walk_mp":
		weaponname = &"AM_MP_WEAPON_30CAL";
		break;
		
	case "mg42_bipod_walk_mp":
		weaponname = &"AM_MP_WEAPON_MG42";
		break;

	case "mortar_cannon_walk_mp":
		weaponname = &"AM_MP_WEAPON_MORTAR_CANNON";
		break;

	case "gas_grenade_mp":
		weaponname = &"AM_MP_WEAPON_GAS_GRENADE";
		break;

	case "fire_grenade_mp":
		weaponname = &"AM_MP_WEAPON_FIRE_GRENADE";
		break;

	case "knife_mp":
		weaponname = &"AM_MP_WEAPON_KNIFE";
		break;


//
//	case "dp28_mp":
//		weaponname = &"PI_WEAPON_MP_DP28";
//		break;

	default:
		weaponname = &"WEAPON_UNKNOWNWEAPON";
		break;
	}

	return weaponname;
}



getweapon_nr(weapon)
{
	switch(weapon)
	{
	
	
	case "colt_mp":
		weapon_nr = 1;
		break;

	case "webley_mp":
		weapon_nr = 2;
		break;

	case "TT30_mp":
		weapon_nr = 3;
		break;

	case "luger_mp":
		weapon_nr = 4;
		break;	
	
	
	
	// American
	case "m1carbine_mp":
		weapon_nr = 5;
		break;

	case "m1garand_mp":
		weapon_nr = 6;
		break;

	case "thompson_mp":
		weapon_nr = 7;
		break;

	case "bar_mp":
		weapon_nr = 8;
		break;

	case "springfield_mp":
		weapon_nr = 9;
		break;

	case "greasegun_mp":
		weapon_nr = 10;
		break;

	case "shotgun_mp":
		weapon_nr = 11;
		break;



	// British
	case "enfield_mp":
		weapon_nr = 12;
		break;

	case "sten_mp":
		weapon_nr = 13;
		break;

	case "bren_mp":
		weapon_nr = 14;
		break;

	case "enfield_scope_mp":
		weapon_nr = 15;
		break;



	// Russian
	case "mosin_nagant_mp":
		weapon_nr = 16;
		break;

	case "SVT40_mp":
		weapon_nr = 17;
		break;

	case "PPS42_mp":
		weapon_nr = 18;
		break;

	case "ppsh_mp":
		weapon_nr = 19;
		break;

	case "mosin_nagant_sniper_mp":
		weapon_nr = 20;
		break;
		
		

	//German
	case "kar98k_mp":
		weapon_nr = 21;
		break;

	case "g43_mp":
		weapon_nr = 22;
		break;

	case "g43_scoped_mp":
		weapon_nr = 23;
		break;

	case "mp40_mp":
		weapon_nr = 24;
		break;

	case "mp44_mp":
		weapon_nr = 25;
		break;

	case "kar98k_sniper_mp":
		weapon_nr = 26;
		break;




// Rest
	case "panzerschreck_mp":
		weapon_nr = 27;
		break;

	case "30cal_walk_mp":
		weapon_nr = 28;
		break;
		
	case "mg42_bipod_walk_mp":
		weapon_nr = 29;
		break;

	case "panzerfaust_mp":
		weapon_nr = 30;
		break;

	case "mortar_cannon_walk_mp":
		weapon_nr = 31;
		break;


	default:
		weapon_nr = 0;
		break;
	}

	return weapon_nr;
}



useAn(weapon)
{
	switch(weapon)
	{
	case "m1carbine_mp":
	case "m1garand_mp":
	case "mp40_mp":
	case "mp44_mp":
	case "shotgun_mp":
		result = true;
		break;

	default:
		result = false;
		break;
	}

	return result;
}

updateAllowed()
{
	for(i = 0; i < level.weaponnames.size; i++)
	{
		weaponname = level.weaponnames[i];

		cvarvalue = getCvarInt(level.weapons[weaponname].server_allowcvar);
		if(level.weapons[weaponname].allow != cvarvalue)
		{
			level.weapons[weaponname].allow = cvarvalue;

			thread updateAllowedAllClients(weaponname);
		}
	}
}

updateAllowedAllClients(weaponname)
{
	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
		players[i] updateAllowedSingleClient(weaponname);
}

updateAllowedSingleClient(weaponname)
{
	self setClientCvar(level.weapons[weaponname].client_allowcvar, level.weapons[weaponname].allow);
}


updateAllAllowedSingleClient()
{
	for(i = 0; i < level.weaponnames.size; i++)
	{
		weaponname = level.weaponnames[i];
		self updateAllowedSingleClient(weaponname);
	}
}

clearWeaponSlots() {

	self setWeaponSlotWeapon("primary", "none");			
	self setWeaponSlotWeapon("primaryb", "none");				
}


giveBotWeapon() {

	
	switch(game["allies"])
	{
	
		case "american":	
			return "thompson_mp";
		case "british":		
			return "m1garand_mp";
		case "russian":		
			return "SVT40_mp";
				
	}	
}




reduceAmmoByRank(slot) {

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");

	if(game["am_enable_player_rank"] && game["am_reduce_ammo_per_rank"] == 1 && isDefined(self.pers["rank"])) {
			
		ammo_count 		= self getweaponslotammo(slot);		
		ammo_count		= int(ammo_count/2);
		
		if(ammo_count > 0) 	ammo_count = ammo_count + int((ammo_count/5) * self.pers["rank"]);
				
		self setWeaponSlotAmmo(slot, ammo_count);	
	}
}



