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



showAutoDownload() {

	if(game["am_error_logfile"] == 1) logPrint("showAutoDownload\n");
	
	if(game["am_only_with_autodownload"] == 1) {
	
		level deleteLevelHudElementByName("null_bild");
		level createLevelHudElement("null_bild", 0,0,"left","top","fullscreen","fullscreen",false,"gfx/custom/empty.tga",640,480,100,1,1,1,1);
	}
}

showClanLevelLogoText() {

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

	if(game["am_show_clan_logo_text"] == 1) {
	
		level deleteLevelHudElementByName("clan_logo_text");
		level createLevelTextHudElement("clan_logo_text", game["am_clan_logo_text_xpos"],game["am_clan_logo_text_ypos"],"left","top","fullscreen","fullscreen",false,game["am_clan_logo_text"],undefined,0.8,-3,game["am_clan_logo_text_alpha"],1,1,1);
 	}
 
 	if(game["am_show_clan_logo_graphic"] == 1) {
 
		level deleteLevelHudElementByName("clan_logo");
		level createLevelHudElement("clan_logo", game["am_clan_logo_graphic_xpos"],game["am_clan_logo_graphic_ypos"],"center","middle","fullscreen","fullscreen",false,"clanlogo.tga",game["am_clan_logo_graphic_width"],game["am_clan_logo_graphic_height"],2,game["am_clan_logo_graphic_alpha"],1,1,1);
	}
}


activateCinemascope() {

	if(game["am_cinemascope"] != 1 && !isDefined(self.pers["enable_cinemascope"])) return;


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

	self endon("disconnect");


	self deletePlayerHudElementByName("cinema_top");
	self deletePlayerHudElementByName("cinema_bottom");
	self createPlayerHudElement("cinema_top", 0,0,"left","top","fullscreen","fullscreen",false,"black",640,80,-50,1,0,0,0);
	self createPlayerHudElement("cinema_bottom", 0,400,"left","top","fullscreen","fullscreen",false,"black",640,80,-50,1,0,0,0);

	self.pers["cinemascope"] = true;		
}



showHealthBar(name,x,y) {

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


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

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

	self deletePlayerHudElementByName(name + "_health");
	self createPlayerHudElement(name + "_health", x+2,y+2,"left","top","fullscreen","fullscreen",true,"white",126,8,0,0.6,0.1,0.85,0.1);


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

	self.pers["healthbar"] = true;
		
}

updateHealthBar(name,newHealth) {

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


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

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



	healthBarData = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName(name + "_health");

	if(isDefined(healthBarData)) {

		newWidth = int((healthBarData["width"]/self.maxhealth) * newHealth);

		if(newWidth < 0) newWidth = 0;
		if(newWidth > 126) newWidth = 126;

		gruen 	= ((1.0/healthBarData["width"])*newWidth) * 0.7;
		rot 	= 1 - gruen;

		newcolor = (rot,gruen,healthBarData["color"][2]);
					
		self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementByName(name + "_health",healthBarData["shader"],newWidth,healthBarData["height"],healthBarData["alpha"],newcolor);
	}	
}

deleteHealthBar(name) {

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

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


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

	
	self deletePlayerHudElementByName(name + "_health");

	self setClientCvar("am_ui_show_healthbar", 0);
	self.pers["am_ui_show_healthbar"] = 0;

	self setClientCvar("am_ui_show_healthbar_back", 0);
	self.pers["am_ui_show_healthbar_back"] = 0;	
		
}


activateSpawnHealth() {

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


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

	
	// * Wenn schon Protection, dann nicht nochmal *
    if(isDefined(self.spawnProtection)) return;
	self.spawnProtection = true;
	
	
	if(game["am_error_logfile"] == 1) logPrint("activateSpawnHealth\n");
	
	
	self iprintln(&"AM_MP_YOU_ARE_PROTECTED"); 
	
    
//    wait 1; // 1 Sekunde warten, bis die HeadIcons eingestellt sind und man sie bearbeiten kann!
    
    

    protect_time = game["am_player_spawn_protect_time"];   
    wait 0.1;
/*    
    self deletePlayerHudElementByName("spawnHealth");
 	self createPlayerHudElement("spawnHealth", 120,420,"center","middle","fullscreen","fullscreen",false,"gfx/hud/hud@health_cross.tga",24,24,1,0,1,1,1);
    wait 1;

    
    self fadeOverPlayerHudElement("spawnHealth",0.05,0.8);
    self scaleOverPlayerHudElement("spawnHealth",0.1, 64, 64);    
    self scaleOverPlayerHudElement("spawnHealth",0.05, 34, 34);
*/    
    
    
    startpos = self.origin;    
    
    // * Protection Zeit *
    for(i=0;i<((protect_time-1)*2);i++) {        
        
        // * Abfragen ob Spieler aus dem Bereich laeuft *
        if(distance(startpos, self.origin) > 300) break;     
        
		// * Wenn Spieler attackiert, dann kein Schutz mehr *
		if( self attackButtonPressed() ) break;  
		
        wait 0.5;   // * 2 Mal pro Sekunden abfragen *  
		
	}
     
/*    
    // * Fade *
    self fadeOverPlayerHudElement("spawnHealth",1,0);
    self scaleOverPlayerHudElement("spawnHealth",0.5, 10, 10);
      
   
   	self deletePlayerHudElementByName("spawnHealth");


   	
    
    wait 1;
*/        
    self.spawnProtection = undefined;

	self iprintln(&"AM_MP_YOU_ARE_NOT_PROTECTED");    
	
}



showEmptyImage() {

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

	self endon("disconnect");


		   
   	// * Nur 1 Mal beim ersten Spawn aktivieren *
   	if(isDefined(self.pers["showEmptyImage_on"])) return;   
   	self.pers["showEmptyImage_on"] = true;

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


	self iprintlnbold(&"AM_MP_CHECKER_BOARD_0");
	wait 1;
	self iprintlnbold(&"AM_MP_CHECKER_BOARD_1");
	wait 3;
	self iprintlnbold(" ");
}


showWelcome() {

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

	self endon("disconnect");


		   
   	// * Nur 1 Mal beim ersten Spawn aktivieren *
   	if(isDefined(self.pers["welcome_message_on"])) return;   
   	self.pers["welcome_message_on"] = true;
       
 	
 	if(game["am_error_logfile"] == 1) logPrint("showWelcome\n");
   
 
 	// * Bei Multiplayer-Mission auf Introscreen warten *
 	if(game["am_gametype"] == "mm") {
 	
 		level waittill("StartSubmission");
 		wait 10;
 	}

 
 
	wait 7;  
	self iprintlnbold(" ");
	

	count = 0;       
	while(isDefined(game["am_welcome_msg"]) && count < game["am_welcome_msg"].size) {

		message = game["am_welcome_msg"][count];

		if(maps\mp\gametypes\_admiral_mod_utils::substr(maps\mp\gametypes\_admiral_mod_utils::toLower(message),0,4) != "wait") {

			if(isDefined(message)) self iprintlnbold(message);
			wait 2;
		}
		else {              
	
			zeit = maps\mp\gametypes\_admiral_mod_utils::strToInt(message);
			wait zeit; 
		}
	
		count++;               
		if(count == game["am_welcome_msg"].size) break;
	
		wait 0.1;
	} 
}


