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




// **  CLEAR  **

ClearPlayerVariables() {

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


	// * Wenn Spieler Protected und Headicon Healthcross angezeigt, dann Reset *
	self.headicon 		= "";
	self.oldheadicon 	= "";
	self.headiconteam 	= "none";


	self.pers["cinemascope"] 			= undefined;
	self.pers["camper"] 				= undefined;
	self.pers["healthbar"] 				= undefined;    
	self.pers["am_boat_id"]     		= undefined;
	self.pers["turred_planted"]			= undefined;
	self.pers["mortar_cannon_planted"]	= undefined;
	self.grenade_picked_up 				= undefined;
    self.spawnProtection 				= undefined;
    self.weapon_pickup_thread_started 	= undefined;
    self.offhand_pickup_thread_started 	= undefined;
    self.artillery_active				= undefined;
    self.spy_is_looking_at_you  		= undefined;
    self.do_status 						= "none";
	self.is_bleeding					= undefined;	
	self.show_heart_icon 				= undefined;
	self.weapon_pickup_warning			= undefined;
	self.ammo_reloaded_crate			= undefined;
	self.ammo_reloaded_count			= undefined;
	
	self.player_info_text_is_showing 	= undefined;
	
	self.DeathSequence					= undefined;
	self.brennt 						= undefined;
	
	

    if(!isDefined(self.pers["rank"])) self.pers["rank"] = 1;
}

ClearHud() {

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

	// * Hudelemente *
	self maps\mp\gametypes\_admiral_mod_hud::deletePlayerHudElementsAll();	
	
	// * SetClient-Hudelemente *
	self deleteSetClientHudElements();	



	if(isDefined(self.squadleader_indicator)) self.squadleader_indicator destroy();


	self.pers["cinemascope"] = undefined;
	self PlayerActivateCinemascope();
	
	
	// * Bei S&D geht ein toter Spieler in den Spectator-Modus, ohne die Funkion dazu zu benutzen *
	if(game["am_gametype"] != "sd" && game["am_gametype"] != "sdr" && game["am_gametype"] != "csd") {
	
		self.pers["healthbar"] 	= undefined;    
		self PlayerActivateHealthbar();
	}


	if(game["am_gametype"] == "mm") {
	
		if(isdefined(self.progressbackground))
			self.progressbackground destroy();

		if(isdefined(self.progressbar))
			self.progressbar destroy();
	}
}


deleteSetClientHudElements() {

	self endon("disconnect");

	/*

	self.pers["am_ui_show_healthbar"] 					= game["am_hud_style"];
	self.pers["am_ui_show_healthbar_back"] 				= game["am_hud_style"];
	self.pers["am_ui_show_healthbar"] 					= 0;
	self.pers["am_ui_show_healthbar_back"] 				= 0;	
	self.pers["am_ui_show_vote_headline"] 				= 1;
	self.pers["am_ui_show_vote_map_button"] 			= 1;
	self.pers["am_ui_show_vote_gametype_button"] 		= 1;
	self.pers["am_ui_show_vote_board_maps"] 			= 1;
	self.pers["am_ui_show_vote_board_gametypes"] 		= 1;	
	self.pers["am_ui_show_player_rank"] 				= self.pers["rank"];
	self.pers["am_ui_show_pickup_weapon"] 				= 0;
	self.pers["am_ui_weapon_pickup_info_text"] 			= text;
	
	self.pers["am_ui_use_info_text"] 					= " ";
	self.pers["am_ui_show_special_weapon_text"] 		= " ";
	self.pers["am_ui_player_info_text"] 				= " ";
	self.pers["am_ui_player_class_info_text"] 			= " ";
	
	self.pers["am_ui_allow_player_class_0"] 			= 2;
	self.pers["am_ui_allow_player_class_1"] 			= 2;
	self.pers["am_ui_allow_player_class_2"] 			= 2;
	self.pers["am_ui_allow_player_class_3"] 			= 2;
	self.pers["am_ui_allow_player_class_4"] 			= 2;
	self.pers["am_ui_allow_player_class_5"] 			= 2;
	self.pers["am_ui_allow_player_class_6"] 			= 2;
	self.pers["am_ui_allow_player_class_7"] 			= 2;
		
	self.pers["am_ui_show_tnt_weapon_ammo"] 			= 0;
	self.pers["am_ui_show_artillery_weapon_ammo"] 		= 0;
	self.pers["am_ui_show_medic_weapon_ammo"] 			= 1;
	self.pers["am_ui_show_artillery_weapon_ammo_rot"]	= 0;    
	self.pers["am_ui_show_artillery_shell"] 			= 0;	
		
	self.pers["am_ui_medic_weapon_ammo"] 				= self.medic_ammo_count;
	self.pers["am_ui_tnt_weapon_ammo"] 					= self.tnt_ammo_count;

	self.pers["am_ui_bomb_status"] 						= bomb.menu_status_text;
	
	self.pers["am_ui_show_special_weapon"] 				= "10";
	
	*/



	self setClientCvar("am_ui_use_info_text", " ");
	self setClientCvar("am_ui_player_class_info_text", " ");
	self setClientCvar("am_ui_player_info_text", " ");
	self setClientCvar("am_ui_weapon_pickup_info_text", " ");
	self setClientCvar("am_ui_show_special_weapon_text", " ");
	
	
	self setClientCvar("am_ui_show_medic_weapon_ammo", "0");
	self setClientCvar("am_ui_show_tnt_weapon_ammo", "0");
	self setClientCvar("am_ui_show_artillery_weapon_ammo", "0");
	self setClientCvar("am_ui_show_artillery_weapon_ammo_rot", "0");    
	self setClientCvar("am_ui_show_artillery_shell", "0");	
	
	self setClientCvar("am_ui_show_player_rank", "0");
	

	if(self.pers["am_ui_show_bomb_menu"] == 1) {
			
		self setClientCvar("am_ui_show_bomb_menu", "0");
		self.pers["am_ui_show_bomb_menu"] = 0;

		self setClientCvar("am_ui_show_bomb_function_selection", "0");
		self.pers["am_ui_show_bomb_function_selection"] = 0;
		
		self setClientCvar("am_ui_show_bomb_time_selection", "0");
		self.pers["am_ui_show_bomb_time_selection"] = 0;
		
		self setClientCvar("am_ui_show_bomb_range_selection", "0");
		self.pers["am_ui_show_bomb_range_selection"] = 0;
		
		self setClientCvar("am_ui_show_bomb_defuse_selection", "0");
		self.pers["am_ui_show_bomb_defuse_selection"] = 0;
		
		self setClientCvar("am_ui_show_bomb_defuse_others_selection", "0");	
		self.pers["am_ui_show_bomb_defuse_others_selection"] = 0;
	}
	
	if(isDefined(self.pers["last_pickup_weapon_shown"])) {
	
		self setClientCvar("am_ui_show_pickup_weapon", "0");
		self.pers["am_ui_show_pickup_weapon"] = 0;
	}
	
}




ClearCompass() {

	self endon("disconnect");

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

	self maps\mp\gametypes\_admiral_mod_compass::DeleteCamping();
}


ClearPlayerObjects() {
	
	self endon("disconnect");


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


	if(isDefined(self.spy_radio_sound)) 	self.spy_radio_sound delete();
	if(isDefined(self.helper)) 				self.helper delete();
	if(isDefined(self.fallschirm)) 			self.fallschirm stopLoopSound();
	
	if(isDefined(self.fahrstuhl))  			self.fahrstuhl delete();
	if(isDefined(self.fallschirm)) 			self.fallschirm delete();
	
	if(isDefined(self.bodyfallsound)) 		self.bodyfallsound delete();

	if(isDefined(self.knife))				self.knife delete();
	
	
	// * Damit bei Reflective, nicht sofort das Turret gelöscht wird => sonst COD2 Absturz *
	self thread DeleteTurret();
	
	self thread DeleteMortarCannon();
	
}



DeleteTurret() {


	self endon("disconnect");

	wait 1;	


	// * Player Turrets *
	self notify("TurretEnd");													
	if(isDefined(self.turret_indicator)) self.turret_indicator destroy();

	turrets = getentarray("misc_turret", "classname");
	for(i = 0; i < turrets.size ; i++) {
	
		if(isDefined(turrets[i].turredid) && isDefined(self.clientid) && turrets[i].turredid == self.clientid) turrets[i] delete();	
	}
	self.pers["turred_planted"] = undefined;

}


DeleteMortarCannon() {


	self endon("disconnect");

	wait 1;	


	// * Player Turrets *
	self notify("MortarCannonEnd");	
	if(isDefined(self.mortar_cannon_indicator)) self.mortar_cannon_indicator destroy();
	
	if(isDefined(self.mortar_cannon)) self.mortar_cannon delete();	
	
	self.pers["mortar_cannon_planted"] = undefined;

}




// **  SET  **

SetCompass() {

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

	self thread CheckCamping();	
}

SetHudPlayer() {

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

	self PlayerActivateCinemascope();	
	self PlayerActivateHealthbar();

	if(level.mapended == true) return;

	self thread maps\mp\gametypes\_admiral_mod_hud::ShowPlayerStance();
	self thread maps\mp\gametypes\_admiral_mod_hud::ShowPlayerRank();
	self thread maps\mp\gametypes\_admiral_mod_hud::activateSpawnHealth();	
	self thread maps\mp\gametypes\_admiral_mod_hud::showEmptyImage();
	self thread maps\mp\gametypes\_admiral_mod_hud::showWelcome();		
}

SetHudSpectator() {

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

	self PlayerActivateCinemascope();		
}

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


	if(level.mapended == true) return;
	
	self thread maps\mp\gametypes\_admiral_mod_sounds::StartBattleChatter();
	self thread CheckPlayerInactive();
	self thread CheckPlayerCrosshair();
	self thread CheckCompassDots();
}

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

}




// **  PLAYER  **

PlayerConnect(random_maplist) {

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

	
	self.do_status = "none";

	if(game["am_skip_info_screen"] == 1) self.pers["skipserverinfo"] = true;

	
	if(getTime() < 3000) wait 1; // * bei lokalem Test für den Playerstarter notwendig *
	
	self PlayerCVarsInit(random_maplist);
	
	// * Ban Check *	
	if(maps\mp\gametypes\_admiral_mod_teamkill::CheckPlayerIsTeamkiller(self getGuid()) ) {
	
		self setClientCvar("am_ex_befehl", "disconnect");	
		wait 0.5;
		self openMenu("ex_befehl"); 
		
		return;
	}	
}


PlayerCVarsInit(random_maplist) {

	self endon("disconnect");


	if(game["am_show_hit_location_graphic"] == 1) 	self maps\mp\gametypes\_admiral_mod_hud::ShowHitFigur("clean");
	else											self maps\mp\gametypes\_admiral_mod_hud::ShowHitFigur("");
	
	
	if(game["am_gametype"] == "csd") 		self setClientCvar("am_ui_game_type", "csd");
	else if(game["am_gametype"] == "noz") 	self setClientCvar("am_ui_game_type", "noz");
	else 									self setClientCvar("am_ui_game_type", "");


	// * Im Waffen-Menu der Axis, die Thompson als Balance Waffe auswählbar machen *
	if(game["am_enable_weapon_thompson_for_axis"] == 1) 	self setClientCvar("ui_allow_thompson_german", "1");
	else {
	
		if(getcvar("ui_allow_thompson_german") == "1")  self setClientCvar("ui_allow_thompson_german", "0");
	}
	
	
	// * Im Waffen-Menu der Americans, die Enfieled als Balance Waffe auswählbar machen *
	if(game["am_enable_weapon_enfield_for_american"] == 1) 	self setClientCvar("ui_allow_enfield_american", "1");
	else {
	
		if(getcvar("ui_allow_enfield_american") == "1") self setClientCvar("ui_allow_enfield_american", "0");
	}



	// * Nur beim 1. Connect alles initialisieren (SD würde doppelte erzeugen) *
	if(isDefined(self.pers["connect_init"])) return;
	self.pers["connect_init"] = true;
	
	
	self setClientCvar("mapname", game["am_mapname"]);	


	if(game["am_show_friends_and_enemys_on_compass"] == 1) 	self setClientCvar("am_ui_show_friends_and_enemys_on_compass", "1");
	else 													self setClientCvar("am_ui_show_friends_and_enemys_on_compass", "0");
	

	if(game["am_forced_autoassign"] == 1) 	self setClientCvar("ui_forced_autoassign", "1");
	else {
	
		if(game["am_gametype"] == "csd") 		self setClientCvar("ui_forced_autoassign", "csd");
		else if(game["am_gametype"] == "noz") 	self setClientCvar("ui_forced_autoassign", "noz");
		else 									self setClientCvar("ui_forced_autoassign", "other");
	}
	


	if(game["am_use_player_class_system"] == 1) {
		
		self setClientCvar("ui_allow_changeteam", "1");
		self setClientCvar("ui_allow_changeplayerclass", "1");		
	}
	else {	
		
		if(getcvar("ui_allow_changeteam") == "1") 			self setClientCvar("ui_allow_changeteam", "0");
		if(getcvar("ui_allow_changeplayerclass") == "1") 	self setClientCvar("ui_allow_changeplayerclass", "0");			
	}
	


	self setClientCvar("rank_v", getcvar("_Mod") + "  " + getcvar("_ModVer"));
	

	self thread PlayerVoteCvarsInit(random_maplist);



	// * AdmiralMod *
	if(game["am_use_player_class_system"] == 1) {
	
		self setClientCvar("am_ui_allow_player_class_0", "1");
		self setClientCvar("am_ui_allow_player_class_1", "1");
		self setClientCvar("am_ui_allow_player_class_2", "1");
		self setClientCvar("am_ui_allow_player_class_3", "1");
		self setClientCvar("am_ui_allow_player_class_4", "1");
		self setClientCvar("am_ui_allow_player_class_5", "1");
		self setClientCvar("am_ui_allow_player_class_6", "1");
		self setClientCvar("am_ui_allow_player_class_7", "1");

		
		self setClientCvar("am_gas_grenade_has_allies_class", game["am_gas_grenade_has_allies_class"]);
		if(game["am_fire_grenade_has_allies_class"] != game["am_gas_grenade_has_allies_class"]) 		self setClientCvar("am_fire_grenade_has_allies_class", game["am_fire_grenade_has_allies_class"]);
		else 																							self setClientCvar("am_fire_grenade_has_allies_class", "-1");
		
		self setClientCvar("am_gas_grenade_has_axis_class", game["am_gas_grenade_has_axis_class"]);
		if(game["am_fire_grenade_has_axis_class"] != game["am_gas_grenade_has_axis_class"]) 			self setClientCvar("am_fire_grenade_has_axis_class", game["am_fire_grenade_has_axis_class"]);
		else 																							self setClientCvar("am_fire_grenade_has_axis_class", "-1");	


	}
	else {
	
		self setClientCvar("am_gas_grenade_has_allies_class", "-1");
		self setClientCvar("am_gas_grenade_has_axis_class", "-1");
		self setClientCvar("am_fire_grenade_has_allies_class", "-1");
		self setClientCvar("am_fire_grenade_has_axis_class", "-1");		
	}


	self setClientCvar("am_ui_mm_mission_text", " ");	

	// * COD3 Style *
	if(game["am_hud_style"] == 2) 	self setClientCvar("am_ui_show_cod3_hud", "1");	
	else							self setClientCvar("am_ui_show_cod3_hud", "");	
	
	self.pers["am_stance"] = 2;
	
	self.pers["am_ui_show_bomb_menu"] = 0;
	
	
	
	if(game["am_third_person_spectate"] == 1) 	self setclientcvar("cg_thirdperson", 1);	
	else 										self setclientcvar("cg_thirdperson", 0);

}

