#include <amxmodx>
#include <reapi>

new const PLUGIN[] = "DeathMatch_Restart";
new const VERSION[] = "1.0";
new const AUTHOR[] = "By.KinG";

new Total_Kill;
new Total_Kill_ID[33];

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR);
	register_event("TextMsg","Event_Round_Restart","a","2&#Game_C");
	RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed", 1);
}

public Event_Round_Restart()
{
	Total_Kill = 0;
	
	new Players[32], Num_All, New_ID;
	get_players(Players, Num_All);
	
	for(new i; i < Num_All; i++)
	{
		New_ID = Players[i];
		Total_Kill_ID[New_ID] = 0;
	}
}

public CBasePlayer_Killed(Victim, Killer)
{
	if(is_user_connected(Victim) && is_user_connected(Killer) && Victim != Killer)
	{
		Total_Kill++;
		Total_Kill_ID[Killer]++;
	}
	
	if(Total_Kill_ID[Killer] == 100)
	{
		new Name[33];
		get_user_name(Killer, Name, 32);
		
		if(get_user_flags(Killer) & ADMIN_RESERVATION)
		{
			client_print_color(0, 0, "^3[BILGI] ^4Admin ^1[^3%s^1] ^4Toplamda^3 100 Kill'e ^4Ulasti", Name);
		}
		else
		{
			client_print_color(0, 0, "^3[BILGI] ^4Oyuncu ^1[^3%s^1] ^4Toplamda^3 100 Kill'e ^4Ulasti", Name);
		}
		
		client_print_color(0, 0, "^3[BILGI] ^4Toplamda^3 %d ^4Kill Alindi", Total_Kill);
		client_print_color(0, 0, "^3[BILGI] ^4Takimlar Karistirilip 5 Saniye Icinde Restart Atilacaktir.");

		new te=0,ct=0;
		for(new pPlayer = 1; pPlayer <= MaxClients; pPlayer++) {
			if(is_user_connected(pPlayer) && !is_user_bot(pPlayer)){
		if(ct>te) rg_set_user_team(pPlayer, TEAM_TERRORIST),te++;
		else if(te>ct) rg_set_user_team(pPlayer, TEAM_CT),ct++;
		else {
			switch(random_num(1, 2)) {
				case 1: rg_set_user_team(pPlayer, TEAM_TERRORIST),te++;
				case 2: rg_set_user_team(pPlayer, TEAM_CT),ct++;
					}
				}
			}
		}
		server_cmd("amx_cvar sv_restart 5");
	}
}