// * AdmiralMOD by Matthias Lorenz, http://www.cod2mod.com *


Teamkill(killed_player_uniq_id) {

	self endon("disconnect");

	self notify("Teamkill");
	self endon("Teamkill");


	if(game["am_error_logfile"] == 1) logPrint("Teamkill\n");


	if(game["am_anti_teamkill"] != 1 || game["am_gametype"] == "dm") return;

	if(!isDefined(game["am_teamkiller_count"])) game["am_teamkiller_count"] = 0;	

	
	// * ClanMember sind keine Teamkiller *
	if(isDefined(self.pers["clanmember"])) return;

	

	// *  *
	if(!isDefined(self.pers["teamkills"])) 	self.pers["teamkills"] = 1;
	else if(self.pers["teamkills"] >= 5)	self.pers["teamkills"] = 1;	
	else									self.pers["teamkills"]++;
	
	
	self iprintlnbold(" ");
	self iprintlnbold(game["am_teamkill_" + self.pers["teamkills"] + "_message"]);	
	self thread DoTeamkiller(game["am_if_teamkill_" + self.pers["teamkills"] + "_then_option"]);	
		
}

DoTeamkiller(option) {
	
	if(game["am_error_logfile"] == 1) logPrint("DoTeamkiller\n");


	self endon("disconnect");
	

	wait 2; // * Muß 1 Sekunde warten, sonst wird der Teamkiller noch vor dem getöteten Teammate abgearbeitet ... *

	switch(option) {
	
		case 1:
			self suicide();	
			break;
		case 2:		
			self suicide();	
			wait 1;
			self [[level.spectator]]();			
			break;
		case 3:
			self.health = 5;
			self thread maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",self.health);	
			self shellshock("default", 30);
			self playrumble("damage_heavy");			
			break;
		case 4:
			self.pers["teamkiller"] = true;				
			self maps\mp\gametypes\_admiral_mod_hud::showTeamkillerBlackScreen();			
			self suicide();			
			wait 5;
			
			self setClientCvar("am_ex_befehl", "disconnect");	
			wait 0.5;
			self openMenu("ex_befehl"); 
			
			break;
		case 5:
			self.pers["teamkiller"] = true;			
			self maps\mp\gametypes\_admiral_mod_hud::showTeamkillerBlackScreen();				
			self suicide();	
				
			// * Teamkiller in die Ban Liste aufnehmen *
			self AddTeamkiller();

			wait 5;
			
			self setClientCvar("am_ex_befehl", "disconnect");	
			wait 0.5;
			self openMenu("ex_befehl"); 
			
			break;			
	}
}




AddTeamkiller() {

	if(game["am_anti_teamkill"] != 1) return;
	
	if(game["am_error_logfile"] == 1) logPrint("AddTeamkiller\n");
	
	
	self endon("disconnect");


	if(!isDefined(game["am_teamkiller_count"])) game["am_teamkiller_count"] = 0;


	// * Nur wenn nicht == 0, dann Teamkiller merken *
	if(self getGuid() == 0) return;
	

	game["am_teamkiller_list_guid"][game["am_teamkiller_count"]] = self getGuid();
	game["am_teamkiller_count"]++;

}



CheckPlayerIsTeamkiller(player_guid) {

	if(!isDefined(game["am_teamkiller_count"])) return false;
	
	
	if(game["am_error_logfile"] == 1) logPrint("CheckPlayerIsTeamkiller\n");


	for(i=0;i<game["am_teamkiller_count"];i++) {
	
		if(game["am_teamkiller_list_guid"][i] == player_guid) return true;
	}
	
	return false;
}