showMessages() {          
     
	if(game["am_show_roto_messages"] != 1) return;
	

   	// * Nicht doppelt *
   	level notify("am_messages");
   	level endon("am_messages");   
          
	level endon("am_vote_start");


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


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


	wait 10; 
	
 
   	for(;;) {
  
 		wait 5;                  
        iprintln(" ");
 
 
      			
		if(game["am_show_mod_features"] == 1) showModModes();
        
        wait 5;
        iprintln(" "); 
 
 
        count = 0;
        while(isDefined(game["am_messages"]) && game["am_messages"].size > 0) {
                        
            message = game["am_messages"][count];
            
            if(maps\mp\gametypes\_admiral_mod_utils::substr(maps\mp\gametypes\_admiral_mod_utils::toLower(message),0,4) != "wait") {
            
                if(isDefined(message)) iprintln(message);
                wait 2;
            }
            else {              
                
                zeit = maps\mp\gametypes\_admiral_mod_utils::strToInt(message);
                wait zeit; 
            }
            
            count++;               
            if(count == game["am_messages"].size) break;
            
            wait 0.1;
        }         
        		
    }

}


showNextMap() {

	level endon("am_vote_start");


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



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



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


	next_map_name = maps\mp\gametypes\_admiral_mod_utils::getNextMap();
  	next_gametype = maps\mp\gametypes\_admiral_mod_utils::getNextGametype();
  	

	map 		= getMapNameAsLocalizedString(next_map_name);
 	gametype 	= getGametypeNameAsLocalizedString(next_gametype);



    
    for(;;) {
    	
    	
    	wait 35;
    	
		
		iprintln(&"AM_MP_NEXT_MAP", map, gametype);
	
    	wait game["am_show_next_map_loop_wait_time"];
    } 	  
}



getMapNameAsLocalizedString(next_map_name) {

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

	switch(next_map_name) {

		case "mp_breakout":
			map = &"AM_MP_MAP_BREAKOUT";
			break;
		case "mp_brecourt":
			map = &"AM_MP_MAP_BRECOURT";
			break;
		case "mp_burgundy":
			map = &"AM_MP_MAP_BURGUNDY";
			break;
		case "mp_carentan":
			map = &"AM_MP_MAP_CARENTAN";
			break;
		case "mp_dawnville":
			map = &"AM_MP_MAP_DAWNVILLE";
			break;
		case "mp_decoy":
			map = &"AM_MP_MAP_DECOY";
			break;
		case "mp_downtown":
			map = &"AM_MP_MAP_DOWNTOWN";
			break;
		case "mp_farmhouse":
			map = &"AM_MP_MAP_FARMHOUSE";
			break;
		case "mp_firestation":
			map = &"AM_MP_MAP_FIRESTATION";
			break;
		case "mp_leningrad":
			map = &"AM_MP_MAP_LENINGRAD";
			break;
		case "mp_matmata":
			map = &"AM_MP_MAP_MATMATA";
			break;
		case "mp_railyard":
			map = &"AM_MP_MAP_RAILYARD";
			break;
		case "mp_toujane":
			map = &"AM_MP_MAP_TOUJANE";
			break;
		case "mp_trainstation":
			map = &"AM_MP_MAP_TRAINSTATION";
			break;
		case "mp_rhine":
			map = &"AM_MP_MAP_RHINE";
			break;
		case "mp_harbor":
			map = &"AM_MP_MAP_HARBOR";
			break;
		default:
			map = &"AM_MP_MAP_UNKNOWN";
			break;
	}
	
	return map;
}


getGametypeNameAsLocalizedString(gametype) {


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


	switch(gametype) {

		case "dm":
			gametype = &"AM_MP_GAMETYPE_NAME_DM";
			break;
		case "tdm":
			gametype = &"AM_MP_GAMETYPE_NAME_TDM";
			break;
		case "hq":
			gametype = &"AM_MP_GAMETYPE_NAME_HQ";
			break;
		case "hq2":
			gametype = &"AM_MP_GAMETYPE_NAME_HQ2";
			break;
		case "ctf":
			gametype = &"AM_MP_GAMETYPE_NAME_CTF";
			break;
		case "ctfb":
			gametype = &"AM_MP_GAMETYPE_NAME_CTFB";
			break;
		case "ctb":
			gametype = &"AM_MP_GAMETYPE_NAME_CTB";
			break;
		case "sd":
			gametype = &"AM_MP_GAMETYPE_NAME_SD";
			break;
		case "sdr":
			gametype = &"AM_MP_GAMETYPE_NAME_SDR";
			break;
		case "csd":
			gametype = &"AM_MP_GAMETYPE_NAME_CSD";
			break;
		case "mm":
			gametype = &"AM_MP_GAMETYPE_NAME_MM";
			break;
		case "dom":
			gametype = &"AM_MP_GAMETYPE_NAME_DOM";
			break;
		case "noz":
			gametype = &"AM_MP_GAMETYPE_NAME_NOZ";
			break;
		case "ein":
			gametype = &"AM_MP_GAMETYPE_NAME_EIN";
			break;
		default:
			gametype = &"AM_MP_GAMETYPE_NAME_UNKNOWN";
			break;
	}   	
	
	return gametype;
}


showModModes() {

	level endon("am_vote_start");



	if(game["am_error_logfile"] == 1) logPrint("showModModes\n");
	
	
	// * Bei Multiplayer-Mission auf Introscreen warten *
	if(game["am_gametype"] == "mm") level waittill("StartSubmission");



	if(game["am_player_sprint_key"] == 1) 	sprint_button	= &"AM_MP_USE_BUTTON";
	else									sprint_button 	= &"AM_MP_MELEE_BUTTON";
	if(game["am_climbing_key"] == 1)		climb_button 	= &"AM_MP_USE_BUTTON";
	else									climb_button 	= &"AM_MP_MELEE_BUTTON";

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

		iprintln(&"AM_MP_BATTLECHATTER_IS_ON");
		wait 4;
	}    	
	if(game["am_player_sprinting"] == 1) {

		iprintln(&"AM_MP_SPRINTING_IS_ON", sprint_button);
		wait 4;
	}    	
	if(game["am_anti_teamkill"] == 1) {

		iprintln(&"AM_MP_ANTITEAMKILL_IS_ON");
		wait 4;
	}    	
	if(game["am_weapon_limit"] == 1) {

		iprintln(&"AM_MP_WEAPON_LIMIT_IS_ON");
		wait 4;
	}  
	if(game["am_climbing"] == 1) {

		iprintln(&"AM_MP_CLIMBING_IS_ON", climb_button);
		wait 4;
	}
	if(game["am_player_artillerie"] == 1) {

		iprintln(&"AM_MP_ARTILLERY_IS_ON");
		wait 4;
	}
}







