
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
init( modVersion )
{
	thread OnPlayerSpawned();
	
}

OnPlayerSpawned()
{
	for(;;)
	{
		level waittill("player_spawn", player);
		player thread StatsText();
		player thread StatsScore();
		player thread StatsKills();
		player thread StatsDeaths();
		player thread StatsMelee();
		player thread StatsHeadshot();
		player thread UpdateStats();
		player thread DestroyStats();
	}
}

StatsText()
{
	if(isdefined(self.hud_Stats))
		self.hud_Stats destroy();

	self.hud_Stats = newClientHudElem(self);
	self.hud_Stats.alignX = "right";
	self.hud_Stats.alignY = "top";
	self.hud_Stats.horzAlign = "right";
	self.hud_Stats.vertAlign = "top";
	self.hud_Stats.x = -6;
	self.hud_Stats.y = 150;
	self.hud_Stats.sort = 0;
	self.hud_Stats.fontScale = 1.4;
	self.hud_Stats.font = "objective";
	self.hud_Stats.glowColor = (0,0,1);
	self.hud_Stats.glowAlpha = 1;
	self.hud_Stats.hidewheninmenu = true;
	self.hud_Stats setText("Stats");
}

StatsScore()
{
	if(isdefined(self.hud_StatsScore))
		self.hud_StatsScore destroy();

	self.hud_StatsScore = newClientHudElem(self);
	self.hud_StatsScore.alignX = "right";
	self.hud_StatsScore.alignY = "top";
	self.hud_StatsScore.horzAlign = "right";
	self.hud_StatsScore.vertAlign = "top";
	self.hud_StatsScore.x = -6;
	self.hud_StatsScore.y = 165;
	self.hud_StatsScore.sort = 0;
	self.hud_StatsScore.fontScale = 1.4;
	self.hud_StatsScore.font = "objective";
	self.hud_StatsScore.glowColor = (0,0,1);
	self.hud_StatsScore.glowAlpha = 1;
	self.hud_StatsScore.hidewheninmenu = true;
	self.hud_StatsScore.label = &"Score: &&1";

	if(isDefined(self.pers["score"]))
		self.hud_StatsScore setValue( self.pers["score"] );
}

StatsKills()
{
	if(isdefined(self.hud_StatsKills))
		self.hud_StatsKills destroy();

	self.hud_StatsKills = newClientHudElem(self);
	self.hud_StatsKills.alignX = "right";
	self.hud_StatsKills.alignY = "top";
	self.hud_StatsKills.horzAlign = "right";
	self.hud_StatsKills.vertAlign = "top";
	self.hud_StatsKills.x = -6;
	self.hud_StatsKills.y = 180;
	self.hud_StatsKills.sort = 0;
	self.hud_StatsKills.fontScale = 1.4;
	self.hud_StatsKills.font = "objective";
	self.hud_StatsKills.glowColor = (0,0,1);
	self.hud_StatsKills.glowAlpha = 1;
	self.hud_StatsKills.hidewheninmenu = true;
	self.hud_StatsKills.label = &"Kills: &&1";

	if(isDefined(self.pers["kills"]))
		self.hud_StatsKills setValue( self.pers["kills"] );
}

StatsDeaths()
{
	if(isdefined(self.hud_StatsDeaths))
		self.hud_StatsDeaths destroy();

	self.hud_StatsDeaths = newClientHudElem(self);
	self.hud_StatsDeaths.alignX = "right";
	self.hud_StatsDeaths.alignY = "top";
	self.hud_StatsDeaths.horzAlign = "right";
	self.hud_StatsDeaths.vertAlign = "top";
	self.hud_StatsDeaths.x = -6;
	self.hud_StatsDeaths.y = 195;
	self.hud_StatsDeaths.sort = 0;
	self.hud_StatsDeaths.fontScale = 1.4;
	self.hud_StatsDeaths.font = "objective";
	self.hud_StatsDeaths.glowColor = (0,0,1);
	self.hud_StatsDeaths.glowAlpha = 1;
	self.hud_StatsDeaths.hidewheninmenu = true;
	self.hud_StatsDeaths.label = &"Deaths: &&1";

	if(isDefined(self.pers["deaths"]))
		self.hud_StatsDeaths setValue( self.pers["deaths"] );
}

StatsMelee()
{
	if(isdefined(self.hud_StatsMelee))
		self.hud_StatsMelee destroy();

	self.hud_StatsMelee = newClientHudElem(self);
	self.hud_StatsMelee.alignX = "right";
	self.hud_StatsMelee.alignY = "top";
	self.hud_StatsMelee.horzAlign = "right";
	self.hud_StatsMelee.vertAlign = "top";
	self.hud_StatsMelee.x = -6;
	self.hud_StatsMelee.y = 210;
	self.hud_StatsMelee.sort = 0;
	self.hud_StatsMelee.fontScale = 1.4;
	self.hud_StatsMelee.font = "objective";
	self.hud_StatsMelee.glowColor = (0,0,1);
	self.hud_StatsMelee.glowAlpha = 1;
	self.hud_StatsMelee.hidewheninmenu = true;
	self.hud_StatsMelee.label = &"Knife: &&1";

	if(isDefined(self.pers["knifes"]))
		self.hud_StatsMelee setValue( self.pers["knifes"] );
}


StatsHeadshot()
{
	if(isdefined(self.hud_StatsHeadshot))
		self.hud_StatsHeadshot destroy();

	self.hud_StatsHeadshot = newClientHudElem(self);
	self.hud_StatsHeadshot.alignX = "right";
	self.hud_StatsHeadshot.alignY = "top";
	self.hud_StatsHeadshot.horzAlign = "right";
	self.hud_StatsHeadshot.vertAlign = "top";
	self.hud_StatsHeadshot.x = -6;
	self.hud_StatsHeadshot.y = 225;
	self.hud_StatsHeadshot.sort = 0;
	self.hud_StatsHeadshot.fontScale = 1.4;
	self.hud_StatsHeadshot.font = "objective";
	self.hud_StatsHeadshot.glowColor = (0,0,1);
	self.hud_StatsHeadshot.glowAlpha = 1;
	self.hud_StatsHeadshot.hidewheninmenu = true;
	self.hud_StatsHeadshot.label = &"Headshot: &&1";

	if(isDefined(self.pers["headshots"]))
		self.hud_StatsHeadshot setValue( self.pers["headshots"] );
}


UpdateStats()
{
self endon( "disconnect" );
self endon( "joined_spectators" );
self endon( "endstats" );
plugins\_name::init();
}

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

DestroyStats()
{
self endon( "disconnect" );
self endon( "joined_spectators" );
self endon( "endstats" );

	level waittill("endround");
	wait 1;
	self.hud_Stats thread killhud();
	self.hud_StatsScore thread killhud();
	self.hud_StatsDeaths thread killhud();
	self.hud_StatsMelee thread killhud();
	self.hud_StatsHeadshot thread killhud();
	self.hud_StatsKills thread killhud();
}

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