ForAllPlayersRandomMaps(){
	// * Maps und Gametypes für Voting *

	maplist 		= game["am_vote_maps_orig"];
	gametypelist 	= game["am_vote_gametypes"];
	mapanzahl = 8;
	
	indexlist = [];
	maplist_result = [];
	
	for(i=0;i<mapanzahl;i++){
		used = false;
		index = RandomInt(maplist.size - 1);
		for(j=0;j<mapanzahl;j++){
			if(isDefined(indexlist[j])  && indexlist[j]== index){
				used = true;
				break;
			}
		}
		if(used){
			i--;
			continue;
		}
		indexlist[i] = index;
	}
		
	if(game["am_vote_map"] == 1) {

		for(i=0;i<mapanzahl;i++) {	
			index = indexlist[i];
			
			if(isDefined(maplist[index])) {

				//map = maps\mp\gametypes\_admiral_mod_utils::firstToUpper(maplist[index]);
				maplist_result[i] = maplist[index];

				//self setClientCvar("am_ui_vote_map_" + i, map);					
			}
			//else {
			//	self setClientCvar("am_ui_vote_map_" + i, " ");					
			//}
		}	
	}
	
	return maplist_result;
}

PlayerVoteCvarsInit(random_maplist) {

	self endon("disconnect");


	wait 1 + RandomInt(10); // * Damit kein Server Command Overflow *


	// * Bei Maprestart (Gametype SD, ...)  nicht erneut die CVars laden *
	if(isDefined(self.pers["VoteCvarsInit"])) return;
	
	self.pers["VoteCvarsInit"] = true;

   
	// * Vote: muß hier stehen, damit eine evtl. alte gesetzte 1 gelöscht wird *
	self setClientCvar("am_ui_show_vote_headline", "0");
	self setClientCvar("am_ui_show_vote_map_button", "0");
	self setClientCvar("am_ui_show_vote_gametype_button", "0");
	self setClientCvar("am_ui_show_vote_board_maps", "0");
	self setClientCvar("am_ui_show_vote_board_gametypes", "0");
	self setClientCvar("am_ui_show_vote_only_for_clanmembers", "0");



	// * Maps und Gametypes für Voting *
	
	gametypelist 	= game["am_vote_gametypes"];

/*
	maplist 		= game["am_vote_maps_orig"];
	mapanzahl = 8;
	
	indexlist = [];
	maplist_result = [];
	
	for(i=0;i<mapanzahl;i++){
		used = false;
		index = RandomInt(maplist.size - 1);
		for(j=0;j<mapanzahl;j++){
			if(isDefined(indexlist[j])  && indexlist[j]== index){
				used = true;
				break;
			}
		}
		if(used){
			i--;
			continue;
		}
		indexlist[i] = index;
	}
*/	
		
	if(game["am_vote_map"] == 1) {

		for(i=0;i<random_maplist.size;i++) {	
			//index = indexlist[i];
			
			if(isDefined(random_maplist[i])) {

				map = maps\mp\gametypes\_admiral_mod_utils::firstToUpper(random_maplist[i]);
				self setClientCvar("am_ui_vote_map_" + i, map);					
			}
			else {
				self setClientCvar("am_ui_vote_map_" + i, " ");					
			}
		}	
	}
	game["am_vote_maps"] = random_maplist;

	if(game["am_vote_gametype"] == 1) {

		for(i=0;i<10;i++) {	

			if(isDefined(gametypelist[i])) {

				gametype = maps\mp\gametypes\_admiral_mod_utils::getGametypeName(gametypelist[i]);

				self setClientCvar("am_ui_vote_gametype_" + i, gametype);				
			}
			else {
			
				self setClientCvar("am_ui_vote_gametype_" + i, " ");					
			}
		}	
	}	

}


PlayerDisconnect() {

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

	self ClearCompass();


	// * Mögliches verbliebenes Turret verschwinden lassen *
	turrets = getentarray("misc_turret", "classname");
	for(i = 0; i < turrets.size ; i++) {
	
		if(isDefined(turrets[i].turredid) && isDefined(self.clientid) && turrets[i].turredid == self.clientid) turrets[i] delete();	
	}
	

	// * Squad * 
	self maps\mp\gametypes\_admiral_mod_squad::SquadMemberDisconnect();
}



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

	self endon("disconnect");
	

	if(isDefined(self.pers["old_team"])) self maps\mp\gametypes\_admiral_mod_squad::RemovePlayerFromSquad(self.pers["old_team"]);
	
}

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

	self endon("disconnect");
	
	
	self ClearPlayerVariables();
	self ClearCompass();
	//self ClearHud();
	self ClearPlayerObjects();
	self SetHudSpectator();
	


	// * Squad * 
	self maps\mp\gametypes\_admiral_mod_squad::SquadMemberSpectator();
	
	
	//self maps\mp\gametypes\_admiral_mod_weapons::MakeWeaponLimit();	


	// * Für neue Boote zum Beispiel *
	if(game["am_show_player_position"] == 1) {
	
		self thread ShowPlayerPosition();			
	}
	

	if(game["am_third_person_spectate"] == 1) 	self setclientcvar("cg_thirdperson", 1);		
}



SpawnPlayerPre() {

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

	self endon("disconnect");


	self CheckClanMember();
	self CheckDoublePlayerName();
	self CheckUnknownSoldier();
	self CheckPlayerNameFunctions();

		
	self setClientCvar("cg_hudCompassSize", "0.8");		

	
	// * Teamkiller nicht wieder ins Spiel lassen * 
	if(isDefined(self.pers["teamkiller"])) return;
	

	if(level.mapended == true) return;

	self maps\mp\gametypes\_admiral_mod_squad::AddPlayerToSquad();


	// * Alte Helme wieder herstellen *
	self maps\mp\gametypes\_teams::model(); 
		

	if(game["am_weapon_arsenal"] == 1) {
	
		self.pers["weapon1"] 		= undefined;
		self.pers["weapon2"] 		= undefined;
		self.pers["spawnweapon"] 	= undefined;
	}



}

SpawnPlayerPost() {

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

	self endon("disconnect");



	self.pers["next_spawn_weapon"] 	= undefined;		


	// * Teamkiller nicht wieder ins Spiel lassen * 
	if(isDefined(self.pers["teamkiller"])) return;
	
	
	// * Multiplayer-Namen bereinigen *
	if(game["am_gametype"] == "mm") {
	
		self thread maps\mp\gametypes\_admiral_mod_xmission_engine::DeleteMissionAddon();	
	}
	

	self ClearPlayerVariables();
	
	// * Bei S&D auch beim Spawn das komplette HUD löschen, da bei einer neuen Runde kein automtischer PlayerKill *
	// * und das HUD wird nur bei einem PlayerKill komplett gelöscht *
	if(game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") self ClearHud();
	
	
	self ClearCompass();
	
	self SetHudPlayer();
	self SetCompass();
	self SetPlayerMonitor();
	
	
	// * Hit Location Graphic *
	if(game["am_show_hit_location_graphic"] == 1) self maps\mp\gametypes\_admiral_mod_hud::ShowHitFigur("clean");

	

	if(level.mapended == true) return;

		
	self thread CheckPlayerStance();
	self thread CheckPlayerJump();
	
	
	if(game["am_parachute"] == 1) self thread PlayerToEarth(self.origin);	
	
	
		
	// * Landung mit dem Boot (Nur wenn nicht Parachute aktiviert) *
	if(game["am_parachute"] == 0 && game["am_boats"] == 1 && !isDefined(self.pers["boat_landing"]) && self.do_status == "none") {
	
		self.pers["boat_landing"] = true;
		
		player_on_boat = false;
		player_on_boat = maps\mp\gametypes\_admiral_mod_vehicles::BoatAddPlayer(self);

		
		// * Landung mit dem Boot nicht möglich, dann mit dem Flugzeug abspringen? *
		if(isDefined(player_on_boat) && player_on_boat == false) {
			
			//self iprintlnbold(&"AM_MP_SORRY_YOU_MUST_WALK");
			//self iprintlnbold(&"AM_MP_MESSAGE_BOLD_EMPTY");
		}	
	}
		
	// * SUQAD Leader Indicator *
	self thread maps\mp\gametypes\_admiral_mod_squad::IndicateLeader();
	
	// * SUQAD Leader Entfernung *
	self thread maps\mp\gametypes\_admiral_mod_squad::CheckSquadLeaderDistance();

	// * Laser Dot *
	self thread maps\mp\gametypes\_admiral_mod_hud::showLaserDot();	

	// * Waffen Limits Check und Limitation *
	//self maps\mp\gametypes\_admiral_mod_weapons::MakeWeaponLimit();	


	// * Pistole merken, wenn diese durch die 2nd Weapongelöscht wird *
	primaryb = self getweaponslotweapon("primaryb");


	// * Waffen wieder herstellen *
	if(game["am_weapon_arsenal"] == 1 && isDefined(self.pers["weapon1"]) && isDefined(self.pers["s_weapon2"]) && isDefined(self.pers["spawnweapon"])) {
	
		self setWeaponSlotWeapon("primary", self.pers["s_weapon1"]);
		self setWeaponSlotClipAmmo("primary", 999);
		self setWeaponSlotAmmo("primary", 999);		
		
		self setWeaponSlotWeapon("primaryb", self.pers["s_weapon2"]);
		self setWeaponSlotClipAmmo("primaryb", 999);
		self setWeaponSlotAmmo("primaryb", 999);	
		
		self setSpawnWeapon(self.pers["spawnweapon"]);
	}
	
	
	// * Player-Class *
	self maps\mp\gametypes\_admiral_mod_player_class::ChangeClassBySpawning();
	
	

	// * Secondary Weapon, dann zuerst Auswahl und dann Weapon Arsenal! *
	self maps\mp\gametypes\_admiral_mod_weapons::GetSecondaryWeapon();

	// * Weapon Arsenal Init Rotation *
	self maps\mp\gametypes\_admiral_mod_weapons::weapon_init();
	self thread maps\mp\gametypes\_admiral_mod_weapons::checkWeaponSlots();

	// * Pistole: Check ob die Pistole vorhanden oder durch die 2nd überschrieben, dann Pistole wiederherstellen *
	if(game["am_weapon_arsenal"] == 1 && game["am_give_pistol"] == 1 && primaryb != self getweaponslotweapon("primaryb")) {
		
		self setWeaponSlotWeapon("primaryb", primaryb);
		self setWeaponSlotClipAmmo("primaryb", 999);
		self setWeaponSlotAmmo("primaryb", 999);			
	}


	if(game["am_player_artillerie"] == 1) {
	
		if(game["am_enable_player_rank"] == 1) {
		
			// * Wenn Rank erreicht und kein Klassen-System *
			if(self.pers["rank"] >= game["am_give_artillery_by_rank_nr"] && game["am_use_player_class_system"] == 0) {
		
				self thread maps\mp\gametypes\_admiral_mod_weapons_class::CheckArtillery();	
			}	
		}
		else {
	
			// * Wenn Punkte erreicht und kein Klassen-System *
			if(self.score >= game["am_player_artillerie_needed_score"] && game["am_use_player_class_system"] == 0) {
		
				self thread maps\mp\gametypes\_admiral_mod_weapons_class::CheckArtillery();
			}	
		}
	}


	// * Grenade Throw BattleChatter *
	self thread maps\mp\gametypes\_admiral_mod_sounds::TalkGrenadeThrow();


	// * Breath Winter Maps *	
	self thread maps\mp\gametypes\_admiral_mod_ambient::WinterBreath();


	// * Player-Class *	
	if(self.pers["player_class"] == 4) self thread maps\mp\gametypes\_admiral_mod_player_class::setClassMedic();
	if(self.pers["player_class"] == 5) self thread maps\mp\gametypes\_admiral_mod_player_class::setClassTNT();
	if(self.pers["player_class"] == 6) self thread maps\mp\gametypes\_admiral_mod_player_class::setClassArtillery();
	if(self.pers["player_class"] == 7) self thread maps\mp\gametypes\_admiral_mod_player_class::setClassSpy();
	
	// * StatusIcon *
	self thread maps\mp\gametypes\_admiral_mod_player_class::SetClassStatusIcon();
	
	
	// * Sprinten und Klettern erst hier zum Schluß, da ansonsten die Waffen bei schon *
	// * aktiviertem sprinten nicht in die Slots geladen werden (bei Weapon Arsenal ON) *
	self thread PlayerSprinting();
	self thread PlayerClimbing();


	// * Check ob Spieler eine MG trägt, wenn ja dann Anzeige aktivieren *
	self thread maps\mp\gametypes\_admiral_mod_weapons_class::CheckMGCarring();

	// * Check ob Spieler eine MG trägt, wenn ja dann Anzeige aktivieren *
	self thread maps\mp\gametypes\_admiral_mod_weapons_class::CheckMCCarring();


	if(game["am_gametype"] == "mm" && game["am_mission_pack_edit"] == 1) {
	
		self thread ShowPlayerDatas();	
		self thread EnableModelPlanter();	
	}


	// * Für neue Boote zum Beispiel *
	if(game["am_show_player_position"] == 1) {
	
		self thread ShowPlayerPosition();			
	}


	self thread maps\mp\gametypes\_weapons::reduceAmmoByRank("primary");
	self thread maps\mp\gametypes\_weapons::reduceAmmoByRank("primaryb");
	
		
	if(isDefined(self.pers["smoke_grenade_text"])) 	{
	
		self setClientCvar("am_ui_show_special_weapon_text", self.pers["smoke_grenade_text"]);
		self.pers["am_ui_show_special_weapon_text"] = self.pers["smoke_grenade_text"];
	}


	if(game["am_third_person_spectate"] == 1) 	self setclientcvar("cg_thirdperson", 0);	

}



SpawnIntermission() {

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

	self endon("disconnect");

}



// **  Functions  **

PlayerActivateCinemascope() {

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


	if(isDefined(self.pers["cinemascope"])) return;
		
	// * CinemascopeBildschirm *
	self maps\mp\gametypes\_admiral_mod_hud::activateCinemascope();
}


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


	if(isDefined(self.pers["healthbar"])) return;
	
	// * Healthbar *
	self maps\mp\gametypes\_admiral_mod_hud::showHealthBar("healthbar",501,455);
}



PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime) {
		
	
	if(game["am_error_logfile"] == 1) logPrint("PlayerDamage\n");

	self endon("disconnect");

	/*
	iprintln(iDamage);
	iprintln(sMeansOfDeath);
	iprintln(sWeapon);
	iprintln(vPoint);	
	*/
	
	if(isDefined(sWeapon) && (sWeapon == "gas_grenade_mp" || sWeapon == "fire_grenade_mp")) {
	
		if(isDefined(eAttacker) && isPlayer(eAttacker) && isDefined(eAttacker.clientid) && isDefined(eAttacker.pers["team"])) {
	
			level thread maps\mp\gametypes\_admiral_mod_weapons_class::CreateWeaponSpecialFX(eAttacker.clientid, eAttacker.pers["team"], iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir);
			return;
		}
	}

//** Hinzugefügt für HELLZone_AM **//

	// Bloodyscreen für Schütze
	
	if( isPlayer(eAttacker) && (sMeansOfDeath == "MOD_MELEE" || distance(eAttacker.origin , self.origin ) < 150) ){
		
		eAttacker thread maps\mp\gametypes\_myaddon::Bloodyscreen();

		self.bloodyscreen = 1;
	}
	
	// Bulletholes für Angeschossenen
	if( sMeansOfDeath == "MOD_PISTOL_BULLET" || sMeansOfDeath == "MOD_RIFLE_BULLET" )
		self thread maps\mp\gametypes\_myaddon::Bulletholes();

//** ---Ende für HELLZone_AM--- **//

	// * Explosionsverstärker *
	if(isDefined(sWeapon) && sWeapon != "gas_grenade_mp" && sWeapon != "fire_grenade_mp") CheckQuake(vPoint,sWeapon);
	

	// ** Wenn nicht DM und Friendly und selbes Team, dann kein Damage **
	if(game["am_gametype"] != "dm" && isPlayer(eAttacker) && (self != eAttacker) && (self.pers["team"] == eAttacker.pers["team"]) && level.friendlyfire == "0") return;



	if(game["am_arm_hit_drop_weapon"] == 1 && (sHitLoc == "left_arm_upper" || sHitLoc == "right_arm_upper" || sHitLoc == "left_arm_lower" || sHitLoc == "right_arm_lower" || sHitLoc == "left_hand" || sHitLoc == "right_hand")) {
						
		if(self getcurrentweapon() != "none") {
		
			self iprintlnbold(&"AM_MP_ARM_HIT", maps\mp\gametypes\_weapons::getWeaponName(self getcurrentweapon()) );
			self maps\mp\gametypes\_weapons::dropWeapon();	
		}
				
		//self.health = (self.health + iDamage) - (self.health - 12);
	}



	
	// * Wenn am Bein getroffen dann geht Spieler zu Boden *
	if(game["am_down_by_leg_shot"] == 1 && isDefined(self.pers["am_stance"]) && self.pers["am_stance"] > 0) {
		
		if(sHitLoc == "left_leg_upper" || sHitLoc == "right_leg_upper" || sHitLoc == "left_leg_lower" || sHitLoc == "right_leg_lower" || sHitLoc == "left_foot" || sHitLoc == "right_foot") {

			self openMenu("step_down"); 
			wait 0.05;
			self closeMenu(); 
		}
	}
	


	
	newHealth = self.health-iDamage;	
	if(newHealth < 1) newHealth = 1;
	
	
	self maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",newHealth);
	


	// * Wenn Gesundheitszustand kritisch, dann kein Sprinten möglich *
	if(newHealth < game["am_deny_sprinting_health"]) {
	
		self.pers["deny_sprinting_health"] = true;			
	}


	// * Player Verletzung Heart-Icon anzeigen, wenn Health < 50 %  (nicht anzeigen  bei HealthRegen ON !) *
	if(game["am_use_player_class_system"] == 1 && game["am_health_regen"] != 1 && !isDefined(self.show_heart_icon) && newHealth < game["am_class_show_medic_damage_heart_if_health_less_than"]) {
	
		self.show_heart_icon = true;
		thread maps\mp\gametypes\_hearticons::addHearticon(self, self.clientid, self.pers["team"]);
		
		// * Medic rufen *
		self thread CallMedic();					
	}



	// * BattleChatter Damage-Kommentar for Enemy *
	if(isPlayer(eAttacker) && eAttacker != self && isDefined(eAttacker.pers["team"]) && isDefined(self.pers["team"]) && eAttacker.pers["team"] != self.pers["team"] ) {

		eAttacker.pers["bc_lastAttackToPlayer_id"] 		= self.clientid;
		eAttacker.pers["bc_lastAttackToPlayer_time"] 	= getTime();


		if(self.pers["team"] == "axis") {
			
			self thread maps\mp\gametypes\_admiral_mod_sounds::TalkDamagedEnemy("GE",eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
		}
		else {
		
			kurz = "US";
		
			switch(game["allies"]) {

				case "american":
					kurz = "US";			
					break;
				case "british":
					kurz = "UK";			
					break;		
				case "russian":
					kurz = "RU";			
					break;
			}

			self thread maps\mp\gametypes\_admiral_mod_sounds::TalkDamagedEnemy(kurz,eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
		}
	}

	// * BattleChatter Damage-Kommentar for Enemy *
	if(isPlayer(eAttacker) && eAttacker != self && isDefined(eAttacker.pers["team"]) && isDefined(self.pers["team"]) && eAttacker.pers["team"] == self.pers["team"] ) {


		if(self.pers["team"] == "axis") {
			
			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkDamagedFriend("GE");
		}
		else {
		
			kurz = "US";
		
			switch(game["allies"]) {

				case "american":
					kurz = "US";			
					break;
				case "british":
					kurz = "UK";			
					break;		
				case "russian":
					kurz = "RU";			
					break;
			}

			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkDamagedFriend(kurz);
		}
	}

	
	client_id = -1;
	client_team = "none";
	if(isPlayer(eAttacker) && (self != eAttacker) && isDefined(eAttacker.clientid)) 	client_id = eAttacker.clientid;
	if(isPlayer(eAttacker) && (self != eAttacker) && isDefined(eAttacker.pers["team"])) client_team = eAttacker.pers["team"];

	self thread StartBleeding(client_id, client_team, iDFlags, sMeansOfDeath, sWeapon);
	

	
	//self thread LostHelmet(vDir,iDamage);


}


CheckQuake(vPoint,sWeapon) {

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



	if(!isDefined(vPoint) || !isDefined(sWeapon)) return;
	

	if(isDefined(level.last_quake_position) && level.last_quake_position == vPoint) return;
	
	level.last_quake_position = vPoint;



	if(isDefined(sWeapon)) {
	
		radius 		= 1;
		strength 	= 0.2;
	
		switch(sWeapon) {

			case "panzerschreck_mp":
				radius 		= 1500;	
				strength 	= 0.7;
				break;
			case "frag_grenade_american_mp":
				radius 		= 1000;				
				strength 	= 0.4;
				break;		
			case "frag_grenade_british_mp":
				radius 		= 1000;				
				strength 	= 0.4;
				break;
			case "frag_grenade_german_mp":
				radius 		= 1000;				
				strength 	= 0.4;
				break;
			case "frag_grenade_russian_mp":
				radius 		= 1000;				
				strength 	= 0.4;
				break;		
		}
		
				

		DoQuake(vPoint, radius, strength);
	}

}





PlayerSpawnProtection() {

	self endon("killed_player");
	self endon("disconnect");

	
	// * Wenn schon angezeigt wird, dann nicht nochmal *
	if(isDefined(self.headicon) && self.headicon == "protection_health_cross") return;
	
		
	self maps\mp\gametypes\_admiral_mod_headicon::saveHeadIcon(); 
	self.headicon = "protection_health_cross";
	self.headiconteam = "none";
	
	
	wait 2;
        
	
    self maps\mp\gametypes\_admiral_mod_headicon::restoreHeadIcon();      
    
	if(self.pers["team"] == "allies")		self.headiconteam = "allies";
	else if(self.pers["team"] == "axis")	self.headiconteam = "axis";
    
}




CallMedic() {

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


	self endon("killed_player");
	self endon("disconnect");


	// * Nicht jedes Mal talken *
	if(RandomInt(100) < game["am_battlechatter_comments_probability"]) return;


	
	// * ein paar Sekunden warten ob der Player den Angriff überhaupt überlebt *
 	wait 3;

	self thread maps\mp\gametypes\_admiral_mod_sounds::DoTalking("am_" + self GetTeamKurz() + "_sanitaeter_hilfe");								
	self sayAll(&"AM_MP_MEDIC");
}



PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration) {

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


	self endon("killed_player");
	self endon("disconnect");

	state = "none";
	eAttacker.headshot = 0;
	
//** Hinzugefügt für HELLZone_AM **//

	self thread maps\mp\gametypes\_myaddon::BulletholesDestroy();
	self thread maps\mp\gametypes\_myaddon::BloodyscreenDestroy();

//** ---Ende für HELLZone_AM--- **//

	if(game["am_show_hit_location_graphic"] == 1) {


		switch(sHitLoc) {
		
			case "head":
			case "helmet":
				state = "head";
				break;
			case "left_arm_upper":
			case "left_arm_lower":
			case "left_hand":
				state = "left_arm";
				break;
			case "right_arm_upper":
			case "right_arm_lower":
			case "right_hand":
			case "gun":
				state = "right_arm";
				break;
			case "torso_upper":
			case "neck":
			case "none":
				state = "torso_upper";
				break;
			case "torso_lower":
				state = "torso_lower";
				break;
			case "left_leg_upper":
			case "left_leg_lower":
				state = "left_leg";
				break;
			case "right_leg_upper":
			case "right_leg_lower":
				state = "right_leg";
				break;
			case "left_foot":
				state = "left_foot";
				break;
			case "right_foot":
				state = "right_foot";
				break;
 		} 		
		
		if(state != "none") self maps\mp\gametypes\_admiral_mod_hud::ShowHitFigur(state);
	}
	
	if( sMeansOfDeath == "MOD_HEAD_SHOT" ){ //** hinzugefügt für HELLZone_AM **////** wenn show hitlocation im Mod ist an erfolgt keine Ausgabe bei einen Kopfschuss **//
	
		if(game["am_show_kill_hit_location"] > 0 && isDefined(eAttacker) && isPlayer(eAttacker) && self != eAttacker) {
		
			loc_name 	= GetHitLocation(sHitLoc);		
			weapon		= maps\mp\gametypes\_admiral_mod_weapons::GetWeaponName(maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(sWeapon));
			dist		= distance(self.origin,eAttacker.origin);
			
			
			
			if(sWeapon == "tnt_bomb_mp") 	weapon	= "TNT";
			if(sWeapon == "artillery_mp") 	weapon	= "Artillery";
					
			if(dist < 60 || weapon == "Grenade" || weapon == "TNT" || weapon == "Artillery") dist = randomfloat(30)+60;
		
		if(level.nachkomma == "0")	//** Entfernung in Metern ohne Kommastelle **//
			s = int(dist/39.37);
		else	//** Entfernung in Metern mit einer Kommastelle **//
			s = int(dist/3.937)/10.0;	
				//** s ist die Distanz des Kills aus dem Admiral Mod **//
				
			if(game["am_show_kill_hit_location"] == 1) iprintln("^7" + loc_name + ":   ^7"+ s + " m   (^7"+ weapon +")");
			if(game["am_show_kill_hit_location"] == 2) self iprintln("^7" + loc_name + ":   ^7"+ s + " m   (^7"+ weapon +")");
			if(game["am_show_kill_hit_location"] == 3) self iprintlnbold("^7" + loc_name + ":   ^7"+ s + " m   (^7"+ weapon +")");
		}
	}
	
//** Hinzugefügt für HELLZone_AM **//

//** Kopfschuss Nachrichten und Sounds **//

	if( sMeansOfDeath == "MOD_HEAD_SHOT" ){
	
		weapon		= maps\mp\gametypes\_admiral_mod_weapons::GetWeaponName(maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(sWeapon));
			if(sWeapon == "tnt_bomb_mp") 	weapon	= "TNT";
			if(sWeapon == "artillery_mp") 	weapon	= "Artillery";
			
		dist = distance(self.origin,eAttacker.origin);
		
		if(level.nachkomma == "0")	//** Entfernung in Metern ohne Kommastelle **//
			s = int(dist/39.37);
		else	//** Entfernung in Metern mit einer Kommastelle **//
			s = int(dist/3.937)/10.0;	
				//** s ist die Distanz des Kills aus dem Admiral Mod **//
		
		eAttacker playlocalSound ( "headshot" );	//** Sound für den Schützen **//
//		eAttacker iprintln ( &"CUSTOM_HEADSHOT" , self.name , &"CUSTOM_ELIDISTATT" , s , &"CUSTOM_METER1" );		//** Text für den Schützen **//
		eAttacker.headshot = 1;
		
//		self playlocalSound ( "headshot" ); //** Sound für den Getöteten **//
//		self iprintln ( &"CUSTOM_HEADSHOT" , eAttacker.name , &"CUSTOM_ELISELF" );	//** Text für den Getöteten **//
//		self iprintln ( &"CUSTOM_DIST" , s , &"CUSTOM_METER2", Weapon );	
		
		iprintln ( &"CUSTOM_HEADSHOT" ,  eAttacker.name , &"CUSTOM_ELI" , self.name );//** Textnachricht für alle Spieler links unten **//
		iprintln ( &"CUSTOM_DIST" , s , &"CUSTOM_METER2", Weapon );
	}
	
//** Durch die Ausgabe von iprintln erscheinen nun 2 Ausgaben links unten für den Kopfschuss, eine Spielstandard, eine von dem Script hier **//

//** Nachricht für ersten Kill - FIRST BLOOD - **//

	if( level.firstblood == 0 && !isDefined ( self.switching_teams ) ){
		players = getentarray("player", "classname");
		
		level.firstblood++; //** Erster Kill wurde gemacht Variable != 0 gesetzt **//
		
		if( isPlayer ( eAttacker ) ){	//** Wenn Spieler Spieler Schütze ist **//

			for( i=0;i < players.size;i++ ){	//** Variable die alle Spieler Anzahl x definiert **//
						
				if( players[i] != self && players[i] != eAttacker && eAttacker != self ){	//** Alle Spieler ausser Schütze und Getöteter und Schütze ist kein Selbstmörder **//
				
					players[i] playlocalsound( "firstblood" ); 	//** Sound für alle Spieler mit Ausnahme des Schützen des Getöteten und des Selbstmörders**//
					
					players[i] iprintln( &"CUSTOM_FB",&"CUSTOM_FBALL1", eAttacker.name );	//** Text für alle Spieler mit Ausnahme des Schützen des Getöteten und des Selbstmörders **//
						
					if( level.teamplay == 0 )
						players[i] iprintln( &"CUSTOM_FBALL2" , self.name );	//** Text wenn keine Teams vorhanden sind **//
						
					else if( eAttacker.pers["team"] != self.pers["team"] && level.teamplay == 1 )	//** Text wenn Teams vorhanden sind und Opfer nicht im gleichen Team ist **//
						players[i] iprintln( &"CUSTOM_FBALL2" , self.name );	//** Text für Gegner Team **//
						
					else if( eAttacker.pers["team"] == self.pers["team"] && level.teamplay == 1 )	//** Text wenn Teams vorhanden sind und Opfer im gleichen Team ist **//
						players[i] iprintln( &"CUSTOM_FBALL3" , self.name , &"CUSTOM_FBALL4" );	//** Text für Opfer Team **//
				}
			}
			
			if( eAttacker != self ){	//** Schütze jedoch nicht Getöteter - Nachricht an Beide **//
			
//				if( eAttacker.Headshot == 1 )
//					wait 1.5;
				eAttacker playlocalsound( "firstblood" ); 	//** Sound für den Schützen mit Wartezeit beim Headshot**//
				
				self playlocalsound( "firstblood" ); 	//** Sounds für den Getöteten mit Wartezeit zwischen den Sounds **//
				self playLocalSound ( "whyami" );
					
				eAttacker iprintln( &"CUSTOM_FB",&"CUSTOM_FBATT" );	//** Text für den Schützen **//
				eAttacker iprintln( &"CUSTOM_FBALL2" , self.name );	
				
				self iprintln( &"CUSTOM_FB" ); 	//** Text für den Getöteten mit Ausnahme eines Selbstmörders **//
				self iprintln( eAttacker.name , &"CUSTOM_FBSELF1" );
			}
			
			for( i=0;i < players.size;i++ ){	//** Variable die alle Spieler Anzahl x definiert **//
			
				if( eAttacker == self ){	//** Spieler ist Selbstmörder **//
				
					players[i] playlocalsound( "firstblood" );	//** Sound für alle Spieler **//	
					self playLocalSound ( "hallelujah" );
						
					if( players[i] != self && players[i] != eAttacker )
						players[i] iprintln( &"CUSTOM_FB",&"CUSTOM_FBALL1" , eAttacker.name );	//** Text für alle Spieler mit Ausnahme des Schützen des Getöteten und des Selbstmörders **//
						
					self iprintln( &"CUSTOM_FB" );		//** Text für den Selbstmörder **//
					self iprintln( &"CUSTOM_FBSELF2" );
						
					if( level.teamplay == 0 && players[i] != self)	
						players[i] iprintln( &"CUSTOM_FBALL5" );	//** Text wenn keine Teams vorhanden sind **//
																	
					else if( eAttacker.pers["team"] != self.pers["team"] && players[i] != self && level.teamplay == 1 )	//** Text wenn Teams vorhanden sind und Selbstmörder nicht im gleichen Team ist **//
						players[i] iprintln( &"CUSTOM_FBALL5");	//** Text für Gegner Team **//
						
					else if( eAttacker.pers["team"] == self.pers["team"] && players[i] != self && level.teamplay == 1 )		//** Text wenn Teams vorhanden sind und Selbstmörder im gleichen Team ist **//
						players[i] iprintln( &"CUSTOM_FBTEAM1" , self.name , &"CUSTOM_FBTEAM2" );	//** Text für Selbstmörder Team **//
				}	
			}	
		}
	}
	
	thread maps\mp\gametypes\_myaddon::Killingspree(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc);
 
//** ---Ende für HELLZone_AM--- **//

	self.spawnProtection = undefined;	
	self maps\mp\gametypes\_admiral_mod_compass::DeleteCamping();

	self ClearHud();


	self thread maps\mp\gametypes\_admiral_mod_sounds::TalkDeath();
	
	
	if(isDefined(self.spy_radio_sound)) {
	
		self.spy_radio_sound stoploopsound();
		self.spy_radio_sound delete();
	}

	

	if(game["am_healthbar"] == 1) {

		healthBarData = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("healthbar_health");
					
		if(isDefined(healthBarData)) {
		
			self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementByName("healthbar_health",healthBarData["shader"],1,healthBarData["height"],0,(1,0,0));
		}
	}
	
	thread dropHealth(self.origin);


	// * Weapons *
	self maps\mp\gametypes\_admiral_mod_weapons::weapon_reset();
	
	// * Squad * 
	self maps\mp\gametypes\_admiral_mod_squad::SquadMemberKilled();

	

	// * BattleChatter Enemy *
	if(isDefined(eAttacker) && isPlayer(eAttacker) && eAttacker != self && isDefined(eAttacker.pers["team"]) && isDefined(self.pers["team"]) && eAttacker.pers["team"] != self.pers["team"] ) {

		eAttacker.pers["bc_lastKilledPlayer_id"] 	= self.clientid;
		eAttacker.pers["bc_lastKilledPlayer_time"] 	= getTime();
		

		if(self.pers["team"] == "axis") {
			
			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkEnemyGekillt("GE");
		}
		else {
		
			kurz = "US";
		
			switch(game["allies"]) {

				case "american":
					kurz = "US";			
					break;
				case "british":
					kurz = "UK";			
					break;		
				case "russian":
					kurz = "RU";			
					break;
			}

			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkEnemyGekillt(kurz);
		}
	}

	// * BattleChatter Friend *
	if(isDefined(eAttacker) && isPlayer(eAttacker) && eAttacker != self && isDefined(eAttacker.pers["team"]) && isDefined(self.pers["team"]) && eAttacker.pers["team"] == self.pers["team"] ) {

		if(self.pers["team"] == "axis") {
			
			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkFriendGekillt("GE");
		}
		else {
		
			kurz = "US";
		
			switch(game["allies"]) {

				case "american":
					kurz = "US";			
					break;
				case "british":
					kurz = "UK";			
					break;		
				case "russian":
					kurz = "RU";			
					break;
			}

			eAttacker thread maps\mp\gametypes\_admiral_mod_sounds::TalkFriendGekillt(kurz);
		}
	}	



	// * Teamkiller (muß hier unten stehen, damit beim Teamkill auch "Sorry" kommt ) * 
	if(isDefined(eAttacker) && isPlayer(eAttacker) && eAttacker != self && self.pers["team"] == eAttacker.pers["team"]) {
	
		// * Wenn bei CSD der Attacker den Bomb-Player killed, dann ihn auch killen *
		if(isDefined(self.bombAttached)) eAttacker suicide();
	
	
		// * Bei einer Granate kein Teamkill, das kann auch Zufall sein das ein Teammitglied getroffen wird *
	
		if(isDefined(sWeapon) && sWeapon != "frag_grenade_american_mp" && sWeapon != "frag_grenade_british_mp" && sWeapon != "frag_grenade_german_mp" && sWeapon != "frag_grenade_russian_mp") {
	
			eAttacker maps\mp\gametypes\_admiral_mod_teamkill::Teamkill(self.clientid);
		}
	}


	self maps\mp\gametypes\_admiral_mod_hud::deleteHealthBar("healthbar");


	// * Für zu heilenden Spieler (linkto) *
	self ClearPlayerObjects();


	// * Player-Class *				 
	self maps\mp\gametypes\_admiral_mod_player_class::ChangeClassByDying();



	if(isDefined(sWeapon) && sWeapon == "knife_mp") self thread BodyFallSound();

}


BodyFallSound() {

	self endon("disconnect");

	
	wait 0.25;
	
	self.bodyfallsound = spawn("script_model", self.origin);
	wait 0.05;
	self.bodyfallsound playsound("bodyfall_dirt_large");
	
	wait 2;
	
	if(isDefined(self.bodyfallsound)) self.bodyfallsound delete();

}




dropHealth(origin) {

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


    if(game["am_health_drop"] != 1) return;
    
    
    
    while(isDefined(level.health_is_dropping)) wait 0.1;    
    level.health_is_dropping = true;
    
    
    
    // * Wenn in der Rotation in der akt. Reihenposition schon ein Health existiert, dann zum überschreiben löschen *
    if(isDefined(game["am_healthqueue"][game["am_healthqueuecurrent"]]))  {
    
    	game["am_healthqueue"][game["am_healthqueuecurrent"]] delete();
    }
        
    
    
    health_nr = RandomInt(3);
    
    health_pack = "xmodel/health_small";
    
    if(health_nr == 1) health_pack = "xmodel/health_medium";
    if(health_nr == 2) health_pack = "xmodel/health_large";
    
    
    
	item_health = spawn("script_model", (0,0,0));	
	item_health setModel(health_pack);
	item_health.targetname = "item_health_" + game["am_healthqueuecurrent"];
	item_health hide(); 	

	trace = bulletTrace(origin, origin + (0,0,-500),false,undefined);		
	item_health.origin = trace["position"] + (0, 0, 1);
	item_health.angles = (0, randomint(360), 0);
	item_health show(); 

    item_health thread healthThink(health_nr);

  
    game["am_healthqueue"][game["am_healthqueuecurrent"]] = item_health;   
    game["am_healthqueuecurrent"]++;    
    
    if(game["am_healthqueuecurrent"] >= 10)  game["am_healthqueuecurrent"] = 0;
    

	level.health_is_dropping = undefined;
}


healthThink(health_nr) {

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

		
	while(1) {
	
		wait 0.5;
		
		if(!isDefined(self)) return;
		
		player = "";
		players = getentarray("player", "classname");

		for(i = 0; i < players.size; i++) {             

			player = players[i];
  		
			if(player.sessionstate == "playing" && distance(self.origin,player.origin) < 80 && player.health < 100) {
													 
				switch(health_nr) {
					
					case 0:
						player playSound("health_pickup_small");  
						player.health += 20;
						break;
					case 1:
						player playSound("health_pickup_medium");  
						player.health += 40;
						break;						
					case 2:
						player playSound("health_pickup_large");  
						player.health += 80;
						break;						
					default:
						player playSound("health_pickup_medium");  
						player.health += 40;
						break;
				}
				
				if(player.health > player.maxhealth) player.health = player.maxhealth;
				
								
				healthBarData = player maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("healthbar_health");
				
				// * Wenn Healthbar des Players nicht mehr vorhanden, dann raus hier! *
				if(!isDefined(healthBarData)) return;
				
				
				if(healthBarData["width"] < 1) 	width = 1;
				else 							width = healthBarData["width"];
				
				newWidth = int((width/100) * player.health);
				
				gruen 	= ((1.0/width)*newWidth) * 0.8;
				rot 	= 1 - gruen;

				newcolor = (rot,gruen,healthBarData["color"][2]);

				player maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementByName("healthbar_health",healthBarData["shader"],newWidth,healthBarData["height"],0.7,newcolor);


				// * Wenn Gesundheitszustand wieder ok, dann Sprinten möglich *
				if(player.health > game["am_deny_sprinting_health"]) {

					player.pers["deny_sprinting_health"] = undefined;			
				}
				
				
				// * Wenn Gesundheitszustand wieder ok, dann kein Heart-Icon mehr anzeigen * 
				if(player.health > 50) {
				
					player.show_heart_icon = undefined;
				}
				
				if(isDefined(self)) self delete();
				return;
			}
		}				
	}
}



PlayerSprinting() {

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


	self notify("PlayerSprinting");
	self endon("PlayerSprinting");

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");

	
	if(game["am_player_sprinting"] != 1) return;

	
	self.pers["sprint"] 				= undefined;
	self.pers["deny_sprinting"] 		= undefined;
	self.pers["deny_sprinting_health"] 	= undefined;


	self thread PlayerSprintingHud();
	
	
	am_weapon_check_timer = 0;
	
	
	// * Player im Spiel *
	while(self.sessionstate == "playing") {
	
		player_origin = self.origin;


		wait 0.2;
		
		
		if(self.do_status != "none") continue;


		sprintKeyPressed = false;
		if(game["am_player_sprint_key"] == 1 && self useButtonPressed()) 	sprintKeyPressed = true;
		if(game["am_player_sprint_key"] == 0 && self meleeButtonPressed()) 	sprintKeyPressed = true;


		
		// * Wenn Player vor einem Weapon Pickup steht, dann nicht beginnen zu sprinten *
    	if(isDefined(self.weapon_pickup_thread_started) || isDefined(self.offhand_pickup_thread_started)) continue;
    	
		

		// * Sprinten aktivieren *
		while(!isDefined(self.pers["deny_sprinting"]) && sprintKeyPressed && self.sessionstate == "playing" && isDefined(self.pers["am_stance"]) && self.pers["am_stance"] >= 2) {


			if(isDefined(self.pers["deny_sprinting_health"])) {
			
				self thread ShowHealthNoSprinting();
				
				wait 5;				
				break;
			}

			
			// * Wenn Spieler auf der Stelle steht, dann nicht sprinten *
			if(player_origin == self.origin) break;


			// * Wenn keine Sprint-Waffe, dann nicht sprinten *
			if(maps\mp\gametypes\_weapons::isNoSprintWeapon(self getCurrentWeapon()) == true) break;

			
			// * Wenn Spieler grad die Waffe läd, dann kein Sprinten einleiten *			
			slot = "primaryb";	
			if(self getCurrentWeapon() == self getweaponslotweapon("primary")) 	slot = "primary";	
			if(self getweaponslotclipammo(slot) == 0 && self getweaponslotammo(slot) > 0) break;
			

			// * Wenn Spieler gerade eine Granate in der Hand hält, dann nicht sprinten *
			if(isDefined(self.grenade_picked_up)) break;


			
			if(self CheckWand(20) == true || isDefined(self.pers["climb"])) break;
									
			
			// * Wenn Sprinting aus, dann sprinten verhindern *
			if(game["am_player_sprinting"] == 0) break;
			
						


			self.pers["sprint"] = true;
			self.do_status = "sprint";
			

			// * aktuelle Waffe merken *			
			rememberWeapon = self getCurrentWeapon();
			
			// * enthaltenes "am_" entfernen *
			checkWeapon = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(rememberWeapon);
			
			// * Wenn keine gültige Sprint-Waffe, dann nicht sprinten *
			if(maps\mp\gametypes\_weapons::isPistol(checkWeapon) == false && maps\mp\gametypes\_weapons::isMainWeapon(checkWeapon) == false) {
			
				self.pers["sprint"] = undefined;
				if(self.do_status == "sprint") self.do_status = "none";
				break;			
			}

			// * Slot ermitteln *
			rememberSlot = "primaryb";	
			if(rememberWeapon == self getweaponslotweapon("primary")) 	rememberSlot = "primary";	
			
			
			clipammo_count 	= self getweaponslotclipammo(rememberSlot);
			ammo_count 		= self getweaponslotammo(rememberSlot);	
			
			
			// * Wenn Sprintwaffe nicht in der Hand, dann wechseln *
			if(maps\mp\gametypes\_admiral_mod_utils::subStr(rememberWeapon,0,3) != "am_")  {

				rememberWeapon = "am_" + rememberWeapon;			
				self PlayerSwitchToSprintWeapon(rememberSlot,rememberWeapon,clipammo_count,ammo_count,1);												
			}	
	

			// * Sprinten *
			while(isDefined(self.pers["sprint"])) {

				player_origin = self.origin;
				
				wait 0.2;

									
				sprintKeyPressed = false;
				if(game["am_player_sprint_key"] == 1 && self useButtonPressed()) 	sprintKeyPressed = true;
				if(game["am_player_sprint_key"] == 0 && self meleeButtonPressed()) 	sprintKeyPressed = true;


				// * Prüfen ende *
				if(distance(player_origin,self.origin) < 25 || !sprintKeyPressed || (isDefined(self.pers["am_stance"]) && self.pers["am_stance"] < 2) || isDefined(self.pers["deny_sprinting"]) || isDefined(self.pers["deny_sprinting_health"]) || isDefined(self.grenade_picked_up) ) {


					// * Slot ermitteln *
					slot = "primaryb";	
					if(self getCurrentWeapon() == self getweaponslotweapon("primary")) slot = "primary";	
					

					// * Wenn Spieler Waffe beim Sprinten in der Hand und grad die Waffe läd, dann Sprinten nicht beenden *
					if(game["am_weapon_disabled_while_sprinting"] == 0 && self getweaponslotclipammo(slot) == 0 && self getweaponslotammo(slot) > 0) continue;
												
					
					// * Wenn Spieler gerade eine Granate in der Hand hält, dann nicht beenden *
					if(isDefined(self.grenade_picked_up)) continue;
							
					
					// * aktuelle Waffe *			
					currentWeapon = self getCurrentWeapon();

					// * enthaltenes "am_" entfernen *
					currentWeapon = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(currentWeapon);

										
					// * Wenn keine gültige Sprint-Waffe, dann nicht sprinten *
					if((maps\mp\gametypes\_weapons::isPistol(currentWeapon) == false && maps\mp\gametypes\_weapons::isMainWeapon(currentWeapon) == false) || maps\mp\gametypes\_weapons::isNoSprintWeapon(currentWeapon) == true) {

						self.pers["sprint"] = undefined;
						if(self.do_status == "sprint") self.do_status = "none";
						break;			
					}
					

											
					
					clipammo_count 	= self getweaponslotclipammo(slot);
					ammo_count 		= self getweaponslotammo(slot);

					self PlayerSwitchToNoSprintWeapon(slot,currentWeapon,clipammo_count,ammo_count,1);	
					
					
					// * Check ob bei einem Slotwechsel beim sprinten, auf dem anderen Slot noch eine Sprintwaffe steckt *					
					other_slot = "primary";
					if(slot == "primary") other_slot = "primaryb";	
					
					currentWeapon = self getweaponslotweapon(other_slot);
					
					if(maps\mp\gametypes\_admiral_mod_utils::subStr(currentWeapon,0,3) == "am_")  {

						currentWeapon = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(currentWeapon);			

						clipammo_count 	= self getweaponslotclipammo(other_slot);
						ammo_count 		= self getweaponslotammo(other_slot);

						self PlayerSwitchToNoSprintWeapon(other_slot,currentWeapon,clipammo_count,ammo_count,0);												
					}
					
					
					
					self.pers["sprint"] = undefined;
					if(self.do_status == "sprint") self.do_status = "none";
					break;

				}


				
				// * aktuellen Slot ermitteln *				
				slot = "primaryb";	
				if(self getCurrentWeapon() == self getweaponslotweapon("primary")) 	slot = "primary";	


				// * Wenn Spieler während dem Sprinten WeaponSlot gewechselt hatte *				
				if(slot != rememberSlot) {
				
					
					// * Alte Waffe wieder einstellen *
					if(game["am_weapon_disabled_while_sprinting"] == 1) {
					
						clipammo_count 	= self getweaponslotclipammo(rememberSlot);
						ammo_count 		= self getweaponslotammo(rememberSlot);
						
						self PlayerSwitchToNoSprintWeapon(rememberSlot,rememberWeapon,clipammo_count,ammo_count,0);
					}
								
				
					rememberSlot = slot;
				
					// * Wenn Weapon gewechsel *	
					currentWeapon = self getCurrentWeapon();
								
					// * aktuelle Waffe merken *			
					rememberWeapon = currentWeapon;
			
			
					// * enthaltenes "am_" entfernen *
					checkWeapon = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(rememberWeapon);
			
				
					// * Wenn keine gültige Sprint-Waffe, dann nicht sprinten *
					if((maps\mp\gametypes\_weapons::isPistol(checkWeapon) == false && maps\mp\gametypes\_weapons::isMainWeapon(checkWeapon) == false) || maps\mp\gametypes\_weapons::isNoSprintWeapon(checkWeapon) == true) {
				
						self.pers["sprint"] = undefined;
						if(self.do_status == "sprint") self.do_status = "none";
						break;			
					}

					 
					// * Wenn das keine Sprintwaffe ist, dann wechseln *
					if(maps\mp\gametypes\_admiral_mod_utils::subStr(rememberWeapon,0,3) != "am_")  {
						
						clipammo_count 	= self getweaponslotclipammo(rememberSlot);
						ammo_count 		= self getweaponslotammo(rememberSlot);

						rememberWeapon = "am_" + rememberWeapon;
						self PlayerSwitchToSprintWeapon(rememberSlot,rememberWeapon,clipammo_count,ammo_count,1);												
					}				
				}
				
			}
		}
		
		
		
		// * Check ob AM_Waffe aber kein USE-Button gedrückt *
						
		am_weapon_check_timer += 0.2;
		if(am_weapon_check_timer > 1) {
		
			am_weapon_check_timer 		= 0;		
			self.deny_weapon_arsenal 	= true;
			wait 0.5;
		
		
			wccw = self getCurrentWeapon();
					
			if(maps\mp\gametypes\_admiral_mod_utils::subStr(wccw,0,3) == "am_")  {
				
				wccw_slot = "primaryb";	
				if(self getCurrentWeapon() == self getweaponslotweapon("primary")) 	wccw_slot = "primary";	
				
				wccw = maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(wccw);			

				wccw_clipammo_count 	= self getweaponslotclipammo(wccw_slot);
				wccw_ammo_count 		= self getweaponslotammo(wccw_slot);

				self PlayerSwitchToNoSprintWeapon(wccw_slot,wccw,wccw_clipammo_count,wccw_ammo_count,1);				
			}			
			
			wait 0.3;
			self.deny_weapon_arsenal = undefined;		
		}		
	}
}


PlayerSwitchToSprintWeapon(slot,weapon,clipammo,ammo,sw) {

	self endon("killed_player");
	self endon("disconnect");


	if(game["am_weapon_disabled_while_sprinting"] == 1) {
	
		self.pers["remember_old_weapon"] 	= maps\mp\gametypes\_admiral_mod_utils::deleteAMextension(weapon);
		self.pers["remember_old_slot"] 		= slot;
		self.pers["remember_old_clipammo"] 	= clipammo;
		self.pers["remember_old_ammo"] 		= ammo;
		weapon = "am_sprintnoweapon_mp";
		
	}
	
		
	self setWeaponSlotWeapon(slot, weapon);			
	self setWeaponSlotClipAmmo(slot, clipammo);
	self setWeaponSlotAmmo(slot, ammo);

	
	if(sw == 1) {
		
		wait 0.1;
		self switchToWeapon(weapon);		
	}
}


PlayerSwitchToNoSprintWeapon(slot,weapon,clipammo,ammo,sw) {

	self endon("killed_player");
	self endon("disconnect");


	if(game["am_weapon_disabled_while_sprinting"] == 1) {

		if(isDefined(self.pers["remember_old_weapon"])) 	weapon 		= self.pers["remember_old_weapon"];
		if(isDefined(self.pers["remember_old_slot"])) 		slot 		= self.pers["remember_old_slot"];
		if(isDefined(self.pers["remember_old_clipammo"]))	clipammo 	= self.pers["remember_old_clipammo"];
		if(isDefined(self.pers["remember_old_ammo"]))		ammo 		= self.pers["remember_old_ammo"];
		
		
	}

	self setWeaponSlotWeapon(slot, weapon);			
	self setWeaponSlotClipAmmo(slot, clipammo);
	self setWeaponSlotAmmo(slot, ammo);

	if(sw == 1) {
	
		wait 0.1;
		self switchToWeapon(weapon);		
	}
}





PlayerSprintingHud() {

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


	self notify("PlayerStepRefreshingThink");
	self endon("PlayerStepRefreshingThink");

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");
	

	bar_height = 1;	
	
	self maps\mp\gametypes\_admiral_mod_hud::createPlayerHudElement("running_time", 120,455,"center","top","fullscreen","fullscreen",false,"white",12,1,2,0.8,0.4,0.4,0.4);

	
	w_time = 0.15 * game["am_sprinting_time"]/10;


	while(1) {
	
		wait 0.2;
				
		
		// * Sprint *
		while(isDefined(self.pers["sprint"])) {
		
					
			wait w_time;

			runBarData = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("running_time");

			if(isDefined(runBarData)) {

				bar_height++;
								
				if(bar_height > 22) {
				
					bar_height = 22;
					self.pers["deny_sprinting"] = true;
					break;
				}
				
				self maps\mp\gametypes\_admiral_mod_hud::scaleOverPlayerHudElement("running_time",w_time*2, runBarData["width"], bar_height);    								
			}		
		}
		
		
		// * Wenn lange gesprintet, dann ausser Atem *
		if(bar_height > 10) {

			self playSound("am_breathing"); 	
			wait 2;
			
			self thread PlayerBreath();		
		}



				
		// * Sprint Refresh *
		while(bar_height > 1 && !isDefined(self.pers["sprint"])) {
		
			wait 0.1;
			
			
			runBarData = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("running_time");

			if(isDefined(runBarData)) {

				bar_height--;

				// * Sprinten wieder erlauben *
				if(bar_height < 15) self.pers["deny_sprinting"] = undefined;


				if(bar_height < 1) {
				
					bar_height = 1;					
					break;
				}
				
				self maps\mp\gametypes\_admiral_mod_hud::scaleOverPlayerHudElement("running_time",0.3, runBarData["width"], bar_height);    								
			}			
		}
		
		self notify("stop_breathing");
	}
}


PlayerBreath() {

	self notify("PlayerBreath");
	self endon("PlayerBreath");

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");

	self endon("stop_breathing");
	
	
	if(game["am_error_logfile"] == 1) logPrint("PlayerBreath\n");


	while(!isDefined(level.sd_sound_play)) {
				
		self playSound("am_breathing"); 					
					
		if(maps\mp\gametypes\_admiral_mod_utils::isWinter()) {
											
			playfxOnTag ( game["cold_breath"], self, "TAG_EYE");
		}
	
		wait 1.7 + RandomFloat(0.1);
	}		
}



PlayerClimbing() {

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


	self notify("PlayerClimbing");
	self endon("PlayerClimbing");

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");

	
	
	if(game["am_climbing"] != 1 && self.pers["player_class"] != 7) return;

	
	// * Wenn Spion aber kein Klettern für den Spion erlaubt dann nicht weiter *
	if(self.pers["player_class"] == 7 && game["am_class_spy_can_climb"] == 0) return;


	
	self.pers["climb"] = undefined;
	self.pers["climb_wait"] = 0;
	
	 
	while(self.sessionstate == "playing") {
	
		
		wait 0.2;

		if(self.do_status != "none") continue;

	
		if(self.pers["climb_wait"] > 0) self.pers["climb_wait"] -= 0.2;
		if(self.pers["climb_wait"] < 0) self.pers["climb_wait"] = 0;


		climbKeyPressed = false;
		if(game["am_climbing_key"] == 1 && self useButtonPressed()) 	climbKeyPressed = true;
		if(game["am_climbing_key"] == 0 && self meleeButtonPressed()) 	climbKeyPressed = true;
		
		
		if(self.pers["climb_wait"] == 0 &&  !isDefined(self.pers["sprint"]) && climbKeyPressed) {  
						
			if(self CheckWand(20) == true) self Climb();	
		}

	
	}
	
	self notify("stop_climbing");	
}



touchPlayerBox(h1,h2,b1,b2) {

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


	//logprint("test start " + gettime() + "\n");
				


	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");
	self endon("stop_climbing");


	touch = touchPlayerBoxPart(h1,h2,b1,b2);
	if(touch == true) return true;

	touch = touchPlayerBoxPart(h1+5,h2-5,b1,b2);
	if(touch == true) return true;

	touch = touchPlayerBoxPart(h1+10,h2-10,b1,b2);
	if(touch == true) return true;

	touch = touchPlayerBoxPart(h1+15,h2-15,b1,b2);
	if(touch == true) return true;

	// Innenraum
	touch = touchPlayerBoxPart(h1,h2,5,b2);
	if(touch == true) return true;
	
	
	//logprint("test end " + gettime() + "\n");
	//logprint("\n");

		
	return touch;	

}



touchPlayerBoxPart(h1,h2,b1,b2) {

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


	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");
	self endon("stop_climbing");


	target_origin = self.origin;
	
	target_angles = self.angles;
	target_angles = (0,target_angles[1],0);
	


	// * Bodenplatte *
	hoehe		= h1;
	blinks   	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,90,0)),b1) + (0,0,hoehe);
	brechts  	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,-90,0)),b1)+ (0,0,hoehe);

	bvorne 		= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,0,0)),b1+1) + (0,0,hoehe);
	bhinten 	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (180,0,0)),b1+1) + (0,0,hoehe);
		
	bvlinks  	= target_origin + bvorne + blinks;
	bvrechts 	= target_origin + bvorne + brechts;	
	bhlinks  	= target_origin + bhinten + blinks;
	bhrechts 	= target_origin + bhinten + brechts;


	// * Kopfplatte *
	hoehe		= h2;
	klinks   	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,90,0)),b2) + (0,0,hoehe);
	krechts  	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,-90,0)),b2)+ (0,0,hoehe);

	kvorne 		= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (0,0,0)),b2) + (0,0,hoehe);
	khinten 	= maps\mp\_utility::vectorScale(anglesToForward(target_angles + (180,0,0)),b2) + (0,0,hoehe);
		
	kvlinks  	= target_origin + kvorne + klinks;
	kvrechts 	= target_origin + kvorne + krechts;	
	khlinks  	= target_origin + khinten + klinks;
	khrechts 	= target_origin + khinten + krechts;


	// * Check Boden *		
	trace_bodenv 	= bulletTrace(bvlinks,  bvrechts, false, undefined);		
	trace_bodenh 	= bulletTrace(bhlinks,  bhrechts, false, undefined);		
	trace_bodenl 	= bulletTrace(bvlinks,  bhlinks,  false, undefined);		
	trace_bodenr 	= bulletTrace(bvrechts, bhrechts, false, undefined);		
	trace_bodenq1 	= bulletTrace(bvlinks,  bhrechts, false, undefined);		
	trace_bodenq2 	= bulletTrace(bvrechts, bhlinks,  false, undefined);		

	// * Check Kopf *		
	trace_kopfv 	= bulletTrace(kvlinks,  kvrechts, false, undefined);		
	trace_kopfh 	= bulletTrace(khlinks,  khrechts, false, undefined);		
	trace_kopfl 	= bulletTrace(kvlinks,  khlinks,  false, undefined);		
	trace_kopfr 	= bulletTrace(kvrechts, khrechts, false, undefined);		
	trace_kopfq1 	= bulletTrace(kvlinks,  khrechts, false, undefined);		
	trace_kopfq2 	= bulletTrace(kvrechts, khlinks,  false, undefined);		

	// * Check Seiten diagonal *
	trace_seitevq1 	= bulletTrace(bvlinks,  kvrechts, false, undefined);		
	trace_seitevq2 	= bulletTrace(bvrechts, kvlinks,  false, undefined);		
	trace_seitehq1 	= bulletTrace(bhlinks,  khrechts, false, undefined);		
	trace_seitehq2 	= bulletTrace(bhrechts, khlinks,  false, undefined);		

	trace_seitelq1 	= bulletTrace(bhlinks,  kvlinks,  false, undefined);		
	trace_seitelq2 	= bulletTrace(bvlinks,  khlinks,  false, undefined);		
	trace_seiterq1 	= bulletTrace(bvrechts, khrechts, false, undefined);		
	trace_seiterq2 	= bulletTrace(bvrechts, khrechts, false, undefined);		


	
	touch = false;
	
	if(trace_bodenv["fraction"] < 1) 	touch = true;
	if(trace_bodenh["fraction"] < 1) 	touch = true;
	if(trace_bodenl["fraction"] < 1) 	touch = true;
	if(trace_bodenr["fraction"] < 1)	touch = true;
	if(trace_bodenq1["fraction"] < 1)	touch = true;
	if(trace_bodenq2["fraction"] < 1)	touch = true;
	
	if(trace_kopfv["fraction"] < 1) 	touch = true;
	if(trace_kopfh["fraction"] < 1) 	touch = true;
	if(trace_kopfl["fraction"] < 1) 	touch = true;
	if(trace_kopfr["fraction"] < 1)		touch = true;
	if(trace_kopfq1["fraction"] < 1)	touch = true;
	if(trace_kopfq2["fraction"] < 1)	touch = true;
	
	
	if(trace_seitevq1["fraction"] < 1) 	touch = true;
	if(trace_seitevq2["fraction"] < 1) 	touch = true;
	if(trace_seitehq1["fraction"] < 1) 	touch = true;
	if(trace_seitehq2["fraction"] < 1) 	touch = true;

	if(trace_seitelq1["fraction"] < 1) 	touch = true;
	if(trace_seitelq2["fraction"] < 1) 	touch = true;
	if(trace_seiterq1["fraction"] < 1) 	touch = true;
	if(trace_seiterq2["fraction"] < 1) 	touch = true;

	
	//if(touch == true) iprintln("Touch!");
		
	return touch;	

}