showTeamkillerBlackScreen() {

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

	self endon("disconnect");


	self createPlayerHudElement("teamkiller_black_screen", 0,0,"left","top","fullscreen","fullscreen",true,"black",640,480,20,1,0,0,0);

	
}



InitLifes() {

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

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



	level createLevelHudElement("flag_allies", 598,15, "center","middle","fullscreen","fullscreen",false,game["hudicon_allies"],17,17,1,1,1,1,1);
	level createLevelHudElement("flag_axis", 626,15, "center","middle","fullscreen","fullscreen",false,game["hudicon_axis"],17,17,1,1,1,1,1);

	level createLevelHudElement("alive", 570,39,"center","middle","fullscreen","fullscreen",false,"gfx/icons/hud@tt30.tga",15,15,1,1,1,1,1);
	level createLevelHudElement("death", 570,62,"center","middle","fullscreen","fullscreen",false,"gfx/hud/death_suicide.tga",15,15,1,game["am_player_life_board_dead_alpha"],1,1,1);

	level createLevelTextHudElement("alive_allies", 598,37,"center","middle","fullscreen","fullscreen",false,undefined,0,1.7,1,1,1,1,1); 
	level createLevelTextHudElement("alive_axis", 626, 37,"center","middle","fullscreen","fullscreen",false,undefined,0,1.7,1,1,1,1,1);

	level createLevelTextHudElement("dead_allies", 598,60,"center","middle","fullscreen","fullscreen",false,undefined,0,1.7,1,game["am_player_life_board_dead_alpha"],1,1,1); 
	level createLevelTextHudElement("dead_axis", 626, 60,"center","middle","fullscreen","fullscreen",false,undefined,0,1.7,1,game["am_player_life_board_dead_alpha"],1,1,1);

}



UpdateLifes() {


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

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


    last_allies_alive 	= 0;
    last_axis_alive 	= 0;
    last_allies_dead 	= 0;
    last_axis_dead 		= 0;

 
    while(1) {      
        
        wait 1;
     
     
        players = getentarray("player", "classname");
    
        if(players.size < 1) continue;
          
    
        lifes["allies"]["alive"] 	= 0;
        lifes["allies"]["dead"] 	= 0;
        lifes["axis"]["alive"] 		= 0;
        lifes["axis"]["dead"] 		= 0;
        
            
        for(i = 0; i < players.size; i++) {
            
            player = players[i];
                
            if(isDefined(player.pers["team"]) && player.pers["team"] != "spectator" && !isDefined(player.pers["imabot_automatic"])) {
    
                if (isAlive(player))    lifes[player.pers["team"]]["alive"]++;
                else                    lifes[player.pers["team"]]["dead"]++;                  
            }
        }   


		if(last_allies_alive != lifes["allies"]["alive"] || last_axis_alive != lifes["axis"]["alive"] || last_allies_dead != lifes["allies"]["dead"] || last_axis_dead != lifes["axis"]["dead"]) {
    
			changeLevelTextHudElementByName("alive_allies",	undefined,lifes["allies"]["alive"],1.7,1,(1,1,1));           
			changeLevelTextHudElementByName("alive_axis",	undefined,lifes["axis"]["alive"],1.7,1,(1,1,1));           
			changeLevelTextHudElementByName("dead_allies",	undefined,lifes["allies"]["dead"],1.7,game["am_player_life_board_dead_alpha"],(1,1,1));           
			changeLevelTextHudElementByName("dead_axis",	undefined,lifes["axis"]["dead"],1.7,game["am_player_life_board_dead_alpha"],(1,1,1));           

			last_allies_alive 	= lifes["allies"]["alive"];
			last_axis_alive 	= lifes["axis"]["alive"];
			last_allies_dead 	= lifes["allies"]["dead"];
			last_axis_dead 		= lifes["axis"]["dead"];       
       	}
    }
}



showLaserDot() {

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

	
	if(isDefined(self.pers["disable_laser_dot"])) return;
	
	if(game["am_error_logfile"] == 1) logPrint("showLaserDot\n");
  
  
    if(game["am_laser_dot"]) {
   
   		x = 320 - game["am_laser_size"]/2;
   		y = 240 - game["am_laser_size"]/2;
   		s = game["am_laser_size"];
   		a = game["am_laser_alpha"];
   		r = game["am_laser_color_red"];
   		g = game["am_laser_color_green"];
   		b = game["am_laser_color_blue"];
   
   		self deletePlayerHudElementByName("laser_dot");
 		self createPlayerHudElement("laser_dot", game["am_laser_x_pos"],game["am_laser_y_pos"],"center","middle","fullscreen","fullscreen",false,"white",s,s,1,a,r,g,b);
         
    }

	
	laserdot = true;

	while(self.sessionstate == "playing") {
	
		wait 0.5;


		current = self getcurrentweapon();
		if(current == "none" && laserdot == true) {
		
			laser_dot = self getPlayerHudElementDataByName("laser_dot");

			if(isDefined(laser_dot)) {
					
				self changePlayerHudElementByName("laser_dot",laser_dot["shader"],laser_dot["width"],laser_dot["height"],0,laser_dot["color"]);
				laserdot = false;
			}
		}			

		if(current != "none" && laserdot == false) {
		
			laser_dot = self getPlayerHudElementDataByName("laser_dot");

			if(isDefined(laser_dot)) {
					
				self changePlayerHudElementByName("laser_dot",laser_dot["shader"],laser_dot["width"],laser_dot["height"],1,laser_dot["color"]);
				laserdot = true;
			}
		}			


	}


}



showVoteBoard() {

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

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

	

	// * VoteBoard Background *
	if(game["am_vote_map"] == 1) 		level createLevelHudElement("vote_board_back_map", 170,110,"center","top","fullscreen","fullscreen",false,"white",220,260,1,0.7,0,0,0);
	if(game["am_vote_gametype"] == 1) 	level createLevelHudElement("vote_board_back_gametype", 470,110,"center","top","fullscreen","fullscreen",false,"white",220,260,1,0.7,0,0,0);
 
 
 
 	// * Die restlichen Elemente *
    players = getentarray("player", "classname");
                            
	for(p = 0; p < players.size; p++) {
		
		
		players[p] setClientCvar("am_ui_show_vote_headline", "1");
		players[p].pers["am_ui_show_vote_headline"] = 1;	

		if(game["am_vote_map"] == 1) {
		
			players[p] setClientCvar("am_ui_show_vote_map_button", "1");
			players[p].pers["am_ui_show_vote_map_button"] = 1;
		}
		if(game["am_vote_gametype"] == 1) {
		
			players[p] setClientCvar("am_ui_show_vote_gametype_button", "1");
			players[p].pers["am_ui_show_vote_gametype_button"] = 1;
		}


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

			players[p] setClientCvar("am_ui_show_vote_board_maps", "1");						
			players[p].pers["am_ui_show_vote_board_maps"] = 1;
		}

		if(game["am_vote_gametype"] == 1) {
		
			players[p] setClientCvar("am_ui_show_vote_board_gametypes", "1");
			players[p].pers["am_ui_show_vote_board_gametypes"] = 1;			
		}		
	}

}



