
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
init( modVersion )
{
	self endon( "disconnect" );
	self endon( "endstats" );
	self endon( "spawned_player" );
	self thread destroyonEnd();
	self thread OnPlayerSpawned();
	
OnPlayerSpawned()
{
	for(;;)
	{
		level waittill("player_spawn", player);
		player thread Stats();
		player thread fader();
		player thread killhud{);
	}
}

Stats()
{
	self.hud_stattext = newClientHudElem(self);
    self.hud_stattext.foreground = true;
	self.hud_stattext.alignX = "left";
	self.hud_stattext.alignY = "top";
	self.hud_stattext.horzAlign = "left";
    self.hud_stattext.vertAlign = "top";
    self.hud_stattext.x = 0;
    self.hud_stattext.y = 145;
    self.hud_stattext.sort = 0;
  	self.hud_stattext.fontScale = 1.4;
	self.hud_stattext.color = (1,1,1);
	self.hud_stattext.font = "objective";
	self.hud_stattext.glowColor = (0.0, 0.0, 1.0);
	self.hud_stattext.glowAlpha = 1;
 	self.hud_stattext.hidewheninmenu = false;	
	
	self.hudscore = newClientHudElem(self);
    self.hudscore.foreground = true;
	self.hudscore.alignX = "left";
	self.hudscore.alignY = "top";
	self.hudscore.horzAlign = "left";
    self.hudscore.vertAlign = "top";
    self.hudscore.x = 0;
    self.hudscore.y = 165;
    self.hudscore.sort = 0;
  	self.hudscore.fontScale = 1.4;
	self.hudscore.color = (1,1,1);
	self.hudscore.font = "objective";
	self.hudscore.glowColor = (0.0, 0.0, 1.0);
	self.hudscore.glowAlpha = 1;
 	self.hudscore.hidewheninmenu = false;	
	
	self.hudkills = newClientHudElem(self);
    self.hudkills.foreground = true;
	self.hudkills.alignX = "left";
	self.hudkills.alignY = "top";
	self.hudkills.horzAlign = "left";
    self.hudkills.vertAlign = "top";
    self.hudkills.x = 0;
    self.hudkills.y = 185;
    self.hudkills.sort = 0;
  	self.hudkills.fontScale = 1.4;
	self.hudkills.color = (1,1,1);
	self.hudkills.font = "objective";
	self.hudkills.glowColor = (0.0, 0.0, 1.0);
	self.hudkills.glowAlpha = 1;
 	self.hudkills.hidewheninmenu = false;	
	
	self.huddeaths = newClientHudElem(self);
    self.huddeaths.foreground = true;
	self.huddeaths.alignX = "left";
	self.huddeaths.alignY = "top";
	self.huddeaths.horzAlign = "left";
    self.huddeaths.vertAlign = "top";
    self.huddeaths.x = 0;
    self.huddeaths.y = 205;
    self.huddeaths.sort = 0;
  	self.huddeaths.fontScale = 1.4;
	self.huddeaths.color = (1,1,1);
	self.huddeaths.font = "objective";
	self.huddeaths.glowColor = (0.0, 0.0, 1.0);
	self.huddeaths.glowAlpha = 1;
 	self.huddeaths.hidewheninmenu = false;	
	
	/*self.hudtime = newClientHudElem(self);
    self.hudtime.foreground = true;
	self.hudtime.alignX = "left";
	self.hudtime.alignY = "top";
	self.hudtime.horzAlign = "left";
    self.hudtime.vertAlign = "top";
    self.hudtime.x = 0;
    self.hudtime.y = 245;
    self.hudtime.sort = 0;
  	self.hudtime.fontScale = 1.4;
	self.hudtime.color = (1,1,1);
	self.hudtime.font = "objective";
	self.hudtime.glowColor = (0.0, 0.0, 1.0);
	self.hudtime.glowAlpha = 1;
 	self.hudtime.hidewheninmenu = false;
	
	self.hudtime2 = newClientHudElem(self);
    self.hudtime2.foreground = true;
	self.hudtime2.alignX = "left";
	self.hudtime2.alignY = "top";
	self.hudtime2.horzAlign = "left";
    self.hudtime2.vertAlign = "top";
    self.hudtime2.x = 0;
    self.hudtime2.y = 225;
    self.hudtime2.sort = 0;
  	self.hudtime2.fontScale = 1.4;
	self.hudtime2.color = (1,1,1);
	self.hudtime2.font = "objective";
	self.hudtime2.glowColor = (0.0, 0.0, 1.0);
	self.hudtime2.glowAlpha = 1;
 	self.hudtime2.hidewheninmenu = false;*/	
	
	self.hud_stattext setText( "Stats" );
	self.hudscore.label = &"Score: &&1";
	//self.hudscore SetClockUp( 5, 60, "hudStopwatch", 64, 64 ); 
	self.hudkills.label = &"Kills: &&1";
	self.huddeaths.label = &"Deaths: &&1";
	trol = 10;
	//text = &"Time: &&1 / " + trol + "";
	//self.hudtime2.label = text;
	
	self.hudscore setValue( self.pers["score"] );
	self.hudkills setValue( self.pers["kills"] );
	self.huddeaths setValue( self.pers["deaths"] );
	if(self.pers["time"] == 0 )
	{
		self.hudtime.label = &"Record: &&1";
		self.hudtime setValue( 0 );
	}
	else
	{
		//self.hudtime.label = &"Record: &&1";
		//self.hudtime setValue( self.pers["time"] );
	}
	
	self.hud_stattext MoveTo(1.5,-10);
	self.hudscore MoveTo(1.5,-10);
	self.hudkills MoveTo(1.5,-10);
	self.huddeaths MoveTo(1.5,-10);
	//self.hudtime MoveTo(1.5,-10);
	//self.hudtime2 MoveTo(1.5,-10)	
{
	
	while(1)
	{
		/*
		self.hud_stattext fadeOverTime(1);
		self.hud_stattext.alpha = 1;	
		self.hud_stat fadeOverTime(1);
		self.hud_stat.alpha = 1;	
		self.hud_stats fadeOverTime(1);
		self.hud_stats.alpha = 1;	
		self.hud_status fadeOverTime(1);
		self.hud_status.alpha = 1;
		*/					
			
		oldscore = self.pers["score"];	
		oldkills = self.pers["kills"];
		olddeaths = self.pers["deaths"];
		oldtime = self.pers["time"];
		oldyourtime = self.yourtime;
		
		while(oldscore == self.pers["score"] && oldkills == self.pers["kills"] && olddeaths == self.pers["deaths"] && oldtime == self.pers["time"] )
			wait .05;
	
		if(oldscore != self.pers["score"])
		{
			self.hudscore thread fader(self.pers["score"]);
		}
		if(oldkills != self.pers["kills"])	
		{
			self.hudkills thread fader(self.pers["kills"]);	
		}
		if(olddeaths != self.pers["deaths"])	
		{
			self.huddeaths thread fader(self.pers["deaths"]);		
		}
		if(oldtime != self.pers["time"])
		{
			self.hudtime thread fader(self.pers["time"]);
		}		
	}
}

fader()
{
	self fadeOverTime(.2);
	self.alpha = 0;
	wait .25;
	self setValue( value );
	self fadeOverTime(.6);
	self.alpha = 1;		
}

destroyonEnd()
{
	w8 = 2;
	
	if( game["roundsplayed"] != level.dvar["round_limit"] )
		w8 = 8;
		
	self endon("disconnect");
	//level waittill("endround");
	
	//wait w8;
	
/*	self.hud_stattext thread killhud();
	self.hudscore thread killhud();	
	self.hudkills thread killhud();
	self.huddeaths thread killhud();
	self.hudtime thread killhud();
	self.hudtime2 thread killhud();*/
	//self.hud_stattext MoveTo(1.5,0);
	self.hudscore MoveTo(1.5,0);
	self.hudkills MoveTo(1.5,0);
	self.huddeaths MoveTo(1.5,0);
	self.hudtime MoveTo(1.5,0);
	self.hudtime2 MoveTo(1.5,0);
}

MoveTo2()
{
	self moveOverTime(time);
	if(isDefined(x))
		self.x = x;
		
	if(isDefined(y))
		self.y = y;
}

killhud()
{
	self fadeOverTime(1);
	self.alpha = 0;
	wait 1;
	self destroy();
}

fasterfader(value)
{
	self fadeOverTime(.05);
	self.alpha = 0;
	wait .05;
	self setValue( value );
	self fadeOverTime(.05);
	self.alpha = 1;		
}