Climb() {

	self notify("Climb");
	self endon("Climb");

	self endon("spawned");
	self endon("killed_player");
	self endon("disconnect");
	self endon("stop_climbing");


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


	if(self touchPlayerBox(55,85,4,4)) return;
		
		
	origin = self.origin;

   	helper = spawn("script_model", (0,0,0));
	helper.origin = self.origin;
		 					
	self linkto(helper);  	
	
	high 		= 0;
	climbstep 	= 60;


	self.pers["climb"] 	= true;
	self.do_status 		= "climb";
	
	self disableWeapon();
		
	helper moveto(self.origin + (0,0,-10),0.2);
	wait 0.2;
	wait 0.05;
	
	
	helper moveto(self.origin + (0,0,20),0.2);
	wait 0.2;
	
	
	
	while(self touchPlayerBox(1,45,30,31)) {
		
		
		
		kopf = bulletTrace(self.origin + (0,0,1), self.origin + (0,0,100), true, undefined);			
		kopf_high = kopf["position"];
		
		decke = bulletTrace(kopf_high + (0,0,1), kopf_high + (0,0,1000), false, undefined);			
		decke_high = decke["position"];
		

		if(distance(kopf_high,decke_high) > 85) helper.origin = helper.origin + (0,0,6);		
		else 									break;
		
		wait 0.05;	

	
	
		// * verhindern das Spieler die Wände hoch klettern *
		high += 6;
		
		
		
			// * Kletter-Sound *
			climbstep += 30;
			if(climbstep >= 180) {

				climbstep = 0;				
				self playSound("am_step_run_plr_carpet"); 
				earthquake( 0.2, 1, self.origin, 80 );
			}

			if(distance(kopf_high,decke_high) < 80)	break;


			if(high > 180 || CheckWand(0) == false) {

				
				// * bis zu einem freien Mauerstück *
				while(CheckWand(0)) {
								
					helper.origin = helper.origin + (0,0,4);	
				
					high+=4;
					if(high > 200) break;
					
					wait 0.05;					
				}
				
				// * nach dem klettern 1 Sekunde warten *
				self.pers["climb_wait"] = 1;
				break;
			}
					
		
	}	
	
	
	self unlink();		
	
	helper delete();
	
	
	// * 1 Sekunde Sprint wait, damit kein geruckle entsteht *
	self.pers["climb_wait"] = 1;
	
	self.pers["climb"] = undefined;
	if(self.do_status == "climb") self.do_status = "none";
	
	self enableWeapon();
}