ShowPlayerStance() {


	if(game["am_player_sprinting"] == 0) return;



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

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

	
	old_stance = -1;


    self deletePlayerHudElementByName("stance"); 			
	self createPlayerHudElement("stance", 120,460,"center","middle","fullscreen","fullscreen",false,"gfx/custom/stance_stand_schablone.tga",36,36,3,1,1,1,1);
    self deletePlayerHudElementByName("background_man"); 			
	self createPlayerHudElement("background_man", 120,460,"center","middle","fullscreen","fullscreen",false,"gfx/custom/stance_stand_man.tga",36,36,1,1,1,1,1);


	while(1) {
	
		wait 0.3;
		
	
		if(isDefined(self.pers["am_stance"])) {
	
			if(old_stance != self.pers["am_stance"]) {
	
    			stance_data = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("stance");
 			
 				if(isDefined(stance_data)) {
 				
 					if(self.pers["am_stance"] == 2)	self changePlayerHudElementByName("stance","gfx/custom/stance_stand_schablone.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);
 					if(self.pers["am_stance"] == 1)	self changePlayerHudElementByName("stance","gfx/custom/stance_crouch_schablone.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);
 					if(self.pers["am_stance"] == 0)	self changePlayerHudElementByName("stance","gfx/custom/stance_prone_schablone.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);
				}
				old_stance = self.pers["am_stance"];
			}
			
			
			if(isDefined(self.pers["sprint"])) {
			
				self.pers["am_stance"] = 3;
			
				stance_data = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("stance");
				if(isDefined(stance_data)) self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementByName("stance","gfx/custom/stance_sprint_schablone.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);
				stance_data = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("background_man");
				if(isDefined(stance_data)) self maps\mp\gametypes\_admiral_mod_hud::changePlayerHudElementByName("background_man","gfx/custom/stance_sprint_man.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);
				
			
				old_stance = self.pers["am_stance"];
			}
			else {
						
				stance_data = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("background_man");
				if(isDefined(stance_data)) changePlayerHudElementByName("background_man","gfx/custom/stance_stand_man.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);


				if(self.pers["am_stance"] == 3) {

					stance_data = self maps\mp\gametypes\_admiral_mod_hud::getPlayerHudElementDataByName("stance");
					if(isDefined(stance_data)) changePlayerHudElementByName("stance","gfx/custom/stance_stand_schablone.tga",stance_data["width"],stance_data["height"],stance_data["alpha"],stance_data["color"]);

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


ShowPlayerRank() {

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

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

	
	old_score = -1;
	old_rank = self.pers["rank"];
	
	while(level.mapended == false) {

		wait 1;
		
		if(self.score == old_score) continue;
		
		
		if(level.mapended == true) break;
		
		
		if(self.score < game["am_rank_2_min_points"]) {		

			self.pers["rank"] = 1;			
			self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
			self.pers["am_ui_show_player_rank"] = self.pers["rank"];		
			
			self.pers["old_rank"] = self.pers["rank"];
			
			old_score = self.score;
			
			if(game["am_gametype"] != "dm" && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headicon = "gfx/custom/hud@us_rank1.tga";
			if(game["am_use_player_class_system"] == 0 || game["am_show_rank_icons_in_highscore"] == 1) self.statusicon = "gfx/custom/hud@us_rank1.tga";
		}
		
		else if(self.score >= game["am_rank_2_min_points"] && self.score < game["am_rank_3_min_points"]) {		

			self.pers["rank"] = 2;						
			self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
			self.pers["am_ui_show_player_rank"] = self.pers["rank"];	

			if(self.pers["rank"] != self.pers["old_rank"]) self thread NewRankAnimation();
			self.pers["old_rank"] = self.pers["rank"];
			
			old_score = self.score;
			
			if(game["am_gametype"] != "dm" && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headicon = "gfx/custom/hud@us_rank2.tga";
			if(game["am_use_player_class_system"] == 0 || game["am_show_rank_icons_in_highscore"] == 1) self.statusicon = "gfx/custom/hud@us_rank2.tga";
		}
		else if(self.score >= game["am_rank_3_min_points"] && self.score < game["am_rank_4_min_points"]) {		

			self.pers["rank"] = 3;
			self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
			self.pers["am_ui_show_player_rank"] = self.pers["rank"];
			
			if(self.pers["rank"] != self.pers["old_rank"]) self thread NewRankAnimation();
			self.pers["old_rank"] = self.pers["rank"];
			
			old_score = self.score;
			
			if(game["am_gametype"] != "dm" && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headicon = "gfx/custom/hud@us_rank3.tga";
			if(game["am_use_player_class_system"] == 0 || game["am_show_rank_icons_in_highscore"] == 1) self.statusicon = "gfx/custom/hud@us_rank3.tga";
		}
		else if(self.score >= game["am_rank_4_min_points"] && self.score < game["am_rank_5_min_points"]) {		

			self.pers["rank"] = 4;
			self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
			self.pers["am_ui_show_player_rank"] = self.pers["rank"];
			
			if(self.pers["rank"] != self.pers["old_rank"]) self thread NewRankAnimation();
			self.pers["old_rank"] = self.pers["rank"];
			
			old_score = self.score;
			
			if(game["am_gametype"] != "dm" && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headicon = "gfx/custom/hud@us_rank4.tga";
			if(game["am_use_player_class_system"] == 0 || game["am_show_rank_icons_in_highscore"] == 1) self.statusicon = "gfx/custom/hud@us_rank4.tga";
		}
		else if(self.score >= game["am_rank_5_min_points"]) {		

			self.pers["rank"] = 5;
			self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
			self.pers["am_ui_show_player_rank"] = self.pers["rank"];
			
			if(self.pers["rank"] != self.pers["old_rank"]) self thread NewRankAnimation();
			self.pers["old_rank"] = self.pers["rank"];
			
			old_score = self.score;
			
			if(game["am_gametype"] != "dm" && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headicon = "gfx/custom/hud@us_rank5.tga";
			if(game["am_use_player_class_system"] == 0 || game["am_show_rank_icons_in_highscore"] == 1) self.statusicon = "gfx/custom/hud@us_rank5.tga";
		}	
	
		// * wurde der Rank verändert, dann Team festlegen *
		if(game["am_gametype"] != "dm" && old_rank != self.pers["rank"] && isDefined(self.pers["team"]) && (self.pers["team"] == "allies" || self.pers["team"] == "axis") && level.drawfriend == 1 && !isDefined(self.bombAttached)) self.headiconteam = self.pers["team"];
	}
}

NewRankAnimation() {

	self endon("spawned");
 	self endon("disconnect");
	self endon("killed_player");
 
 	if(game["am_error_logfile"] == 1) logPrint("NewRankAnimation\n");

	
	wait 0.2;
	
	
	if(game["am_promotion_sound_next_rank"] == 1) {

		self thread AniBlinken();
		
		
		if(isDefined(self.pers["team"]) && isDefined(self.pers["rank"])) {
		
			team = self.pers["team"];
		
		
			wait 3; // * Warten wegen Soundausgabe DOM / Flag Captured *
		
			self playLocalSound("am_rank_up");	
			wait 3;			
		
			if(game[team] == "russian") 	self playLocalSound("am_rank_words_russian_" + self.pers["rank"]);	
			if(game[team] == "american") 	self playLocalSound("am_rank_words_american_" + self.pers["rank"]);	
			if(game[team] == "british") 	self playLocalSound("am_rank_words_british_" + self.pers["rank"]);	
			if(game[team] == "german") 		self playLocalSound("am_rank_words_german_" + self.pers["rank"]);	
		}
	}


	wait 2;

	self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
	self.pers["am_ui_show_player_rank"] = self.pers["rank"];
	
}


AniBlinken() {

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


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


	for(i=0;i<10;i++) {
	
		wait 0.5;
		self setClientCvar("am_ui_show_player_rank", "0");
		self.pers["am_ui_show_player_rank"] = 0;
		wait 0.5;
		self setClientCvar("am_ui_show_player_rank", self.pers["rank"]);
		self.pers["am_ui_show_player_rank"] = self.pers["rank"];
	}

}






ShowMissionIntroScreen(fadein, string1, string2, string3, pausetime1, pausetime2, timebeforefade, fadeout) {
		
    self notify("ShowMissionIntroScreen");
    self endon("ShowMissionIntroScreen");

    self endon("disconnect");


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

		
 	if(fadein > 0) {
 	
 		self deletePlayerHudElementByName("introscreen_black");
 		self createPlayerHudElement("introscreen_black", 0,0,"left","top","fullscreen","fullscreen",true,"black",640,480,1,0,0,0,0);
		
		self fadeOverPlayerHudElement("introscreen_black",fadein, 1);
	}


 	self deletePlayerHudElementByName("introscreen_black_t1");
 	self deletePlayerHudElementByName("introscreen_black_t2");
 	self deletePlayerHudElementByName("introscreen_black_t3");
 	self deletePlayerHudElementByName("introscreen_black_t4");
 	self deletePlayerHudElementByName("introscreen_black_t5");
	self createPlayerHudElement("introscreen_black_t1", 0,0,"left","top","fullscreen","fullscreen",true,"black",640,270,1,1,0,0,0);
	self createPlayerHudElement("introscreen_black_t2", 0,365,"left","top","fullscreen","fullscreen",true,"black",640,115,1,1,0,0,0);
	self createPlayerHudElement("introscreen_black_t3", 0,270,"left","top","fullscreen","fullscreen",false,"black",640,95,1,1,0,0,0);
	self createPlayerHudElement("introscreen_black_t4", 0,270,"left","top","fullscreen","fullscreen",true,"black",640,95,1,1,0,0,0);
	self createPlayerHudElement("introscreen_black_t5", 550,270,"left","top","fullscreen","fullscreen",true,"black",90,95,1,1,0,0,0);


 	self deletePlayerHudElementByName("introscreen_black");


	self freezeControls(true);
	wait .05;


	self thread fadeOverPlayerHudElement("introscreen_black_t4",6,0.2);


	level.introstring = [];
	
	
	if(isdefined(string1))			self introscreen_create_line(1,string1, 1.75 ,1.5);
	
	if(isdefined(pausetime1))		wait pausetime1;
	else							wait 2;	

	if(isdefined(string2))			self introscreen_create_line(2,string2, 1.3 ,1.5);
	
	if(isdefined(pausetime2))		wait pausetime1;
	else							wait 2;	

	if(isdefined(string3))			self introscreen_create_line(3,string3, 1.3 ,1.5);
	
	
	
	if(isdefined(timebeforefade))	wait timebeforefade;
	else							wait 3;




	self thread fadeOverPlayerHudElement("introscreen_black_t4",1.5,1);

	
	
	// Fade out text
	self thread introscreen_fadeOutText(1,1.5);
	self thread introscreen_fadeOutText(2,1.5);
	self thread introscreen_fadeOutText(3,1.5);


	wait 2;
	level notify("introscreen_fade_ende");
	wait 2;


 	self createPlayerHudElement("introscreen_black", 0,0,"left","top","fullscreen","fullscreen",true,"black",640,480,1,1,0,0,0);

 	self deletePlayerHudElementByName("introscreen_black_t1");
 	self deletePlayerHudElementByName("introscreen_black_t2");
 	self deletePlayerHudElementByName("introscreen_black_t3");
	self deletePlayerHudElementByName("introscreen_black_t4");
	self deletePlayerHudElementByName("introscreen_black_t5");



	self freezeControls(false);
	
	if(fadeout > 0) self fadeOverPlayerHudElement("introscreen_black",fadeout,0);
	
	
}

introscreen_create_line(nr,string, size, time) {

    self endon("disconnect");


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


	yPos = -150 + (nr * 30);
	
	if (level.xenon)
		yPos -= 60;


	self deletePlayerHudElementByName("introscreen_line_" + nr);    			
	self createPlayerTextHudElement("introscreen_line_" + nr, 0,ypos,"center","middle","center","middle",true,string,undefined,size,2,0,1,1,1);

	self fadeOverPlayerHudElement("introscreen_line_" + nr,time,1);

}

introscreen_fadeOutText(nr, time) {
	
    self endon("disconnect");

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


	self fadeOverPlayerHudElement("introscreen_line_" + nr,time,0);
	self deletePlayerHudElementByName("introscreen_line_" + nr);  	
}




ShowTickerText(team,mp_text,length,objective,fadein,fadeout) {

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


	if(team == "all") {


		level deleteLevelHudElementByName("submission_objective_background");
		level deleteLevelHudElementByName("submission_objective_star");
		level deleteLevelHudElementByName("submission_objective_ticker");
		level deleteLevelHudElementByName("submission_objective_text");    			


		level createLevelHudElement("submission_objective_background", 320,90,"center","middle","fullscreen","fullscreen",true,"black",640,20,1,0,1,1,1);
		level thread fadeOverLevelHudElement("submission_objective_background",fadein,1);

		if(objective) {

			level createLevelHudElement("submission_objective_star", 20,90,"center","middle","fullscreen","fullscreen",true,"objective",12,12,2,0,1,1,1);
			level thread fadeOverLevelHudElement("submission_objective_star",fadein,1);
		}



		wait 1.5;


		textpos = 30;

		if(!objective) textpos = 10;


		level createLevelHudElement("submission_objective_ticker", 640,90,"right","middle","fullscreen","fullscreen",true,"black",640-textpos,20,3,1,1,1,1);
		level createLevelTextHudElement("submission_objective_text", textpos,90,"left","middle","fullscreen","fullscreen",true,mp_text,undefined,1,2,1,0,1,0);




		laenge = length * 4;

		level thread scaleOverLevelHudElement("submission_objective_ticker",1.5,620-textpos-laenge,20);


		for(i=0;i<1.5;i+=0.05) {

			level thread maps\mp\gametypes\mm::playSoundOnPlayers("am_MM_ticker_sound");
			wait 0.05;
		}

		level deleteLevelHudElementByName("submission_objective_ticker");


		wait 6;


		level thread fadeOverLevelHudElement("submission_objective_background",fadeout,0);
		level thread fadeOverLevelHudElement("submission_objective_star",fadeout,0);		
		level thread fadeOverLevelHudElement("submission_objective_text",fadeout,0);	

		wait 0.1 + 2;

		level deleteLevelHudElementByName("submission_objective_background");
		level deleteLevelHudElementByName("submission_objective_star");    			
		level deleteLevelHudElementByName("submission_objective_text");    

	}
	else {
		
		wait 0.5; // etwas verzögern, denn wenn ein Spieler in Bombennähe stirbt ist der Background nicht mehr da.
		
		
		players = getentarray("player", "classname");

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

			if(isDefined(players[i].pers["team"]) && (players[i].pers["team"] == "allies" || players[i].pers["team"] == "axis") ) {

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

					players[i] thread ShowObjectiveTextPlayer(mp_text,length,objective,fadein,fadeout);	
				}				
			}
		}	
	}



}



ShowObjectiveTextPlayer(mp_text,length,objective,fadein,fadeout) {

    self notify("ShowObjectiveText");
    self endon("ShowObjectiveText");

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


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


	self deletePlayerHudElementByName("submission_objective_background");
	self deletePlayerHudElementByName("submission_objective_star");
	self deletePlayerHudElementByName("submission_objective_ticker");
	self deletePlayerHudElementByName("submission_objective_text");    			


	self createPlayerHudElement("submission_objective_background", 320,90,"center","middle","fullscreen","fullscreen",true,"black",640,20,1,0,1,1,1);
	self thread fadeOverPlayerHudElement("submission_objective_background",fadein,1);

	if(objective) {

		self createPlayerHudElement("submission_objective_star", 20,90,"center","middle","fullscreen","fullscreen",true,"objective",12,12,2,0,1,1,1);
		self thread fadeOverPlayerHudElement("submission_objective_star",fadein,1);
	}



	wait 3;


	textpos = 30;

	if(!objective) textpos = 10;


	self createPlayerHudElement("submission_objective_ticker", 640,90,"right","middle","fullscreen","fullscreen",true,"black",640-textpos,20,3,1,1,1,1);
	self createPlayerTextHudElement("submission_objective_text", textpos,90,"left","middle","fullscreen","fullscreen",true,mp_text,undefined,1,2,1,0,1,0);




	laenge = length * 4;

	self thread scaleOverPlayerHudElement("submission_objective_ticker",1.5,620-textpos-laenge,20);


	for(i=0;i<1.5;i+=0.05) {

		self playLocalSound("am_MM_ticker_sound");
		wait 0.05;
	}

	self deletePlayerHudElementByName("submission_objective_ticker");


	wait 6;


	self thread fadeOverPlayerHudElement("submission_objective_background",fadeout,0);
	self thread fadeOverPlayerHudElement("submission_objective_star",fadeout,0);		
	self thread fadeOverPlayerHudElement("submission_objective_text",fadeout,0);	

	wait 0.1 + 2;

	self deletePlayerHudElementByName("submission_objective_background");
	self deletePlayerHudElementByName("submission_objective_star");    			
	self deletePlayerHudElementByName("submission_objective_text");   			

}



showPlayerInfo(text) {

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

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

	
	self setClientCvar("am_ui_player_info_text", text);
	self.pers["am_ui_player_info_text"] = text;
}

deletePlayerInfo() {

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

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

	
	self setClientCvar("am_ui_player_info_text", " "); 		
	self.pers["am_ui_player_info_text"] = " ";
}


showWeaponPickupInfo(text) {

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

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

	
	self setClientCvar("am_ui_weapon_pickup_info_text", text);
	self.pers["am_ui_weapon_pickup_info_text"] = text;
}

deleteWeaponPickupInfo() {

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

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

	
	self setClientCvar("am_ui_weapon_pickup_info_text", " "); 
	self.pers["am_ui_weapon_pickup_info_text"] = " ";
}


showPlayerClass(class_name) {

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


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

	
	self iprintln(&"AM_MP_YOU_JOINED_CLASS", class_name);
}





createPlayerHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,foreground,shader,shader_width,shader_height,sort,alpha,color_r,color_g,color_b) {

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


	self endon("disconnect");


	if(!isDefined(self.hud)) self.hud = [];
	
	count = self.hud.size;

	self.hud[count] = newClientHudElem(self);
	self.hud[count].x = x;
	self.hud[count].y = y;
	self.hud[count].alignX = xAlign;
	self.hud[count].alignY = yAlign;
	self.hud[count].horzAlign = horzAlign;
	self.hud[count].vertAlign = vertAlign;
	self.hud[count].foreground = foreground;
	self.hud[count] setShader(shader, shader_width, shader_height);	
	self.hud[count].sort = sort;
	self.hud[count].alpha = alpha;
	self.hud[count].color = (color_r,color_g,color_b);
	
	self.hud[count].name 			= hud_element_name;
	self.hud[count].shader_name 	= shader;
	self.hud[count].shader_width 	= shader_width;
	self.hud[count].shader_height 	= shader_height;
	
	//logPrint("Create: " + hud_element_name + " " + count + "\n");
}

createPlayerTextHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,foreground,text,value,font_scale,sort,alpha,color_r,color_g,color_b) {

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


	if(!isDefined(self.hud)) self.hud = [];
	
	count = self.hud.size;

	self.hud[count] = newClientHudElem(self);
	self.hud[count].x = x;
	self.hud[count].y = y;
	self.hud[count].alignX = xAlign;
	self.hud[count].alignY = yAlign;
	self.hud[count].horzAlign = horzAlign;
	self.hud[count].vertAlign = vertAlign;
	self.hud[count].foreground = foreground;
	self.hud[count].sort = sort;
	self.hud[count].alpha = alpha;
	self.hud[count].color = (color_r,color_g,color_b);
	self.hud[count].fontScale = font_scale;
	
	if(isDefined(text)) 	self.hud[count] setText(text);  	
	if(isDefined(value)) 	self.hud[count] setValue(value);  	
    
	self.hud[count].name 		= hud_element_name;
	self.hud[count].font_scale 	= font_scale;	
	
}


createPlayerClockHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,width,height,foreground,sort,alpha,time,timeleft) {

	if(game["am_error_logfile"] == 1) logPrint("createPlayerClockHudElement\n");
	
	
	if(timeleft < 1 ) timeleft = 1;
	
	
	self endon("disconnect");


	if(!isDefined(self.hud)) self.hud = [];
	
	count = self.hud.size;

	self.hud[count] = newClientHudElem(self);
	self.hud[count].x = x;
	self.hud[count].y = y;
	self.hud[count].alignX = xAlign;
	self.hud[count].alignY = yAlign;
	self.hud[count].horzAlign = horzAlign;
	self.hud[count].vertAlign = vertAlign;
	self.hud[count].foreground = foreground;
	self.hud[count].sort = sort;
	self.hud[count].alpha = alpha;
	self.hud[count] setClock(timeleft, time, "hudStopwatch", width, height);
	    
	self.hud[count].name = hud_element_name;
	
}




createPlayerTimerHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,alpha,archived,font,font_scale,label,time) {

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


	self endon("disconnect");


	if(!isDefined(self.hud)) self.hud = [];
	
	count = self.hud.size;

	self.hud[count] = newClientHudElem(self);
	self.hud[count].x = x;
	self.hud[count].y = y;
	self.hud[count].alignX = xAlign;
	self.hud[count].alignY = yAlign;
	self.hud[count].horzAlign = horzAlign;
	self.hud[count].vertAlign = vertAlign;
	self.hud[count].alpha = alpha;
	self.hud[count].archived = archived;
	self.hud[count].font = font;
	self.hud[count].fontScale = font_scale;	
	if(isDefined(label)) self.hud[count].label = label;  	
	self.hud[count] setTimer(time);  
	
	self.hud[count].sort = 500;
	self.hud[count].foreground = false;
    
	self.hud[count].name 		= hud_element_name;
	self.hud[count].font_scale 	= font_scale;	
	
}

changePlayerTimerHudElementByName(hud_element_name,alpha) {

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


	self endon("disconnect");

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
				if(isDefined(self.hud[i])) self.hud[i].alpha = alpha;
				
				break;
			}
		}	
	}
}



deletePlayerHudElementsAll() {

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

	self endon("disconnect");


	if(isDefined(level.am_hud_is_deleting)) {
	
		while(isDefined(level.am_hud_is_deleting)) wait 0.1;
	}

	level.am_hud_is_deleting = true;


	// * Alle HUD-Elemente des Spielers entfernen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name)) {
					
				if(game["am_squads"] == 1 && isDefined(self.WaitingToSpawn) && self.hud[i].name == "squad_respawn_timer") continue;

				//logprint("Destroy: " + self.hud[i].name + " " + i + "\n");
				
				if(maps\mp\gametypes\_admiral_mod_utils::subStr(self.hud[i].name,0,11) != "introscreen") {

					self.hud[i] destroy();
					self.hud[i].name = undefined;			
				}
			}
		}	
		
		new_ar = [];
		
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name)) new_ar[new_ar.size] = self.hud[i];			
		}
		
		self.hud = [];		
		self.hud = new_ar;	
	}
	
	
	level.am_hud_is_deleting = undefined;

}


deletePlayerHudElementByName(hud_element_name) {

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


	self endon("disconnect");


	if(isDefined(level.am_hud_is_deleting)) {
	
		while(isDefined(level.am_hud_is_deleting)) wait 0.1;
	}

	level.am_hud_is_deleting = true;


	// * HUD-Element des Spielers entfernen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
			
				if(game["am_squads"] == 1 && isDefined(self.WaitingToSpawn) && self.hud[i].name == "squad_respawn_timer") continue;

				//logprint("Destroy: " + self.hud[i].name + " " + i + "\n");


				self.hud[i] destroy();
				self.hud[i].name = undefined;			
			}
		}
	
		
		new_ar = [];
		
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name)) new_ar[new_ar.size] = self.hud[i];			
		}
		
		self.hud = [];		
		self.hud = new_ar;	

	}
	
	level.am_hud_is_deleting = undefined;
	
}


