

public client_authorized(id)
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	new authid[32];
	get_user_authid(id,authid,31);

	if(equal(authid,"STEAM_ID_PENDING"))
	{
		client_cmd(id,"reconnect");
	}
	
	return PLUGIN_CONTINUE;
}

public  client_putinserver(id) 
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	g_player_class[id]=0;
	g_player_first_spawn[id]=true;
	g_restart_attempt[id]=false;
	
	g_player_character_reseted[id]=false;
	
	reset_player(id);
	reset_player_attributes(id);
	reset_player_skills(id);
	restore_player(id);
	restore_cooldowns(id);
	
	return PLUGIN_CONTINUE;
}

public client_disconnect(id)
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	item_reset(id);
	save_player(id);
	
	return PLUGIN_CONTINUE;
}

public client_damage(attacker,victim,damage,weapon,hitplace,ta)
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	g_player_damage_dealt[attacker][victim]=damage;
	
	if(attacker!=victim)
	{
		skill_passive(attacker,victim,1,damage,weapon,hitplace,ta);
	}
	
	return PLUGIN_CONTINUE;
}

public client_death(killer,victim,weapon,hitplace,tk) 
{
	if(get_pcvar_num(cvar_bleach) != 1) return PLUGIN_CONTINUE;
	
	new xp;
	static bonusxp;
	bonusxp = g_player_level[victim]/g_player_level[killer];
	
	if(bonusxp < 0.6) bonusxp = 1;
	
	if(g_player_died_by_skill[victim])
	{
		g_player_died_by_skill[victim]=false;
	}
	else if((killer == victim) && (weapon != CSW_C4))
	{
		xp=xp_get(get_pcvar_num(cvar_xp_suicide));
		
		client_print(killer,print_chat,"%L",killer,"L_XP_SUICIDE",PLUGIN_TAG,xp);
		xp_set(killer,g_player_experience[killer]-xp);
	}	
	else if(tk)
	{
		xp=xp_get(get_pcvar_num(cvar_xp_teamkill));
		
		client_print(killer,print_chat,"%L",killer,"L_XP_TEAMKILL",PLUGIN_TAG,xp);
		xp_set(killer,g_player_experience[killer]-xp);
	}
	else
	{
		skill_passive(killer,victim,0,g_player_damage_dealt[killer][victim],weapon,hitplace,tk);
		
		if(hitplace == HIT_HEAD)
		{
			xp=xp_get((get_pcvar_num(cvar_xp_kill)+get_pcvar_num(cvar_xp_headshot))*bonusxp);
			
			client_print(killer,print_chat,"%L",killer,"L_XP_HEADSHOT",PLUGIN_TAG,xp);
			xp_set(killer,g_player_experience[killer]+xp);
		}
		else 
		{
			xp=xp_get(get_pcvar_num(cvar_xp_kill)*bonusxp);
			
			client_print(killer,print_chat,"%L",killer,"L_XP_KILL",PLUGIN_TAG,xp);
			xp_set(killer,g_player_experience[killer]+xp);
		}
		
		if(g_player_bomber==victim)
		{
			g_player_bomber=0;
			xp=xp_get(get_pcvar_num(cvar_xp_bomber)*bonusxp);
			
			client_print(killer,print_chat,"%L",killer,"L_XP_BOMBER",PLUGIN_TAG,xp);
			xp_set(killer,g_player_experience[killer]+xp);
		}
		else if(g_player_planter==victim)
		{
			g_player_planter=0;
			xp=xp_get(get_pcvar_num(cvar_xp_planter)*bonusxp);
			
			client_print(killer,print_chat,"%L",killer,"L_XP_PLANTER",PLUGIN_TAG,xp);
			xp_set(killer,g_player_experience[killer]+xp);
		}
		else if(g_player_defuser==victim)
		{
			g_player_defuser=0;
			xp=xp_get(get_pcvar_num(cvar_xp_defuser)*bonusxp);
			
			client_print(killer,print_chat,"%L",killer,"L_XP_DEFUSER",PLUGIN_TAG,xp);
			xp_set(killer,g_player_experience[killer]+xp);
		}
	}
	
	new id,players[MAXPLAYERS];
	static num,req_damage,name_killer[32];
	
	req_damage=floatround(g_player_damage_dealt[killer][victim]*0.45);
	get_user_name(killer,name_killer,31);
	
	get_players(players,num,"ch");
	for (new i; i < num; ++i)
	{
		id=players[i];
		
		if(g_player_damage_dealt[id][victim] == 0)
		{
			continue;
		}
		else
		{
			if((is_user_alive(id)) && (id != killer) && (!tk))
			{
				if(g_player_damage_dealt[id][victim] > req_damage)
				{
					xp=xp_get(get_pcvar_num(cvar_xp_assist)*bonusxp);
					
					client_print(id,print_chat,"%L",id,"L_XP_ASSIST",PLUGIN_TAG,xp,name_killer);
					xp_set(id,g_player_experience[id]+xp);
				}
			}
			
			g_player_damage_dealt[id][victim]=0;
		}
	}
	
	g_player_class_selected[victim]=false;
	
	drop_player_item(victim);
	
	restore_player(victim);
	set_user_rendering(victim);
	remove_status_icon(victim);
	
	return PLUGIN_CONTINUE;
}