CheckWand(hoehe) {


 	self endon("spawned");
	self endon("killed_player");
    self endon("disconnect");

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



	// * nicht klettern wenn an der Playervorderseite keine Wand ist *	
	vorne = maps\mp\_utility::vectorScale(anglesToForward(self.angles), 2) + (0,0,hoehe);
	vorne2 = maps\mp\_utility::vectorScale(anglesToForward(self.angles), 40) + (0,0,hoehe);

	wand = bulletTrace(self.origin + vorne, self.origin + vorne2, false, undefined);
	if(wand["fraction"] < 1) return true;
	
	return false;
}




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

	self notify("CheckCamping");
	self endon("CheckCamping");

	level endon("am_end_map");
    level endon("round_ended");
 	
 	self endon("spawned");
	self endon("killed_player");
    self endon("disconnect");


	if(game["am_show_campers"] != 1) return;
	

	// * Bei Multiplayer-Mission auf Introscreen warten *
	if(game["am_gametype"] == "mm") level waittill("StartSubmission");


    // * Doppelte Camping Anzeige verhindern *
    self notify("mod_camping_check_die");
    self endon("mod_camping_check_die");

     
    
    campingtime = 0;
        
    while (isPlayer(self) && isAlive(self) && !isDefined(self.pers["camper"]) && self.pers["team"] != "spectator") {
           
        position = self getorigin();
        wait 1;
        
        compareposition = self getorigin();
        
        // * bleibt der Spieler innerhalb der festgelegten Camping-Distanz ? *
        if (distance(position,compareposition) < 50)   campingtime = campingtime + 1;        
        else                                           campingtime = 0;
        
                    
        if (campingtime == game["am_warn_campers_after_sec"]) {
        
            self iprintlnbold(&"AM_MP_MOVING_CAMPER");            
        }
        
        if (campingtime > game["am_indicate_campers_after_sec"] && maps\mp\gametypes\_admiral_mod_compass::NextFreeObjectiveInactiv()) {
        
			self iprintlnbold(&"AM_MP_BECAUSE_YOU_ARE");
                        
            // * Spieler Markieren * 
            self thread maps\mp\gametypes\_admiral_mod_compass::StartCamperMonitor();
            self thread maps\mp\gametypes\_myaddon::CamperFurz();
           break;             
        }    
    }
}