getPlayerHudElementDataByName(hud_element_name) {

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


	self endon("disconnect");

	// * Alle HUD-Elemente des Spielers entfernen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
				//logPrint("GetWidth: " + self.hud[i].name + " " + i + "\n");
				
				data["shader"]  	= self.hud[i].shader_name;
				data["width"] 		= self.hud[i].shader_width;
				data["height"] 		= self.hud[i].shader_height;
				data["alpha"] 		= self.hud[i].alpha;
				data["color"] 		= self.hud[i].color;
				data["x"] 			= self.hud[i].x;
				data["y"] 			= self.hud[i].y;
				data["horzAlign"] 	= self.hud[i].horzAlign;
				data["vertAlign"] 	= self.hud[i].vertAlign;
				data["sort"] 		= self.hud[i].sort;

			
				return data;				
			}
		}
	}
}



changePlayerHudElementByName(hud_element_name,shader,shader_width,shader_height,alpha,color) {

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


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

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
				//logPrint("Change: " + self.hud[i].name + " Width: " + shader_width + "\n");
				
				if(shader_width < 1) 	shader_width = 0;
				if(shader_height < 1) 	shader_height = 0;
				
				if(isDefined(self.hud[i])) self.hud[i] setShader(shader, shader_width, shader_height);	
				if(isDefined(self.hud[i])) self.hud[i].alpha = alpha;
				if(isDefined(self.hud[i])) self.hud[i].color = color;
				
				break;
			}
		}	
	}
}

