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

	resettimeout();

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

	// clean player hud
	self thread ww2x\_wwx_hud::cleanplayer();

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

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

	if(level.wwx_currentgt != "dm" && level.wwx_currentgt != "sd" && level.wwx_currentgt != "esd" && level.wwx_currentgt != "lms")
	{
		self.psoffsettime = 0;
		maps\mp\gametypes\_spectating::setSpectatePermissions();
	}

	if(level.wwx_currentgt == "sd" || level.wwx_currentgt == "esd")
	{
		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");
	}

	self setClientCvar("cg_objectiveText", "");

	if(level.wwx_currentgt == "htf")
	{
		if(level.scorelimit > 0)
			self setClientCvar("cg_objectiveText", &"MP_HTF_OBJ_TEXT", level.scorelimit);
		else
			self setClientCvar("cg_objectiveText", &"MP_HTF_OBJ_NOSCORE");
	}

	if(level.wwx_currentgt == "lts")
	{
		if(level.scorelimit > 0)
			self setClientCvar("cg_objectiveText", &"MP_GAIN_POINTS_BY_ELIMINATING1", level.scorelimit);
		else
			self setClientCvar("cg_objectiveText", &"MP_GAIN_POINTS_BY_ELIMINATING1_NOSCORE");		

		level maps\mp\gametypes\lts::updateTeamStatus();
		self.usedweapons = false;
	}

	if(level.wwx_currentgt == "ihtf")
	{
		if(level.scorelimit > 0)
			self setClientCvar("cg_objectiveText", &"MP_IHTF_OBJ_TEXT", level.scorelimit);
		else
			self setClientCvar("cg_objectiveText", &"MP_IHTF_OBJ_NOSCORE");
	}

	if(level.wwx_currentgt == "lib")
	{
	if (level.roundlength <= 0)
		self setClientCvar("cg_objectiveText", &"MP_LIB_OBJ3");
	else
		self setClientCvar("cg_objectiveText", &"MP_LIB_OBJ4");
	}

	if(level.wwx_currentgt == "hq") level maps\mp\gametypes\hq::hq_removeall_hudelems(self);
	
	if(level.wwx_currentgt == "sd")
	{
		level maps\mp\gametypes\sd::updateTeamStatus();
		self.usedweapons = false;
	}

	if(level.wwx_currentgt == "esd")
	{
		level maps\mp\gametypes\esd::updateTeamStatus();
		self.usedweapons = false;
	}
}

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

	resettimeout();

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

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

	if(level.wwx_currentgt != "dm" || level.wwx_currentgt != "lms")
	{
		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");

	if(level.wwx_currentgt == "ctf") self thread maps\mp\gametypes\ctf::updateTimer();
	if(level.wwx_currentgt == "htf") self thread maps\mp\gametypes\htf::updateTimer();
	
	if(level.wwx_currentgt == "hq")
	{
		level maps\mp\gametypes\hq::hq_removeall_hudelems(self);
		self thread maps\mp\gametypes\ctf::updateTimer();
	}
}