VoteMap(maplist) {

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


	level endon("am_vote_end");
	self endon("disconnect");


	if(game["am_vote_map"] != 1) return;

	if(isDefined(self.pers["team"]) && self.pers["team"] == "spectator") return;



	x = 170;


	self maps\mp\gametypes\_admiral_mod_hud::createPlayerHudElement("vote_point_map", x,100,"center","top","fullscreen","fullscreen", false,"white",220,14,2,0.4,0,0.7,0);
	
	self.vote_position_map = -1;
	
	
	
	while(1) {

		wait .05;
		
		
		if(self attackButtonPressed()) {

			self.vote_position_map++;
			self playlocalsound("vote");
			if(self.vote_position_map == maplist.size) self.vote_position_map = 0;
			
			self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementPositionByName("vote_point_map",x,120 + self.vote_position_map * 15);
		
			while(self attackButtonPressed()) wait 0.1;
		}
	}
}



VoteGametype(gametypelist) {

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


	level endon("am_vote_end");
	self endon("disconnect");


	if(game["am_vote_gametype"] != 1) return;
	
	if(isDefined(self.pers["team"]) && self.pers["team"] == "spectator") return;
	
	

	x = 470;


	self maps\mp\gametypes\_admiral_mod_hud::createPlayerHudElement("vote_point_gametype", x,100,"center","top","fullscreen","fullscreen", false,"white",220,14,2,0.4,0,0,0.7);
	
	self.vote_position_gametype = -1;
	
	

	while(1) {

		wait .05;
		
		
		if(self useButtonPressed()) {

			self.vote_position_gametype++;
			self playlocalsound("vote");
			if(self.vote_position_gametype == gametypelist.size) self.vote_position_gametype = 0;
			
			self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementPositionByName("vote_point_gametype",x,120 + self.vote_position_gametype * 15);
		
			wait 0.2;
		}
	}
}


SpawnVoteIntermission() {

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


    self notify("spawned");
    
    self.sessionstate = "spectator";
    self.spectatorclient = -1;
	self.archivetime = 0;
	self.psoffsettime = 0;
	self.friendlydamage = undefined;

	if(self.pers["team"] == "spectator")
		self.statusicon = "";

	maps\mp\gametypes\_spectating::setSpectatePermissions();
    self allowSpectateTeam("allies", false);
    self allowSpectateTeam("axis", false);
    self allowSpectateTeam("freelook", false);
    self allowSpectateTeam("none", true);

    spawnpointname = "mp_global_intermission";
    spawnpoints = getentarray(spawnpointname, "classname");
    spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

    if(isDefined(spawnpoint))
        self spawn(self.origin, self.angles);
    else
        maps\mp\_utility::error("NO " + spawnpointname + " SPAWNPOINTS IN MAP");
}


SpawnVotePlayer() {

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


	self endon("disconnect");
	self notify("spawned");
	self notify("end_respawn");

	resettimeout();

	// Stop shellshock and rumble
	self stopShellshock();
	self stoprumble("damage_heavy");


	self.sessionteam = self.pers["team"];
	self.sessionstate = "playing";
	self.spectatorclient = -1;
	self.archivetime = 0;
	self.psoffsettime = 0;
	self.statusicon = "";
	self.maxhealth = 100;
	self.health = self.maxhealth;
	self.friendlydamage = undefined;

	spawnpointname = "mp_tdm_spawn";
	spawnpoints = getentarray(spawnpointname, "classname");
	spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

	if(isDefined(spawnpoint))
		self spawn(spawnpoint.origin, spawnpoint.angles);
	else
		maps\mp\_utility::error("NO " + spawnpointname + " SPAWNPOINTS IN MAP");

	if(!isDefined(self.pers["savedmodel"]))
		maps\mp\gametypes\_teams::model();
	else
		maps\mp\_utility::loadModel(self.pers["savedmodel"]);

	maps\mp\gametypes\_weapons::givePistol();
	maps\mp\gametypes\_weapons::giveGrenades();
	maps\mp\gametypes\_weapons::giveBinoculars();

	if(isDefined(self.pers["weapon"])) {

		self giveWeapon(self.pers["weapon"]);
		self giveMaxAmmo(self.pers["weapon"]);
		self setSpawnWeapon(self.pers["weapon"]);
	}

	

	waittillframeend;
	self notify("spawned_player");
		
}


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


	self notify("CheckPlayerStance");
	self endon("CheckPlayerStance");

	self endon("killed_player");
	self endon("disconnect");


	// stance 0 = liegen
	// stance 1 = hocken
	// stance 2 = stehen


	while(1) {	
	
		wait 0.25;
	
	
		trace 	= bulletTrace( self.origin + ( 20, 0, 60 ), self.origin + ( -20, 0, 60 ), true, undefined );
		trace2 	= bulletTrace( self.origin + ( 20, 0, 40 ), self.origin + ( -20, 0, 40 ), true, undefined );

		stance = 2;

		if(trace["fraction"] == 1) stance = 1;
		if(trace2["fraction"] == 1) stance = 0;



		self.pers["am_stance"] = stance;
	}

}


CheckPlayerJump() {

	if(game["am_anti_bunny_hopper_shooters"] != 1)	return;
	
	if(game["am_error_logfile"] == 1) logPrint("CheckPlayerJump\n");


	self notify("CheckPlayerJump");
	self endon("CheckPlayerJump");

	self endon("killed_player");
	self endon("disconnect");

		
	while(1) {	
	
		wait 0.3;
	
		if(!self isOnGround()) {
			
			self disableWeapon();
			while(!self isOnGround()) wait 0.2;	
		}
		self enableWeapon();		
	}

}




ShowPlayerDatas() {

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


	self notify("ShowPlayerDatas");
	self endon("ShowPlayerDatas");

	self endon("killed_player");
	self endon("disconnect");


	while(1) {
	
		self iprintln("Player Origin: " + self.origin);
		wait 2;
		self iprintln("Player Angles: " + self.angles);
		wait 2;
		
		if(isDefined(level.testbomb)) {
		
			self iprintlnbold("^3Melee=^2Place Object,^3Use=^2Change Object,^3Attack=^2Change Angle");
			wait 4;	
					
			self iprintln("Object Origin: " + level.testbomb.origin);			
			wait 2;
		
			self iprintln("Object Angles: " + level.testbomb.angles);
		}
		
		wait 5;
	}
}


ShowPlayerPosition() {

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


	self notify("ShowPlayerPosition");
	self endon("ShowPlayerPosition");

	self endon("killed_player");
	self endon("disconnect");


	while(1) {
	
		self iprintln("Player Origin: " + self.origin);
		self iprintln("Player Angles: " + self.angles);
		wait 2;
		
		
		wait 5;
	}
}




EnableModelPlanter() {

	self endon("killed_player");
	self endon("disconnect");


	if(isDefined(self.pers["imabot"])) return;


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


	self notify("EnableBombPlanter");
	self endon("EnableBombPlanter");


	trace = self GetEyeTrace();
	angles = vectortoangles(vectornormalize(trace["normal"])) + (90,0,0);

	level.testbomb = spawn("script_model", trace["position"]);
	level.testbomb.angles = angles;
	

	model[0] = "xmodel/mp_tntbomb";
	model[1] = "xmodel/german_artillery_flak88_aa_nm_static";
	model[2] = "xmodel/prop_map_4_obj";
	model[3] = "xmodel/military_german_fieldradio_grey";
	model[4] = "xmodel/prop_barrel_benzin";

	
	m = 0;
	angle[0] = level.testbomb.angles[0];
	angle[1] = level.testbomb.angles[1];
	angle[2] = level.testbomb.angles[2];
	
	winkel = 0;
	
	while(1) {
	
		if(self meleeButtonPressed()) {

	
			trace = self GetEyeTrace();
			angles = vectortoangles(vectornormalize(trace["normal"])) + (90,0,0);

			level.testbomb.origin = trace["position"];
			level.testbomb.angles = (angle[0],angle[1],angle[2]);
			level.testbomb setmodel(model[m]);
			
			winkel++;
			if(winkel > 2) winkel = 0;
			
			wait 1;							
		}

		if(self useButtonPressed()) {

			m++;
			if(m == model.size) m = 0;
			
			level.testbomb setmodel(model[m]);
			
						
			wait 1;
			
		}

		if(self attackButtonPressed()) {

			angle[winkel] += 2;
			if(angle[winkel] >= 360) angle[winkel] = 0;
			level.testbomb.angles = (angle[0],angle[1],angle[2]);
					
		}

		wait 0.1;
	}
}


ShowHealthNoSprinting() {

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


    self endon("disconnect");
	self endon("killed_player");

	level endon("am_end_map");


	self setClientCvar("am_ui_player_info_text", "@AM_MP_LNG_HEALTH_NO_SPRINTING");
	self.pers["am_ui_player_info_text"] = "AM_MP_LNG_HEALTH_NO_SPRINTING";
	wait 5;
	self setClientCvar("am_ui_player_info_text", " ");
	self.pers["am_ui_player_info_text"] = " ";

}


LostHelmet(vDir,iDamage) {


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


    self endon("disconnect");
	self endon("killed_player");

	/*
	if(self.pers["savedmodel"]["attach"][1]["model"] != "") {

		helmoffset = self getPlayerHeadOffset();
		
		helm = spawn("script_model",self.origin + helmoffset);
		helm setmodel(self.pers["savedmodel"]["attach"][1]["model"]);
		helm.angles = self.angles;

		self detach(self.pers["savedmodel"]["attach"][1]["model"],"");
		self.pers["savedmodel"]["attach"][1]["model"] = "";


		vRichtung = maps\mp\_utility::vectorScale(vectorNormalize(vDir),iDamage/4.5);
					

		helm thread maps\mp\gametypes\_admiral_mod_world::fallObject("helm", vRichtung, "grenade_bounce_brick");
	}
	*/


}


GetEyeTrace() {

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


	self endon("spawned");
	self endon("disconnect");
	self endon("killed_player");


	startOrigin = self getEye() + self getPlayerEyeOffset();
	forward = anglesToForward( self getplayerangles() );
	forward = maps\mp\_utility::vectorScale( forward, 100000 );
	endOrigin = startOrigin + forward;

	trace = bulletTrace( startOrigin, endOrigin, false, self );

	
	return trace;
}


StartBleeding(client_id, client_team, iDFlags, sMeansOfDeath, sWeapon) {
 

	self endon("spawned");
	self endon("disconnect");
	self endon("killed_player");


	if(!isDefined(client_id) || !isDefined(client_team)) return;

    	
       

	// * Wenn Bleeding eingeschaltet oder ein Spieler am Boden liegt und auf den Medic wartet *
	if(game["am_bleeding"] != 1) return;
	

	if(isDefined(self.is_bleeding)) return;
	self.is_bleeding = true;


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


	wait 0.1;
	self maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",self.health);


	wait 1;


	if(self.health >= game["am_bleeding_start_if_health_less_than"]) {
	
		self.is_bleeding = undefined;
		return;
	}
	
	
	iDFlags |= 4;


	
	while(self.health < game["am_bleeding_start_if_health_less_than"]) {
		
		
		self playsound("am_atmen",self.origin);				

		
		eAttacker = getPlayer(client_id,client_team);		    
		if(!isDefined(eAttacker)) eAttacker = self;


		blood_sub = game["am_bleeding_speed"];
		
		// * Wenn verletzter Spieler sich auf den Boden legt, dann nur /2 des Schadens *
		if(game["am_bleeding_speed"] > 1 && self.pers["am_stance"] == 0) blood_sub = int(blood_sub/2);

		
		self finishPlayerDamage(self, eAttacker, blood_sub, iDFlags, sMeansOfDeath, "none", self.origin, (0,0,0), "none",0);
		
		self maps\mp\gametypes\_shellshock::shellshockOnDamage(sMeansOfDeath, game["am_bleeding_speed"]);
		
		

		self maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",self.health);


		self setClientCvar("am_ui_show_healthbar_back", 0);
		self.pers["am_ui_show_healthbar_back"] = 0;
		
		wait 0.40;
		self setClientCvar("am_ui_show_healthbar_back", game["am_hud_style"]);
		self.pers["am_ui_show_healthbar_back"] = game["am_hud_style"];
		
		wait 0.40;
	}

		
	self setClientCvar("am_ui_show_healthbar_back", game["am_hud_style"]);
	self.pers["am_ui_show_healthbar_back"] = game["am_hud_style"];
		
	self.is_bleeding = undefined;

}




getPlayerEyeOffset() {

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


    self endon("disconnect");

	
	offset = (0,0,18);

	if(self.pers["am_stance"] == 1) offset = (0,0,2);
	if(self.pers["am_stance"] == 0) offset = (0,0,-27);

	
	return offset;
}


getPlayerHeadOffset() {

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


    self endon("disconnect");

	
	offset = (0,0,74);

	switch(self.pers["am_stance"]) {

		// gebückt
		case 1:
			offset = (0,0,54);
			break;

		// liegend
		case 0:
			offset = (0,0,25);
			break;      

	}
	
	return offset;
}












// **********************************************************************


getPlayer(client_id,team) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == client_id && isDefined(players[i].pers["team"]) && players[i].pers["team"] == team) {

			return players[i];
		}
	}
		
	return undefined;
}

getPlayerName(client_id) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == client_id) {

			return players[i].name;
		}
	}
		
	return "";
}


getPlayerPlaying(client_id,team) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].sessionstate == "playing" && players[i].clientid == client_id && isDefined(players[i].pers["team"]) && players[i].pers["team"] == team) {

			return players[i];
		}
	}
		
	return undefined;
}




getPlayerOrigin(client_id) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].sessionstate == "playing" && players[i].clientid == client_id) {

			return players[i].origin;
		}
	}
		
	return undefined;
}


getPlayerEyesOrigin(client_id) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == client_id) {

			if(players[i].sessionstate == "playing") 	{
			
				offset = (0,0,0);			
				if(players[i].pers["am_stance"] == 1) offset = (0,0,-28);
				if(players[i].pers["am_stance"] == 0) offset = (0,0,-40);
			
				return players[i] getEye() + offset;
			}
			else return undefined;
		}
	}
		
	return undefined;
}


getPlayerEyesTarget(client_id) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == client_id) {

			if(players[i].sessionstate == "playing") {
								
				players[i].eye = spawn("script_origin",(0,0,0));
				players[i].eye linkto (players[i],"tag_eye",(0,0,0),(0,0,0));
				
				origin = players[i].eye.origin;
				
				players[i].eye delete();
				
				if(isDefined(origin)) 	return origin;
				else 					return undefined;
			}
			else return undefined;
		}
	}
		
	return undefined;
}




getPlayerStance(client_id) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].sessionstate == "playing" && players[i].clientid == client_id) {

			return players[i].pers["am_stance"];
		}
	}
		
	return undefined;
}