changePlayerHudElementAlphaByName(hud_element_name,alpha) {

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


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

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
						
				if(isDefined(self.hud[i])) self.hud[i].alpha = alpha;							
				break;
			}
		}	
	}
}


changePlayerHudElementTextByName(hud_element_name, text, color) {

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


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

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
						
				if(isDefined(self.hud[i])) self.hud[i] setText(text);	
				if(isDefined(self.hud[i])) self.hud[i].color = color;
							
				break;
			}
		}	
	}
}

changePlayerHudElementPositionByName(hud_element_name,x,y) {

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


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

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
				//logPrint("Change: " + self.hud[i].name + " Width: " + shader_width + "\n");
				
				if(x < 1) 	x = 0;
				if(y < 1) 	y = 0;
				
				if(isDefined(self.hud[i])) self.hud[i].x = x;
				if(isDefined(self.hud[i])) self.hud[i].y = y;
				
				break;
			}
		}	
	}
}



fadeOverPlayerHudElement(hud_element_name,time,alpha) {

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


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

	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
			 	if(isDefined(self.hud[i])) self.hud[i] fadeOverTime(time);
			 	if(isDefined(self.hud[i])) self.hud[i].alpha = alpha;
			 	
			 	wait time;
			 	break;
			}
		}
	}
}

