/* Plugin generated by AMXX-Studio */

#include <amxmodx>  
#include <csstats>  
#include <cstrike>  
#include <fun>  

/*Description 

What this plugin does is determine a user's overall kills/deaths 
and sets their scores accordingly. So, if I have for example 300 kills and 123 deaths, 
when I join the server my score will be 300-123.

Credits:
GHW_Chronic - Coding help, DoD version. 
v3x - Coding help. 
Me - Idea + original, original, coding (and then the optimization which comes later ) 
Suicid3 - Finding RoundStart function. 
Kraugh - Explaining runtime error problem, fixing!

					Changelog
				v. 1.0 - Original Coding
				v. 1.1 - Addition of Description, credits, changelog
				v. 1.2 - Coding Optimization
				v. 1.3 - Removed sv_restartround bug.
				v. 1.4 - Added new event.
				v. 1.5 - Fixed bug! :)
				v. 1.6 - Removed runtime error.
				v. 1.7 - Bug free.*/

new bool:gSet[33];
new gStats[8]; 
new gBodyhits[8]; 

public plugin_init() 
{  
	register_plugin("Set Stats", "1.7", "Satan")
	register_logevent("new_round", 2 , "1=Round_Start");  	
}  
//-------------------------------------------------------------------
public client_connect(id) 
{ 
	gSet[id] = false
} 
//-------------------------------------------------------------------
public new_round() 
{ 
	new players[32], num, i; 
	get_players(players,num); 
	
	for(i=0;i<num;i++) 
	set_stats(players[i]); 
}
//-------------------------------------------------------------------
public set_stats(id) 
{ 
	get_user_stats(id, gStats, gBodyhits)
	new kills = get_user_frags(id)
	new timesdied = get_user_deaths(id)
	new frags = gStats[0]
	new deaths = gStats[1]
	
	if(!gSet[id] && frags != kills || deaths != timesdied) 
	{ 
		set_user_frags(id, frags)
		cs_set_user_deaths(id, deaths); 
		gSet[id] = true;
	} 
	return PLUGIN_CONTINUE
}  