searchPlayerGetClientId(thread_owner_client_id,sessionstate,team,radius,health) {

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


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].sessionstate == sessionstate && players[i].clientid != thread_owner_client_id && isDefined(players[i].pers["team"]) && players[i].pers["team"] == team && distance(self.origin,players[i].origin) < radius && players[i].health < health) {

			return players[i].clientid;
		}
	}
		
	return undefined;
}


checkPlayerState(clientid,sessionstate,team,radius,health) {
	
 	if(game["am_error_logfile"] == 1) logPrint("checkPlayerState\n");


    self endon("disconnect");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == sessionstate && isDefined(players[i].pers["team"]) && players[i].pers["team"] == team && distance(self.origin,players[i].origin) < radius && players[i].health < health) {

			return true;
		}
	}
		
	return false;
}

checkPlayerLookingToObject(player_client_id, object_origin, range) {

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


	players = getentarray("player", "classname");

	for(i = 0; i < players.size; i++) {             

		if(players[i].clientid == player_client_id) {
			
			if(players[i] playerLookingAt(object_origin,range)) {
			
				return true;
			}	
			
			break;
		}
	}		
			
	return false;
}

playerLookingAt(object_origin, range) {

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


	self endon("disconnect");


	if(!isDefined(self.pers["am_stance"])) return false;
	

	offset = 18;

	if(self.pers["am_stance"] == 1) offset = 2;
	if(self.pers["am_stance"] == 0) offset = -27;

	// * Nur wenn der Spieler das Objekt anguckt *								
	target_range = vectordot(anglestoforward(self getplayerangles()),anglestoforward(vectortoangles(vectornormalize((self getEye() + (0,0,offset)) - object_origin)))) * -1;
	
	if(target_range >= range) return true;
	
	return false;

}

checkPlayerInRange(origin,team, radius) {

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

	
	players = getentarray("player", "classname");

	for(i = 0; i < players.size; i++) {             

		if(players[i].sessionstate == "playing" && isDefined(players[i].pers["team"]) && (players[i].pers["team"] == team || team == "all") && distance(players[i].origin,origin) < radius) {
			
			return players[i].clientid;			
		}
	}		
	
	return -1;
}


checkOtherPlayerInRange(client_id, origin, team, radius) {

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

	
	players = getentarray("player", "classname");

	for(i = 0; i < players.size; i++) {             

		if(players[i].sessionstate == "playing" && isDefined(players[i].pers["team"]) && (players[i].pers["team"] == team || team == "all") && distance(players[i].origin,origin) < radius && players[i].clientid != client_id) {
			
			return players[i].clientid;			
		}
	}		
	
	return -1;
}



getPlayerHealth(clientid) {
	
	if(game["am_error_logfile"] == 1) logPrint("getPlayerHealth\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			return players[i].health;
		}
	}
		
	return 1;
}

changePlayerHealth(clientid,health_step) {
	
	if(game["am_error_logfile"] == 1) logPrint("changePlayerHealth\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {

			if(players[i].health >= 100) return false;
			
			players[i].health += health_step;
			
			players[i] thread maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",players[i].health);
			
			return true;
		}
	}
		
	return false;
}

setPlayerHealth(clientid,health) {
	
	if(game["am_error_logfile"] == 1) logPrint("setPlayerHealth\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i].health = health;
			
			players[i] thread maps\mp\gametypes\_admiral_mod_hud::updateHealthBar("healthbar",players[i].health);
			break;
		}
	}	
}


doShellShock(clientid, shellshock, time) {
	
	if(game["am_error_logfile"] == 1) logPrint("doShellShock\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i] shellshock(shellshock, time);
			break;
		}
	}	
}



doBurningBody(clientid) {
	
 	if(game["am_error_logfile"] == 1) logPrint("BurningBody\n");
 	
	
	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i] thread burn();
			break;
		}
	}		
}



burn() {


	if(game["am_player_can_burn"] != 1) return;


	self endon("disconnect");
	self endon("killed_player");


	if(isDefined(self.brennt)) return;	
	self.brennt = true;
	
	for(i=0;i<15;i++) {
	
		switch(randomint(10)) {
		
			case 0: 
				tag = "j_head";
				break;
			case 1:
				tag = "j_shoulder_le";
				break;
			case 2:
				tag = "j_shoulder_ri";
				break;			
			case 3: 
				tag = "j_hip_le";
				break;
			case 4: 
				tag = "j_hip_ri";
				break;
			case 5: 
				tag = "j_knee_le";
				break;
			case 6: 
				tag = "j_knee_ri";
				break;
			case 7: 
				tag = "j_wrist_le";
				break;
			case 8:	
				tag = "j_wrist_ri";
				break;			
			case 9: 
				tag = "j_head";
				break;
			default: 
				tag = "pelvis";
				break;
		}
				
		playfxontag(game["body_burn_fx"], self, tag);
		playfxontag(game["body_burn_torso_fx"], self, "pelvis");
		
				
		wait .25;
	}
	
	self.brennt = undefined;
}






allowSprinting(clientid) {
	
	if(game["am_error_logfile"] == 1) logPrint("allowSprinting\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i].pers["deny_sprinting_health"] = undefined;	
			break;
		}
	}	
}


deleteHeartIcon(clientid) {

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


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i].show_heart_icon = undefined;
			break;
		}
	}		
}



setPlayerInfo(clientid,info_text) {
	
	if(game["am_error_logfile"] == 1) logPrint("setPlayerInfo\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			// * Player-Info anzeigen *
			players[i] maps\mp\gametypes\_admiral_mod_hud::showPlayerInfo(info_text);			
			break;
		}
	}	
}



givePlayerPoints(clientid,clientteam,points) {
	
	if(!isDefined(clientid) || !isDefined(clientteam)) return;
	
	if(clientteam != "allies" && clientteam != "axis") return;
	
	
	
	if(game["am_error_logfile"] == 1) logPrint("givePlayerPoints\n");


	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			players[i] doPlayerPoints(clientteam,points);
			break;
		}
	}	
}



doPlayerPoints(clientteam,points) {
	
	self endon("disconnect");


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

	
	if(isDefined(self.pers["score"])) 	{
	
		self.pers["score"] = self.pers["score"] + points;		
		
		if(isDefined(self.score)) self.score = self.pers["score"];
	}
	else {
	
		self.score 	= self.score + points;
	}


	if(game["am_gametype"] != "dom") level [[level.checkScoreLimit]]();	
	
	
	if(game["am_gametype"] == "tdm") {
		
		teamscore = getTeamScore(clientteam);
		teamscore += points;
		setTeamScore(clientteam, teamscore);
	}
	
	
	level notify("update_teamscore_hud");
	level notify("update_allhud_score");
}




linkPlayer(clientid) {
	

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

	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			// * Player-Info anzeigen *
			players[i] linkto(self);			
			break;
		}
	}	
}


unlinkPlayer(clientid) {

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

	players = getentarray("player", "classname");

	for(i=0;i<players.size;i++) {

		if(players[i].clientid == clientid && players[i].sessionstate == "playing") {
			
			// * Player-Info anzeigen *
			players[i] unlink();			
			break;
		}
	}	
}


WaitForRadius(origin, radius, height) {


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

	if(!isDefined(origin) || !isDefined(radius) || !isDefined(height)) return;


	trigger = spawn("trigger_radius", origin, 0, radius, height);	

	while(1) {
				
		trigger waittill("trigger", other);	
	
		if(isPlayer(other) && other.sessionstate == "playing") {
					
			if(isDefined(trigger)) trigger delete();
			return other;
		}	
		
		wait 0.1;
	}
	
	if(isDefined(trigger)) trigger delete();
}



WaitForUseObject(object, team, origin, radius, height, text) {

	level endon("mission_end");
	level endon("submission_end");


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

	if(!isDefined(team) || !isDefined(origin) || !isDefined(radius) || !isDefined(height) || !isDefined(text)) return;


	trigger = spawn("trigger_radius", origin, 0, radius, height);	

	while(isDefined(object)) {
		
		wait 0.1;
		trigger waittill("trigger", other);	
	
		// * Damit man nicht mitten in den Objekten planten kann *
		if(isDefined(object.isTurret) && distance(object.origin, other.origin) < 50) continue;
		if(isDefined(object.isBarrels) && distance(object.origin, other.origin) < 70) continue;
			
	
		if(isPlayer(other) && other.sessionstate == "playing" && (other.pers["team"] == team || team == "all") && other isOnGround()) {
			
			
			if(other useButtonPressed()) {
			
				if(isDefined(trigger)) trigger delete();
				return other;				
			}
			
			
			if(!isDefined(other.pers["show_use_info_text"])) {
			
				other.pers["show_use_info_text"] = true;
				other thread PlayerShowHintString(trigger, object, team, origin, radius, height, text);		
			}
		}	
	}
	
	if(isDefined(trigger)) trigger delete();
}


WaitForLookAtUseObject(object, team, origin, radius, height, text) {


	level endon("mission_end");
	level endon("submission_end");


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

	if(!isDefined(team) || !isDefined(origin) || !isDefined(radius) || !isDefined(height) || !isDefined(text)) return;


	trigger = spawn("trigger_radius", origin, 0, radius, height);	

	while(isDefined(object)) {
		
		wait 0.1;
		trigger waittill("trigger", other);	
	
		if(isPlayer(other) && other.sessionstate == "playing" && (other.pers["team"] == team || team == "all") && other isOnGround()) {
			
			
			if(other useButtonPressed()) {

				offset = 18;
			
				if(other.pers["am_stance"] == 1) offset = 2;
				if(other.pers["am_stance"] == 0) offset = -27;

				// * Nur wenn der Spieler das Object, ansonsten einfach übersprinten *								
				target_range = vectordot(anglestoforward(other getplayerangles()),anglestoforward(vectortoangles(vectornormalize((other getEye() + (0,0,offset)) - origin)))) * -1;

				if(target_range >= 0.97) {
			
					if(isDefined(trigger)) trigger delete();
					return other;				
				}
			}
			
			
			if(!isDefined(other.pers["show_use_info_text"])) {
			
				other.pers["show_use_info_text"] = true;
				other thread PlayerShowHintString(trigger, object, team, origin, radius, height, text);		
			}
		}	
	}
	
	if(isDefined(trigger)) trigger delete();
}




PlayerSetHintString(object, team, origin, radius, height, text) {

	level endon("mission_end");
	level endon("submission_end");


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

	if(!isDefined(team) || !isDefined(origin) || !isDefined(radius) || !isDefined(height) || !isDefined(text)) return;


	trigger = spawn("trigger_radius", origin, 0, radius, height);	

	while(isDefined(object)) {
		
		wait 0.1;
		trigger waittill("trigger", other);	
	
		// * Damit man nicht mitten in den Objekten planten kann *
		if(isDefined(object.isTurret) && distance(object.origin, other.origin) < 50) continue;
		if(isDefined(object.isBarrels) && distance(object.origin, other.origin) < 70) continue;
		
	
		if(isPlayer(other) && other.sessionstate == "playing" && (other.pers["team"] == team || team == "all") && !isDefined(other.pers["show_use_info_text"])) {
			
			other.pers["show_use_info_text"] = true;
			other thread PlayerShowHintString(trigger, object, team, origin, radius, height, text);		
		}	
	}
	
	if(isDefined(trigger)) trigger delete();
}


PlayerShowHintString(trigger, object, team, origin, radius, height, text) {

	self endon("killed_player");
	self endon("disconnect");
	

	self maps\mp\gametypes\_admiral_mod_hud::createPlayerHudElement("usehand", 320,340,"center","middle","fullscreen","fullscreen",false,"gfx/icons/hint_usable",32,32,1,1,1,1,1);
	self setClientCvar("am_ui_use_info_text", text);
	self.pers["am_ui_use_info_text"] = text;


	while(isDefined(trigger) && isDefined(object) && distance(self.origin,origin) <= radius) {

		// * Damit man nicht mitten in den Objekten planten kann *
		if(isDefined(object.isTurret) && distance(self.origin,origin) < 50) break;
		if(isDefined(object.isBarrels) && distance(self.origin,origin) < 70) break;

	
		wait 0.2;	
	}

	self setClientCvar("am_ui_use_info_text", " ");
	self.pers["am_ui_use_info_text"] = " ";
	self maps\mp\gametypes\_admiral_mod_hud::deletePlayerHudElementByName("usehand");

	
	self.pers["show_use_info_text"] = undefined;
}



WaitForPlayersUseButton(object, team, origin, radius, height) {

	level endon("mission_end");
	level endon("submission_end");


	trigger = spawn("trigger_radius", origin, 0, radius, height);	
	
		
	while(isDefined(object)) {
	
		wait 0.1;
		trigger waittill("trigger", other);	
		
		if(isPlayer(other) && other.sessionstate == "playing" && (other.pers["team"] == team || team == "all") && other useButtonPressed()) {
			
			if(isDefined(trigger)) trigger delete();
			return other;
		}
	}
	
	if(isDefined(trigger)) trigger delete();
	return;
}



WaitForPlayerReachPosition(team, origin, radius, height) {
	
	level endon("mission_end");
	level endon("submission_end");


	trigger = spawn("trigger_radius", origin, 0, radius, height);	
	
		
	while(1) {
	
		wait 0.1;
		trigger waittill("trigger", other);	
		
		if(isPlayer(other) && other.sessionstate == "playing" && (other.pers["team"] == team || team == "all")) {
			
			if(isDefined(trigger)) trigger delete();
			return true;
		}
	}
	
	if(isDefined(trigger)) trigger delete();
	return false;
}



// *********************************************************************



getPlayerClassName(class) {

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


	switch(class) {
	
		case 0:		
			classname = "Soldier Light";
			break;
	
		case 1:		
			classname = "Soldier Heavy";
			break;
			
		case 2:		
			classname = "Support";
			break;
			
		case 3:		
			classname = "Sharpshooter";
			break;

		case 4:		
			classname = "Medic";
			break;	
			
		case 5:		
			classname = "TNT";
			break;
			
		case 6:		
			classname = "Officer";
			break;		

		case 7:		
			classname = "Spy";
			break;		


		default:
			classname = "Unknown";
			break;				
	}		
	
	return classname;

}


GetTeamKurz() {


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


	self endon("killed_player");
	self endon("disconnect");


	kurz = "GE";


	if(self.pers["team"] == "allies")
	{
		switch(game["allies"]) {
		
		case "american":
			kurz = "US";			
			break;
		case "british":
			kurz = "UK";			
			break;		
		case "russian":
			kurz = "RU";			
			break;
		}
	}
	
	
	return kurz;
}


GetKurzAllies() {


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

	
	kurz = "US";
	
	switch(game["allies"]) {
		
		case "american":
			kurz = "US";			
			break;
		case "british":
			kurz = "UK";			
			break;		
		case "russian":
			kurz = "RU";			
			break;
	}
	
	
	return kurz;
}


CheckClanMember() {


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


	self endon("killed_player");
    self endon("disconnect");


	// * Namen holen *
	name = self.name;

	// * Clan-Member TAG Check *
	if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(toLower(name), toLower(game["am_clanmember_tag"])) > -1) {
     
    	self.pers["clanmember"] = true;
    }


}

CheckDoublePlayerName() {

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


	self endon("killed_player");
    self endon("disconnect");


	// * Namen holen *
	name = self.name;

  
    // * Unknown Soldier *
	if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(toLower(name), "unknown") > -1) {
     
    	name = self MakeNewPlayerName(); 
    }

	// * neuen Namen schreiben *
	self setClientCvar("name", name);
}


CheckUnknownSoldier() {

	if(game["am_change_unknown_soldier_names"] != 1) return;

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


	self endon("killed_player");
    self endon("disconnect");


	// * Namen holen *
	name = self.name;

  
    // * Unknown Soldier *
	if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(toLower(name), "unknown") > -1) {
      
    	name = self MakeNewPlayerName(); 
    
    	//self iprintln(name);
    }


	trys = 0;

	// * Check ob dieser Name schon existiert, dann einen anderen vergeben oder eine Nummer anhängen *
	while(self CheckPlayerNameExist(name)) {
	
		name = self MakeNewPlayerName(); 
		
		trys++;
		if(trys > 5) {
		
			name += " " + randomint(500);
			break;
		}
	}
	
	// * neuen Namen schreiben *
	self setClientCvar("name", name);

}