scaleOverPlayerHudElement(hud_element_name,time,width,height) {

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


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


	// * Alle HUD-Elemente des Spielers durchsuchen *
	if(isDefined(self.hud) && self.hud.size > 0) {
	
		for(i=0;i<self.hud.size;i++) {
		
			if(isDefined(self.hud[i].name) && self.hud[i].name == hud_element_name) {
		
			 	if(isDefined(self.hud[i])) self.hud[i] scaleOverTime(time,width,height);
			 	
			 	wait time;
			 	break;
			 }
		}
	}
}



createLevelHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,foreground,shader,shader_width,shader_height,sort,alpha,color_r,color_g,color_b) {

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


	if(!isDefined(level.hud)) level.hud = [];
	
	count = level.hud.size;

	level.hud[count] = newHudElem();
	level.hud[count].x = x;
	level.hud[count].y = y;
	level.hud[count].alignX = xAlign;
	level.hud[count].alignY = yAlign;
	level.hud[count].horzAlign = horzAlign;
	level.hud[count].vertAlign = vertAlign;
	level.hud[count].foreground = foreground;
	level.hud[count] setShader(shader, shader_width, shader_height);	
	level.hud[count].sort = sort;
	level.hud[count].alpha = alpha;
	level.hud[count].color = (color_r,color_g,color_b);
	
	level.hud[count].name 			= hud_element_name;
	level.hud[count].shader_name 	= shader;
	level.hud[count].shader_width 	= shader_width;
	level.hud[count].shader_height 	= shader_height;
	
	
}


createLevelTextHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,foreground,text,value,font_scale,sort,alpha,color_r,color_g,color_b) {

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


	if(!isDefined(level.hud)) level.hud = [];
	
	count = level.hud.size;

	level.hud[count] = newHudElem();
	level.hud[count].x = x;
	level.hud[count].y = y;
	level.hud[count].alignX = xAlign;
	level.hud[count].alignY = yAlign;
	level.hud[count].horzAlign = horzAlign;
	level.hud[count].vertAlign = vertAlign;
	level.hud[count].foreground = foreground;
	level.hud[count].sort = sort;
	level.hud[count].alpha = alpha;
	level.hud[count].color = (color_r,color_g,color_b);
	level.hud[count].fontScale = font_scale;
	
	if(isDefined(text)) level.hud[count] setText(text);  	
	if(isDefined(value)) level.hud[count] setValue(value);  	
    
	level.hud[count].name 			= hud_element_name;
	level.hud[count].shader_text 	= text;
	level.hud[count].font_scale 	= font_scale;	
	
}

createLevelTimerHudElement(hud_element_name, x,y,xAlign,yAlign,horzAlign,vertAlign,archived,font,font_scale,sort,label,time,alpha,color_r,color_g,color_b) {

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


	if(!isDefined(level.hud)) level.hud = [];
	
	count = level.hud.size;

	level.hud[count] = newHudElem();
	level.hud[count].x = x;
	level.hud[count].y = y;
	level.hud[count].alignX = xAlign;
	level.hud[count].alignY = yAlign;
	level.hud[count].horzAlign = horzAlign;
	level.hud[count].vertAlign = vertAlign;
	level.hud[count].alpha = alpha;
	level.hud[count].archived = archived;
	level.hud[count].font = font;
	level.hud[count].fontScale = font_scale;
	level.hud[count].color = (color_r,color_g,color_b);
	level.hud[count].sort = sort;
	level.hud[count].label = label;  	
	level.hud[count] setTimer(time);  	
    
	level.hud[count].name = hud_element_name;
	level.hud[count].font_scale = font_scale;	
	
}

changeLevelHudElementByName(hud_element_name,alpha) {

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


	// * Alle HUD-Elemente des Levels durchsuchen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name) && level.hud[i].name == hud_element_name) {
														
 				if(isDefined(level.hud[i])) level.hud[i].alpha = alpha;
				
				break;
			}
		}	
	}
}

changeLevelTextHudElementByName(hud_element_name,text,value,font_size,alpha,color) {

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


	// * Alle HUD-Elemente des Levels durchsuchen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name) && level.hud[i].name == hud_element_name) {
						
				if(font_size < 0.1) 	font_size = 0;
				
				if(isDefined(level.hud[i]) && isDefined(text)) 	level.hud[i] setText(text);  	
				if(isDefined(level.hud[i]) && isDefined(value)) level.hud[i] setValue(value);  	
 
 				if(isDefined(level.hud[i])) level.hud[i].fontScale = font_size;
				if(isDefined(level.hud[i])) level.hud[i].alpha = alpha;
				if(isDefined(level.hud[i])) level.hud[i].color = color;
				
				break;
			}
		}	
	}
}


fadeOverLevelHudElement(hud_element_name,time,alpha) {

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



	// * Alle HUD-Elemente des Levels durchsuchen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name) && level.hud[i].name == hud_element_name) {
		
			 	if(isDefined(level.hud[i])) level.hud[i] fadeOverTime(time);
			 	if(isDefined(level.hud[i])) level.hud[i].alpha = alpha;
			 	
			 	wait time;
			 	break;
			}
		}
	}
}

scaleOverLevelHudElement(hud_element_name,time,width,height) {

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


	// * Alle HUD-Elemente des Levels durchsuchen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name) && level.hud[i].name == hud_element_name) {
		
			 	if(isDefined(level.hud[i])) level.hud[i] scaleOverTime(time,width,height);
			 	
			 	wait time;
			 	break;
			 }
		}
	}
}




deleteLevelHudElementByName(hud_element_name) {

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


	// * HUD-Elemente entfernen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name) && level.hud[i].name == hud_element_name) {
		
				
				level.hud[i] destroy();
				level.hud[i].name = undefined;
			}
		}
	
		
		new_ar = [];
		
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name)) new_ar[new_ar.size] = level.hud[i];			
		}
		
		level.hud = new_ar;
	}
}

deleteLevelHudElementAll() {

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


	// * HUD-Elemente entfernen *
	if(isDefined(level.hud) && level.hud.size > 0) {
	
		for(i=0;i<level.hud.size;i++) {
		
			if(isDefined(level.hud[i].name)) {
						
				level.hud[i] destroy();
				level.hud[i].name = undefined;
			}
		}

		level.hud = [];
	}
}




ShowHitFigur(state) {

	self endon("disconnect");

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

	
	self setClientCvar("am_ui_show_am_hit_figur", state);
	self.pers["am_ui_show_am_hit_figur"] = state;
		
}