CheckPlayerNameFunctions() {


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


	self endon("killed_player");
    self endon("disconnect");


	// * Namen holen *
	name 	= self.name;
	oldname = self.name;

  	

	// * Cinematic, Laser Dot ein bzw. ausschalten *
	if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(name, ":cl1=1") > -1) {
	
		self.pers["enable_cinemascope"] = true;
		name = maps\mp\gametypes\_admiral_mod_utils::replace_string(":cl1=1", "", name);
	}
	
	if(maps\mp\gametypes\_admiral_mod_utils::find_first_string(name, ":cl2=0") > -1) {
	
		self.pers["disable_laser_dot"] = true;
		name = maps\mp\gametypes\_admiral_mod_utils::replace_string(":cl2=0", "", name);
	}

	
	// * neuen Namen schreiben *
	if(name != oldname) self setClientCvar("name", name);

}


CheckPlayerNameExist(name) {

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


	self endon("killed_player");
    self endon("disconnect");

	// * Check ob dieser Name schon existiert *
	players = getentarray("player", "classname");

	for(i = 0; i < players.size; i++) {             

		if(players[i] != self && players[i].name == name) {
			
			return true;
		}
	}	
	
	return false;
}


MakeNewPlayerName() {

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


	self endon("killed_player");
    self endon("disconnect");

      
	rnd_names = game["am_unknown_soldier_names"];
	
	name = rnd_names[randomint(rnd_names.size)];

	return name;
}


CheckPlayerInactive() {


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

	
	self notify("CheckPlayerInactive");
	self endon("CheckPlayerInactive");

    self endon("disconnect");

	
	if(game["am_switch_incative_player_to_spectator"] != 1 || isDefined(self.pers["imabot_automatic"])) return;


	wait 10;
	
	
	while(1) {
	
		origin = self.origin;
		angles = self.angles;
		
		wait game["am_switch_incative_player_to_spectator_waittime"];			
	
		if(self.sessionstate == "playing" && self.origin == origin && self.angles == angles) {
		
			self suicide();	
			wait 0.1;
			self [[level.spectator]]();			
			break;		
		}
	}

}



CheckPlayerCrosshair() {

	self notify("CheckPlayerCrosshair");
	self endon("CheckPlayerCrosshair");


	self endon("disconnect");

	while(1) {

		wait 45;

		self setClientCvar("cg_drawCrosshair", game["am_crosshairs"]);
		wait 0.1;
		self setClientCvar("cg_crosshairEnemyColor", game["am_crosshair_red"]);
		wait 0.1;		
		self setClientCvar("cg_drawcrosshairnames", game["am_crosshair_names"]);
		wait 0.1;			
	}
}


CheckCompassDots() {

	self notify("CheckCompassDots");
	self endon("CheckCompassDots");


	self endon("disconnect");

	while(1) {

		wait 30;

		self setClientCvar("cg_hudCompassSoundPingFadeTime", game["am_compass_red_dots_fade_time"]);			
	}
}







DamageToPlayers(points, client_id, client_team, position, radius, height, maxDamage, minDamage, iDFlags, sMeansOfDeath, sWeapon) {

	if(!isDefined(client_id) || !isDefined(client_team)) return;


	// * Wenn keine Submission läuft, dann kein kill möglich * 
	if(game["am_gametype"] == "mm" && !isDefined(level.submission_is_runnning)) return;


    eAttacker = getPlayer(client_id, client_team);
    
    
    
    
    if(isDefined(sWeapon) && sWeapon != "gas_grenade_mp" && sWeapon != "fire_grenade_mp" && sWeapon != "knife_mp") level DoQuake(position, radius + 1200, 1);
    
 
    players = [];
    players = getentarray("player", "classname");
                        
    for(i = 0; i < players.size; i++) {             

        // * Wenn aufrufendes Objekt nicht mehr da, dann Ende *
        if(!isDefined(self)) return;
        
                
        player = players[i];
                              
        
        dist = distance(player.origin, position);
        
        if(!isDefined(player.spawnProtection) && dist < radius && isPlayer(player) && isAlive(player) && player.sessionstate == "playing" && (player.origin[2] < position[2] + height && player.origin[2] > position[2] - height) ) {                     
               
               
            if(isDefined(sWeapon) && (sWeapon == "gas_grenade_mp")) {
            
            	// * Spion hat Gasmaske *
            	if(player.pers["player_class"] == 7) continue;
            }
   
               
               
            if(dist > 0)    damage = ((maxDamage * (radius/dist)) / 8) + minDamage;
            else            damage = maxDamage;
           
           
            damage = int(damage);
              
           
              
            trace = bulletTrace(position + (0,0,20), player.origin + (0,0,40), false, undefined);	
						
			// * Wenn ein Gegenstand zwischen Spieler und Projektil, dann kein Damage (nicht bei Gas + Fire) *
			if(trace["fraction"] != 1 && sWeapon != "gas_grenade_mp") continue;  
              

			
			// * Wenn Friendly Fire = off, dann kein Damage beim eigenen Team *
			if(level.friendlyfire == "0" && isDefined(player.pers["team"]) && player.pers["team"] == client_team) 
			{
				return;
			}			
			
			
			
			health = player.health - damage;
			
			
			// * eAttacker bekommt Punkte für jeden getöteten Player, aber nur wenn eAttacker im Spiel *				      
			// * Punkte vergeben (-1 da auch bei finishPlayerDamage 1 Punkt vergeben wird = KilledPlayer) *
			if(isDefined(eAttacker)) {
			
				if(health <= 0 && eAttacker != player) {
					
					if(points > 1) {
	
						givePlayerPoints(client_id,client_team,points-1);				
					}
				}
			}
		
			player thread GoingToDeath(sWeapon);
			
					
			if(health < 1) {		
			
				// * Wenn eattacker noch lebt *
				if(isDefined(eAttacker)) 	player finishPlayerDamage(player, eAttacker, damage, iDFlags, sMeansOfDeath, sWeapon, position, (0,0,0), "none",0);
				else 						player finishPlayerDamage(player, player, damage, iDFlags, sMeansOfDeath, sWeapon, position, (0,0,0), "none",0);
			}
			
			
			if(isDefined(sWeapon) && sWeapon == "fire_grenade_mp") 	{
			
				doShellShock(player.clientid, "shellshock_fire", randomfloat(0.2) + 0.2);
				doBurningBody(player.clientid);
			}

			if(isDefined(sWeapon) && sWeapon == "gas_grenade_mp") 	{
			
				doShellShock(player.clientid, "shellshock_gas", randomfloat(0.4) + 0.3);
			}
			
			if(isDefined(sWeapon) && sWeapon != "gas_grenade_mp" && sWeapon != "fire_grenade_mp" && sWeapon != "knife_mp") player maps\mp\gametypes\_shellshock::shellshockOnDamage(sMeansOfDeath, damage);

			setPlayerHealth(player.clientid, health);           
        }                       
    }    
     
    return;       
}



GoingToDeath(sWeapon) {


	self endon("killed_player");
	self endon("disconnect");


	if(isDefined(self.DeathSequence)) return;
	
	self.DeathSequence = true;

	
	wait (randomfloat(1.2) + 0.1);

	if(sWeapon == "fire_grenade_mp") {

		self playsound("am_brennen",self.origin);		
	}

	if(sWeapon == "gas_grenade_mp")	{

		self playsound("am_gurgeln",self.origin);	
	}

	
	wait 2.5;
	
	self.DeathSequence = undefined;
	
}



DoQuake(position, radius, strength) {
    
    if(!isDefined(position) || !isDefined(radius) || !isDefined(strength)) return;
    if(radius < 10) radius = 10;
    
    
    players = [];
    players = getentarray("player", "classname");
                        
    for(i = 0; i < players.size; i++) {             
   
                
        player = players[i];                              
        
        dist = distance(player.origin, position);
        
        if(dist < radius && isPlayer(player) && isAlive(player) && player.sessionstate == "playing") {                     

			mod_length 		= 2.6 - ((2.6/radius)*dist);
			mod_strength 	= strength - ((strength/radius)*dist);
			
			if(mod_length < 0.01) 		mod_length = 0.01;
			if(mod_strength < 0.01) 	mod_strength = 0.01;
			
			
			//iprintln("Stärke: " + mod_strength);
			//iprintln("Zeit: " + mod_length);
			
			earthquake(mod_strength, mod_length, player.origin, 100); 
			
			//self shellshock(0.75, 2, player.origin, 2250);
			//self viewkick(100, player.origin); 
			
			//level.player allowStand(false);
			//level.player allowCrouch(false);
			//level.player allowProne(true);
					
			//wait 0.15;
			//level.player viewkick(127, level.player.origin);  //Amount should be in the range 0-127, and is normalized "damage".  No damage is done.
			//level.player shellshock(strShocktype, duration);
					
		}
	}
   
   
   	return;
}




GetHitLocation(loc) {

	loc_name = loc;
		
	if(loc == "helmet")				loc_name = "Helmet";
	if(loc == "head") 				loc_name = "Head";
	if(loc == "neck")				loc_name = "Neck";
	
	if(loc == "torso_upper")		loc_name = "Upper Torso";
	if(loc == "torso_lower")		loc_name = "Lower Torso";
	
	if(loc == "left_arm_upper")		loc_name = "Upper Left Arm";
	if(loc == "left_arm_lower")		loc_name = "Lower Left Arm";
	if(loc == "left_hand")			loc_name = "Left Hand";
	
	if(loc == "right_arm_upper")	loc_name = "Upper Right Arm";
	if(loc == "right_arm_lower")	loc_name = "Lower Right Arm";
	if(loc == "right_hand")			loc_name = "Right Hand";
	
	if(loc == "right_leg_upper")	loc_name = "Upper Right Leg";
	if(loc == "right_leg_lower")	loc_name = "Lower Right Leg";
	if(loc == "right_foot")			loc_name = "Right Foot";
	
	if(loc == "left_leg_upper")		loc_name = "Upper Left Leg";
	if(loc == "left_leg_lower")		loc_name = "Lower Left Leg";
	if(loc == "left_foot")			loc_name = "Left Foot";
	
	if(loc == "none")				loc_name = "Body";
	
	return loc_name;

}




PlayerToEarth(spawn_position) {


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


	self endon("disconnect");
	self endon("killed_player");
 

	if(game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd" || isDefined(self.pers["first_parachute"])) return;
	self.pers["first_parachute"] = true;



	// * Falls Mapberechnung noch nicht zu Ende * 
	
	z = 0;
	while(!isDefined(game["map_dimension_ready"])) {
	
		wait 1;
		z++;
		if(z > 5) return; // * Wenn nach 5 Sekunden keine Berechnung erfolgte, dann kein Parachute *
	
	}

	// * Falls keine Maphöhe existiert kein Parachute *
	if(!isDefined(game["map_dim_vMax"][2])) return;
	

    self.do_status = "parachuting";
 
 	start_position = spawn_position + (0,0,game["map_dim_vMax"][2] - 250);
 	
 
 
    self.fallschirm = spawn("script_model", (0,0,0));
    self.fallschirm setModel("xmodel/am_fallschirm");    
   	self.fallschirm.origin = self.origin;
  	self.fallschirm.angles = self.angles + (0,0,90);
    self.fallschirm hide();
    
    self.fahrstuhl = spawn("script_model", (0,0,0));
   	self.fahrstuhl.origin = self.fallschirm.origin;
  	self.fahrstuhl.angles = self.angles;
        
    
    self.fallschirm linkto (self.fahrstuhl);
    self linkto(self.fahrstuhl);
    


	self.fahrstuhl.origin = start_position;
    self.fallschirm show();

	

    fallschirm_loslass_hoehe = 200;

    
    self.fahrstuhl playloopsound("am_parachuting");

    
    if(isDefined(spawn_position) && spawn_position == (0,0,0)) {

        trace = bulletTrace(self.origin + (0,0,-100),self.origin + (0,0,-30000),false,undefined);

        ziel_position = trace["position"];
        ziel_position = ziel_position + (0,0,fallschirm_loslass_hoehe);

        // * Boden finden *
        ziel_position = BodenPositionFinden(ziel_position);
    }
    else {
    
        ziel_position = spawn_position;
    }
    
   
    zeit  = maps\mp\gametypes\_admiral_mod_utils::ZeitSpeedBerechnung(50, start_position, ziel_position);
            
    self.fahrstuhl moveto(ziel_position, zeit);
    
    zeit        = zeit * 20;
    loslassen   = int(zeit-50);


    landen          = 0;
    landen_sound    = 0;
    
    for(i=0;i < zeit && isPlayer(self) && isAlive(self);i++) {      
        
        if(isDefined(self.fahrstuhl)) self.fahrstuhl.angles = self.angles;
        wait 0.05;
    
    
        while(self meleeButtonPressed() && landen == 0 && game["am_parachute_drive_melee"] == 1) {
        
            
            if(isDefined(self.fahrstuhl)) self.fahrstuhl.angles = self.angles;
            wait 0.05;
        
            forwardvector   = anglestoforward(self.angles);                
            vorwaerts_pos   = self.fahrstuhl.origin + (maps\mp\_utility::vectorScale(forwardvector,10)) + (0,0,-5);
        
            if(isDefined(self.fahrstuhl)) self.fahrstuhl.origin = vorwaerts_pos; 
            
            
            ziel_position = BodenPositionFinden(self.origin) + (0,0,50);
            
           
            // * Lande-Sound abspielen *
            if(landen_sound == 0 && distance(self.origin, ziel_position) < fallschirm_loslass_hoehe * 2)  {
            
                landen_sound = 1;                
            }
           
            
            if(distance(self.origin, ziel_position) < fallschirm_loslass_hoehe) {
            
                landen = 1;
                break;  
            }
            
            
            i = -1;
        }
        
        
        if(i == -1) {  

            zeit_neu = maps\mp\gametypes\_admiral_mod_utils::ZeitSpeedBerechnung(50, self.origin, ziel_position);            
            self.fahrstuhl moveto(ziel_position, zeit_neu);    

            i           = 0;
            zeit        = zeit_neu * 20;
            loslassen   = int(zeit-40);
        }
    
    
    
        // * 2 Sekunden vorher den Landungs-Sound abspielen *
                
        if(landen_sound == 0 && i == loslassen) {    
            
            landen_sound = 1;                    
        }
    
    }
    
	self.fahrstuhl stoploopsound();
    wait 0.1;   
    self playsound("Land_dirt_big"); 
    
    self unlink();
   
           
    self.do_status = "none";
        
    
    if(isDefined(self.fallschirm)) self.fallschirm stopLoopSound();

    if(isDefined(self.fahrstuhl))  self.fahrstuhl delete();
    if(isDefined(self.fallschirm)) self.fallschirm delete();

     
   return;  
}


BodenPositionFinden(start_position) {


    schleifen_anzahl    = 0;
   
    trace_point         = true;            
    ziel_position       = start_position;
   
    while(trace_point == true) {

        schleifen_anzahl++;
        if(schleifen_anzahl > 10) break;

        trace = bulletTrace(start_position + (0,0,-50), start_position + (0,0,-30000),false,undefined);

        if(isDefined(trace["position"]) && trace["position"][2] > -25000) {
        
            ziel_position   = trace["position"];
            
            //iprintln(ziel_position[2]);
            //iprintln(trace["surfacetype"]);
            
        }
        else {
        
            trace_point    = false;
        }

    }
            

    return ziel_position;
}

GetClanTeam() {

	clan_team_count["allies"] = 0;
	clan_team_count["axis"] = 0;

    
    players = [];
    players = getentarray("player", "classname");
                        
    for(i = 0; i < players.size; i++) {      
    
    	if(isDefined(players[i].pers["clanmember"])) {
    	
    		if(isDefined(players[i].pers["team"]) && (players[i].pers["team"] == "allies" || players[i].pers["team"] == "axis")) clan_team_count[players[i].pers["team"]]++;
    	}    
    }
        
    if(clan_team_count["allies"] > clan_team_count["axis"]) 		return "allies";
	else if(clan_team_count["allies"] < clan_team_count["axis"])	return "axis";
	else 															return "none";		
	
}

