// * AdmiralMOD - Multiplayer Engine v1.0 by Matthias Lorenz 



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

	
	maps\mp\gametypes\_admiral_mod_xmission_pack::MissionPack();

	MissionEngineVars();
}


MissionEngineVars() {

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


	level.highscore_text 		= "^7Welcome to the Admiral^1MOD ^7Multiplayer Missions";
	level.highscore_text_allies = "^7Welcome to the Admiral^1MOD ^7Multiplayer Missions";
	level.highscore_text_axis 	= "^7Welcome to the Admiral^1MOD ^7Multiplayer Missions";


	level.mission_nr 			= 0;


	// * Sizes *
	level.mission_size 			= game["am_mission_map"].size;
	level.submission_size 		= game["am_mission_submissions"][level.mission_nr].size;


	// * Spawn erlauben *
	level.submission_spawn_allow = true;
	
	
	
	game["am_climbing"] = 0;
	game["am_show_team_score"] = 0;
	game["am_squads"] = 0;
	game["am_mortar_attacks"] = 0;
	game["am_max_turrets"] = 0;
		
}


SetMissionVars(mission_nr) {


	// * MOD-Mission-Vars *		
	if(game["am_spawntype"][mission_nr] == "boat") {
	
		game["am_boats"] 		= 1;
		game["am_parachute"] 	= 0;
	}
	else if(game["am_spawntype"][mission_nr] == "parachute") {
	
		game["am_boats"] 		= 0;
		game["am_parachute"] 	= 1;
	}
	else {
	
		game["am_boats"] 		= 0;
		game["am_parachute"] 	= 0;
	}		
}




MissionEnginePrecache() {


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


	// * Precache Elements (Attention: Gamestate < 15000 !!!) *

	// * Do not edit this lines *

	precacheString(game["am_mission_pack_name"]);
	precacheString(game["am_mission_pack_creator"]);
	precacheString(game["am_mission_pack_version"]);
	

	precacheString(&"AM_MP_MMISSION_GET_READY");
	precacheString(&"AM_MP_MMISSION_OBJECTIVE_COMPLETE");
	precacheString(&"AM_MP_MMISSION_OBJECTIVE_FAILED");
	
	precacheString(&"MP_ALLIESHAVEBEENELIMINATED");
	precacheString(&"MP_AXISHAVEBEENELIMINATED");
	precacheString(&"MP_TIMEHASEXPIRED");


	for(i=0;i<level.mission_size;i++) {

		precacheString(game["am_mission_title"][i]);
		precacheString(game["am_mission_subtitle"][i]);
		precacheString(game["am_mission_date"][i]);	


		submissions = game["am_mission_submissions"][i];
		
		for(ii=0;ii<submissions.size;ii++) {

			precacheString(submissions[ii]["order_text_allies"]);	
			precacheString(submissions[ii]["order_text_axis"]);
		}
	}

	precacheShader("gfx/custom/objective_star_light_yellow.tga");

	precacheModel("xmodel/german_artillery_flak88_aa_nm_static");
	precacheModel("xmodel/german_artillery_flak88_aa_nm_d_static");
	precacheModel("xmodel/prop_map_4_obj");

	precacheModel("xmodel/vehicle_panzer_ii_static");
	precacheModel("xmodel/vehicle_panzer_ii");
	precacheModel("xmodel/vehicle_panzer_ii_destroyed");

	precacheModel("xmodel/vehicle_american_sherman_static");
	precacheModel("xmodel/vehicle_american_sherman");
	precacheModel("xmodel/vehicle_american_sherman_d");

	precacheModel("xmodel/vehicle_tiger_woodland_static");
	precacheModel("xmodel/vehicle_tiger_woodland");
	precacheModel("xmodel/vehicle_tiger_woodland_d");


	
	precacheModel("xmodel/military_german_fieldradio_grey");	
	precacheModel("xmodel/military_german_fieldradio_grey_d");
	
	precacheModel("xmodel/prop_barrel_benzin");

	level._effect["bombexplosion"] 		= loadfx("fx/props/barrelexp.efx");
	level._effect["panzer_flash"] 		= loadfx("fx/muzzleflashes/panzer_flash.efx");
	level._effect["panzer_explosion"] 	= loadfx("fx/explosions/panzer_explosion.efx");


}



MissionEngineStart() {

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




	// * Wenn Test, dann hier bleiben *
	if(game["am_mission_pack_edit"] == true) {

		mission_nr = 0;
		level.submission_nr = 0;
	
		level.submission 				= [];
		level.submissions_mod_features 	= [];

		level.submission 				= game["am_mission_submissions"][mission_nr][level.submission_nr];
		level.submission_effects 		= game["am_mission_submissions_effects"][mission_nr][level.submission_nr];
		level.submission_bombs 			= game["am_mission_submissions_bombs"][mission_nr][level.submission_nr];
		level.submission_mod_features 	= game["am_mission_submissions_modfeatures"][mission_nr][level.submission_nr];
		level.submission_bots_allies 	= game["am_mission_submissions_bots_allies"][mission_nr][level.submission_nr];
		level.submission_bots_axis 		= game["am_mission_submissions_bots_axis"][mission_nr][level.submission_nr];


		// * nur zu Testzwecken *
		thread PlayEffects();
		
	
		while(1) {
				
			wait 5;
		}	
	}
	



	// * Warten bis mindestens 2 Spieler auf dem Spielfeld sind *
		
	teams_komplett = false;
	while(!teams_komplett) {

		teams_komplett = CheckPlayerCountEachTeam();

		wait 1;
	}


	SetMissionVars(level.mission_nr);
	

	// * Alle toten Spieler wieder respawnen (für Mission-Intro) *
	level.spawnpoint_allies		= undefined;
	level.spawnpoint_axis		= undefined;

	SpawnAllPlayers();
	

	wait 1;	
	
	
		

	// * Load next Mission Map *		
	CheckLoadMissionMap();	



	zeit = 30; // * 30 Sekunden *

	// * Auf alle Spieler warten *
	waittimer = newHudElem();
	waittimer.x = 288;
	waittimer.y = 208;
	waittimer.horzAlign = "left";
	waittimer.vertAlign = "top";
	waittimer setClock(zeit, 60, "hudStopwatch", 64, 64);

	wait zeit;

	if(isDefined(waittimer)) waittimer destroy();



	// * Missions Ticker Text *
	wait 1;
	
	if(game["am_use_player_class_system"] == 1) iprintlnbold(&"AM_MP_SELECT_YOUR_PLAYER_CLASS");
	else 										iprintlnbold(&"AM_MP_SELECT_YOUR_WEAPON");
	wait 8;


	maps\mp\gametypes\_admiral_mod_hud::ShowTickerText("all",&"AM_MP_MMISSION_GET_READY",28,false,1,2);


	

	// * Nach dem Ticker kein Spawn mehr erlauben... da Spieler sonst keinen dunklen Screen sieht *
	level.submission_spawn_allow = undefined;

	
	level notify("mission_start");
	
	wait 2;
	
	
	// * Mission *
	SwitchToMission(level.mission_nr);
}



CheckLoadMissionMap() {

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


	if(game["am_mission_map"][level.mission_nr] != game["am_mapname"]) {
	
			
		if(level.mission_nr > 0) SaveMissionDatas();
		
		wait 2;
		
	
		iprintlnbold(&"AM_MP_MAPCHANGE_FOR_MISSIONSTART");
		wait 8;
	
	
   		map =  "gametype mm map " + game["am_mission_map"][level.mission_nr];
   
    	setcvar("sv_maprotationcurrent",map);
	
		exitLevel(false);
	}
}




SwitchToMission(mission_nr) {

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


	level notify("StartMission");



	// * Wenn Mission Pack startet denn Info anzeigen *
	if(mission_nr == 0) {

		// * Welcome Info *	

		mission_title 		= game["am_mission_pack_name"];
		mission_subtitle 	= game["am_mission_pack_creator"];
		mission_date 		= game["am_mission_pack_version"];

		
		// * allen Spielern den Missionsstart anzeigen (ShowMissionIntroScreen) *
		players = getentarray("player", "classname");

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

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

				players[i] thread maps\mp\gametypes\_admiral_mod_hud::ShowMissionIntroScreen(2,mission_title, mission_subtitle, mission_date, 2, 2, 2, 0);
			}
		}	
	
		wait 15;
	}
	
		

	mission_title 		= game["am_mission_title"][mission_nr];
	mission_subtitle 	= game["am_mission_subtitle"][mission_nr];
	mission_date 		= game["am_mission_date"][mission_nr];
	mission_text 		= game["am_mission_text"][mission_nr];
	mission_max_time	= game["am_mission_max_time"][mission_nr];


	fadein = 2;

	// * allen Spielern den Missionsstart anzeigen (ShowMissionIntroScreen) *
	players = getentarray("player", "classname");

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

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

			if(mission_nr == 0) players[i] thread maps\mp\gametypes\_admiral_mod_hud::ShowMissionIntroScreen(0,mission_title, mission_subtitle, mission_date, 2, 2, 10, 3);
			else 				players[i] thread maps\mp\gametypes\_admiral_mod_hud::ShowMissionIntroScreen(fadein,mission_title, mission_subtitle, mission_date, 2, 2, 10, 3);
		}
	}


	
		
	musicplay("am_MM_intro");


	
	// * Missionstext-Box füllen *
	if(mission_nr > 0)  wait (0.1 + fadein);
	
	for(i=0;i<players.size;i++) {

		if(players[i].sessionstate == "playing") {
			
			players[i] setClientCvar("am_ui_mm_mission_text", mission_text);
		}
	}





	level waittill("introscreen_fade_ende");


	players = getentarray("player", "classname");
	for(i=0;i<players.size;i++) {

		players[i] setClientCvar("am_ui_mm_mission_text", " ");			
	}



	// * Mission-Time *
	thread ShowMissionTime(mission_max_time);


	StartSubMissions(mission_nr);
	
}




StartSubMissions(mission_nr) {


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


	level endon("StartMission");
	
	level notify("StartSubmission");

	
	level.submission_nr = 0;



	while(level.submission_nr < level.submission_size) {

		
		level.bomb_planted 		= undefined;
		level.bomb_defused 		= undefined;
		level.bomb_destroyed 	= undefined;



		level.submission 				= [];
		level.submissions_mod_features 	= [];

		level.submission 				= game["am_mission_submissions"][mission_nr][level.submission_nr];
		level.submission_effects 		= game["am_mission_submissions_effects"][mission_nr][level.submission_nr];
		level.submission_bombs 			= game["am_mission_submissions_bombs"][mission_nr][level.submission_nr];
		level.submission_mod_features 	= game["am_mission_submissions_modfeatures"][mission_nr][level.submission_nr];
		level.submission_bots_allies 	= game["am_mission_submissions_bots_allies"][mission_nr][level.submission_nr];
		level.submission_bots_axis 		= game["am_mission_submissions_bots_axis"][mission_nr][level.submission_nr];



	
		// * Wenn in jedem Team nicht mindestens 1 Spieler, dann nächste Submission noch nicht starten *		
		if(!CheckPlayerCountEachTeam()) iprintlnbold(&"AM_MP_EACH_TEAM_ONE_PLAYER");
		
		teams_komplett = false;
		while(!teams_komplett) {
								
			teams_komplett = CheckPlayerCountEachTeam();
			
			wait 1;
		}

		

		// * Sub-Mission-Time *
		thread ShowSubMissionTime(level.submission["submission_time"]);



		// * Spawnpoints *
		level.spawnpoint_allies		= level.submission["spawn_pos_allies"];
		level.spawnpoint_axis		= level.submission["spawn_pos_axis"];


		// * Mission Mod-Features aktivieren *
		SetMissionMODFeatures();

		
		// * Spawn erlauben *
		level.submission_spawn_allow = true;


		// * PlayerSpawen *
		if(level.submission_nr == 0) 	SpawnAllPlayers();
		else							SpawnAllPlayersSubmission();


		// * Während der Submission Spawn verbieten *
		level.submission_spawn_allow = undefined;


		// * Submission *
		level.submission_is_runnning = true;

		

	
		// * SubMission Objective anzeigen *
		thread ShowSubmissionObjective();

		
		// * Submission-Ziel im Highscore Objective Text anzeigen *
		level.highscore_text_allies = level.submission["highscore_text_allies"];
		level.highscore_text_axis 	= level.submission["highscore_text_axis"];
		
		ChangeHighscoreText();
		
		
		
			

		// * Bomben platzieren *
		thread PlaceBombs();
		

		// * Effekte Abspielen *
		thread PlayEffects();

				

		// * BattleChatter SubMission Sound *
		thread PlayGoingSounds();


		level.submission["done"] = 0;



		// * Alle Verteidigungs-Bots Spawnen *
		if(isDefined(level.submission_bots_allies)) thread SpawnAlliesAutomaticBots();
		if(isDefined(level.submission_bots_axis)) 	thread SpawnAxisAutomaticBots();
 
	
	

		wait 1;
		
		// * Check ob Submission erfolgreich (+ Zeitbegrenzung) *
		SubmissionChecks();


		wait 3;

		// * Text-Submission-Ziel anzeigen *
		maps\mp\gametypes\_admiral_mod_hud::ShowTickerText("allies",level.submission["order_text_allies"],level.submission["highscore_text_allies"].size,true,2,2);	
		maps\mp\gametypes\_admiral_mod_hud::ShowTickerText("axis",level.submission["order_text_axis"],level.submission["highscore_text_axis"].size,true,2,2);	



	
		level waittill("submission_end");
		
		level.submission_is_runnning = undefined;
		
		
		maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("submission_timer");
		
		
		
		
		if(level.submission["done"] == 1) {
			
			maps\mp\gametypes\_admiral_mod_hud::ShowTickerText(level.submission["order_for"],&"AM_MP_MMISSION_OBJECTIVE_COMPLETE",24,false,1,1);
			maps\mp\gametypes\_admiral_mod_hud::ShowTickerText(GetOtherTeam(level.submission["order_for"]),&"AM_MP_MMISSION_OBJECTIVE_FAILED",24,false,1,1);
		
			if(level.submission["order_for"] == "allies") {
			
				level.highscore_text_allies = "^2Mission objective complete";
				level.highscore_text_axis 	= "^1Mission objective failed";
				
				teamscore = getTeamScore("allies");
				teamscore++;
				setTeamScore("allies", teamscore);		
				
			}
			else {
			
				level.highscore_text_axis 	= "^2Mission objective complete";
				level.highscore_text_allies	= "^1Mission objective failed";			
			
				teamscore = getTeamScore("axis");
				teamscore++;
				setTeamScore("axis", teamscore);	
			}

			ChangeHighscoreText();
		}
		else {
		
			maps\mp\gametypes\_admiral_mod_hud::ShowTickerText(level.submission["order_for"],&"AM_MP_MMISSION_OBJECTIVE_FAILED",22,false,1,1);
			maps\mp\gametypes\_admiral_mod_hud::ShowTickerText(GetOtherTeam(level.submission["order_for"]),&"AM_MP_MMISSION_OBJECTIVE_COMPLETE",22,false,1,1);
			
			if(level.submission["order_for"] == "axis") {
			
				level.highscore_text_allies = "^2Mission objective complete";
				level.highscore_text_axis 	= "^1Mission objective failed";
			
				teamscore = getTeamScore("allies");
				teamscore++;
				setTeamScore("allies", teamscore);	
			}
			else {
			
				level.highscore_text_axis 	= "^2Mission objective complete";
				level.highscore_text_allies	= "^1Mission objective failed";		
				
				teamscore = getTeamScore("axis");
				teamscore++;
				setTeamScore("axis", teamscore);
			}
			
			ChangeHighscoreText();

		}					
		
				
		// * auf den Ticker warten *
		wait 12;
				
		
		// * Nur wenn Submission erfolgreich, dann weiter * 
		if(level.submission["done"] == 1) 	level.submission_nr++;	
		else 								iprintlnbold("Submission Replay");
				
	}


	// * Wenn alle Submissions gespielt *

	maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("mission_timer");
		

	wait 3;

	game["mission_done"][level.mission_nr] = 1;
	
	iprintlnbold(&"AM_MP_MMISSION_COMPLETE");

	musicstop();	
	musicplay("am_MM_victory");	
	wait 20;




	// * Nächste Mission *	

	level.mission_nr++; 
	
	
	// * Noch nicht alle Missionen gespielt ? *
	if(level.mission_nr < level.mission_size) {
	

		iprintlnbold(&"AM_MP_MMISSION_LOAD");	
		wait 16;
		
		// * Check ob nächste Mission auf anderer Map, wenn ja laden *	
		CheckLoadMissionMap();	
		
		
		// * Wenn nächste Mission auf gleicher Map dann weiter *
		SwitchToMission(level.mission_nr);
		
	}
	else  {
	
	
	
		// * Wenn alle Missionen gespielt *

		level notify("mission_end");

		KickAllAutomaticBots();


	
		maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("mission_timer");
		
	 
		iprintlnbold(&"AM_MP_MMISSION_ALL_PLAYED");	
		wait 5;
		
		
		// * Team-Player Winner Satz *
		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"] == level.submission["order_for"]) {

				ku = GetTeamKuerzel(level.submission["order_for"]);

				players[i] playlocalsound("am_win_" + ku);				
			}
		}
		
		
		// * Tabelle aller Missionen anzeigen *
		wait 5;
		maps\mp\gametypes\mm::endMap();
		
						
		wait 1;
		
		// * Missionen neu starten (Map von MissionPack initialisieren und dann Map Neustart) *
		
		MissionEngineInit();
		
		map =  "gametype mm map " + game["am_mission_map"][level.mission_nr];		   
		setcvar("sv_maprotationcurrent",map);
			
		exitLevel(false);
		
	
			
	}


}


SpawnAlliesAutomaticBots() {

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

		position 	= level.submission_bots_allies["position"][i];
		weapon 		= level.submission_bots_allies["weapon"][i];
		skill 		= level.submission_bots_allies["skill"][i];		

		bot_player = GetFreeSpectatorAutomaticBot();
		if(!isDefined(bot_player)) bot_player = addtestclient();

		// * Wenn Bot erzeugt werden konnte *
		if(isDefined(bot_player)) bot_player thread maps\mp\gametypes\_teams::AutomaticPlayer("allies", position, weapon, skill);		
	}	
}	
		
SpawnAxisAutomaticBots() {
	
	for(i=0;i<level.submission_bots_axis.size;i++) {

		position 	= level.submission_bots_axis["position"][i];
		weapon 		= level.submission_bots_axis["weapon"][i];
		skill 		= level.submission_bots_axis["skill"][i];		

		bot_player = GetFreeSpectatorAutomaticBot();
		if(!isDefined(bot_player)) bot_player = addtestclient();

		// * Wenn Bot erzeugt werden konnte *
		if(isDefined(bot_player)) bot_player thread maps\mp\gametypes\_teams::AutomaticPlayer("axis", position, weapon, skill);			
	}	
	
}


GetFreeSpectatorAutomaticBot() {

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

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

		if(isDefined(players[i].pers["imabot_automatic"]) && isDefined(players[i].pers["team"]) && players[i].pers["team"] == "spectator") return players[i];			
	}
}



KickAllAutomaticBots() {

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

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

		//if(isDefined(players[i].pers["imabot_automatic"])) players[i] openMenu("kick_player"); 		
	}
}







DeleteAllEntitys() {

	/*
	entitytypes = getentarray();
	for(i = 0; i < entitytypes.size; i++)
	{
		if(isdefined(entitytypes[i])) entitytypes[i] delete();
	}
	*/
}




CheckPlayerCountEachTeam() {

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

	
	allies 	= 0;
	axis 	= 0;
	
	
	players = getentarray("player", "classname");

	mind_one_player = false;

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

		if(isDefined(players[i].pers["imabot"]) || isDefined(players[i].pers["imabot_automatic"])) {
		
		}
		else mind_one_player = true;
				
		if(isDefined(players[i].pers["team"])) {

			if(players[i].pers["team"] == "allies") allies++;
			if(players[i].pers["team"] == "axis") 	axis++;
		}
	}
	 
	
	if(allies > 0 && axis > 0 && mind_one_player == true) return true;
	
	return false;

}



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


	if(isDefined(level.submission_mod_features["sprinting"]) && level.submission_mod_features["sprinting"] > 0)	{
					
		game["am_player_sprinting"] = 1;
	}
	else game["am_player_sprinting"] = 0;
	
	if(isDefined(level.submission_mod_features["climbing"]) && level.submission_mod_features["climbing"] > 0)	{
					
		game["am_climbing"] = 1;
	}
	else game["am_climbing"] = 0;
	
	if(isDefined(level.submission_mod_features["spawn_protection"]) && level.submission_mod_features["spawn_protection"] > 0)	{
					
		game["am_player_spawn_protect"] = 1;
	}
	else game["am_player_spawn_protect"] = 0;

}




ShowSubmissionObjective() {

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


	wait 2; // * Warten auf den Ticker text *

	// empty, invisible, current

	objective_delete(0);
	
	objective_add(0, "current", level.submission["position"],"objective");
	objective_team(0, "none");
	
	
	thread SubMissionObjectiveAnimation();
	
	
	level waittill("submission_end");
	
	objective_delete(0);	
	
}


SubMissionObjectiveAnimation() {

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


	level endon("StartMission");
	level endon("StartSubmission");


	level endon("submission_end");

	i = 0;

	while(1) {
	
		objective_icon(0, "gfx/custom/objective_star_light_yellow.tga");   
		
		wait 0.5;
	
		objective_icon(0, "objective");   
		wait 0.5;		
		
		
		i++;
		if(i == 20) break;
	}		
}


ChangeHighscoreText() {

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


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

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

		if(players[i].sessionstate == "playing") {
		
			if(isDefined(players[i].pers["team"]) && players[i].pers["team"] == "allies") 	{
			
				players[i] setClientCvar("cg_objectiveText", &"AM_MP_MMISSION_OBJECTIVE_TEXT",level.highscore_text_allies);
			}			
			else if(isDefined(players[i].pers["team"]) && players[i].pers["team"] == "axis") 	{
			
				players[i] setClientCvar("cg_objectiveText", &"AM_MP_MMISSION_OBJECTIVE_TEXT",level.highscore_text_axis);
			}			
			else {
						
				players[i] setClientCvar("cg_objectiveText", &"AM_MP_MMISSION_OBJECTIVE_TEXT",level.highscore_text);
			}
		}
	}	

}





PlayGoingSounds() {

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


	wait 3; // * Warten bis der Bildschirm wieder da ist *


	ku = "";

	playing_players = 0;

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

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

		if(players[i].sessionstate == "playing" && isDefined(players[i].pers["team"])) {
		
			if(players[i].pers["team"] == level.submission["order_for"]) 	{
			
				ku = GetTeamKuerzel(players[i].pers["team"]);
			
				players[i] playlocalsound("am_verteidigen_" + ku);	
				//players[i] playlocalsound("am_angreifen_" + ku);	
			}
			else {			
			
				ku = GetTeamKuerzel(players[i].pers["team"]);
			
				//players[i] playlocalsound("am_verteidigen_" + ku);	
				players[i] playlocalsound("am_angreifen_" + ku);	
			}
		}
	}
}






SubmissionChecks() {

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


	if(level.submission["order"] == "unit_reach_point") 	thread CheckReachedPosition();
	if(level.submission["order"] == "defend_position") 		thread CheckDefendPosition();
	if(level.submission["order"] == "attack_position") 		thread CheckAttackPosition();
	
	if(level.submission["order"] == "destroy_turret") 		thread CheckBombDestroyed("turret");
	if(level.submission["order"] == "destroy_barrels") 		thread CheckBombDestroyed("barrels");
	if(level.submission["order"] == "destroy_radio") 		thread CheckBombDestroyed("radio");
	if(level.submission["order"] == "get_document") 		thread CheckGotDocument();

}




CheckAttackPosition() {

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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");

	wait 5; // * Auf den Ticker warten, dann kommt erst das waittill("submission_end") *
	
	
	order_team 	= level.submission["order_for"];	
	other_team 	= GetOtherTeam(level.submission["order_for"]);
	

	while(1) {
	
		other_player_in_target_range	= 0;
		other_player_alive_count 		= 0;
		order_player_alive_count 		= 0;


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

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

			if(isDefined(players[i].pers["team"])) {
				
				if(players[i].pers["team"] == other_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) {
					
						// * zählen wieviele Verteidiger noch am Leben *
						other_player_alive_count++;
				
						// * zählen wieviele Verteidiger noch am Ort *
						if(distance(players[i].origin,level.submission["position"]) <= level.submission["radius"]) other_player_in_target_range++;			
					}
				}

				// * zählen wieviele Angreifer noch am Leben *
				if(players[i].pers["team"] == order_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) order_player_alive_count++;					
				}
			}
		}
		

		// * Wenn alle Angreifer Tod dann Submission gescheitert *
		if(order_player_alive_count == 0)  {
		
			if(order_team == "allies") {
			
				wait 2;
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
				
				wait 2;
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}


			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;		
		}

		
		// * Wenn alle Verteidiger Tod dann Submission erfolgreich *
		if(other_player_alive_count == 0)  {
		

			if(other_team == "allies") {
			
				wait 2;
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
			
				wait 2;
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}
			
			level.submission["done"] = 1;	
			level notify("submission_end");

			break;		
		}


		// * Wenn keiner der Verteitiger mehr in Range, dann Submission erfolgreich *
		if(other_player_in_target_range == 0)  {
		
			if(other_team == "allies") 	iprintlnbold(&"AM_MP_MMISSION_ALLIES_AWAY");
			else						iprintlnbold(&"AM_MP_MMISSION_AXIS_AWAY");
		
			level.submission["done"] = 1;	
			level notify("submission_end");
			break;
		}


		
		wait 1;
	}
}



CheckDefendPosition() {

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


	level endon("StartMission");
	level endon("StartSubmission");
	
	level endon("submission_end");
	
	wait 5; // * Auf den Ticker warten, dann kommt erst das waittill("submission_end") *
	
	
	order_team 	= level.submission["order_for"];	
	other_team 	= GetOtherTeam(level.submission["order_for"]);
	

	while(1) {
	
		order_player_in_target_range	= 0;
		order_player_alive_count 		= 0;
		other_player_alive_count 		= 0;


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

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

			if(isDefined(players[i].pers["team"])) {
				
				if(players[i].pers["team"] == order_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) {
					
						// * zählen wieviele Verteidiger noch am Leben *
						order_player_alive_count++;
				
						// * zählen wieviele Verteidiger noch am Ort *
						if(distance(players[i].origin,level.submission["position"]) <= level.submission["radius"]) order_player_in_target_range++;			
					}
				}

				// * zählen wieviele Angreifer noch am Leben *
				if(players[i].pers["team"] == other_team && !isDefined(players[i].pers["imabot_automatic"])) {
				
					if(players[i].sessionstate == "playing") other_player_alive_count++;					
				}
			}
		}
		

		// * Wenn alle Angreifer Tod dann Submission erfolgreich *
		if(other_player_alive_count == 0)  {
		
			
			if(other_team == "allies") {
			
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
			
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}

			level.submission["done"] = 1;	
			level notify("submission_end");

			
			break;		
		}

		
		
		// * Wenn alle Verteidiger Tod dann Submission gescheitert *
		if(order_player_alive_count == 0)  {
		
			if(order_team == "allies") {
			
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
			
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}


			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;		
		}
		
		
		// * Wenn keiner der Verteitiger mehr in Range, dann Submission gescheitert *
		if(order_player_in_target_range == 0)  {
		
			if(order_team == "allies") 	iprintlnbold(&"AM_MP_MMISSION_ALLIES_AWAY");
			else						iprintlnbold(&"AM_MP_MMISSION_AXIS_AWAY");

			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;
		}
		
		
		wait 1;
	}
}



CheckReachedPosition() {

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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");

	wait 5; // * Auf den Ticker warten, dann kommt erst das waittill("submission_end") *
	
	
	order_team 	= level.submission["order_for"];	
	other_team 	= GetOtherTeam(level.submission["order_for"]);


	while(1) {
	
		order_player_alive_count 		= 0;
		order_player_in_target_range 	= -1; // * für: wenn 0 Player in diesem Team *


		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"] == order_team && !isDefined(players[i].pers["imabot_automatic"])) {

				order_player_alive_count++;
				
				if(distance(players[i].origin,level.submission["position"]) <= level.submission["radius"]) {
					
					if(order_player_in_target_range == -1) order_player_in_target_range = 0;
					order_player_in_target_range++;
				}
			
			}
		}
		
		// * Wenn alle am Ziel dann Submission erfolgreich *
		if(order_player_alive_count == order_player_in_target_range)  {
		
			level.submission["done"] = 1;	
			level notify("submission_end");
			
			break;		
		}
		
		
		// * Wenn alle Tod dann Submission gescheitert *
		if(order_player_alive_count == 0)  {
		
			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;		
		}		
		
		wait 1;
	}
}




CheckBombDestroyed(model) {

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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");

		
	order_team 	= level.submission["order_for"];	
	other_team 	= GetOtherTeam(level.submission["order_for"]);


	ActivateBombZone(model);
	
	
	wait 2;
	
	
	while(1) {
	
		
		order_player_in_target_range	= 0;
		order_player_alive_count 		= 0;
		other_player_alive_count 		= 0;


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

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

			if(isDefined(players[i].pers["team"])) {
				
				if(players[i].pers["team"] == order_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) {
					
						// * zählen wieviele Verteidiger noch am Leben *
						order_player_alive_count++;
				
						// * zählen wieviele Verteidiger noch am Ort *
						if(distance(players[i].origin,level.submission["position"]) <= level.submission["radius"]) order_player_in_target_range++;			
					}
				}

				// * zählen wieviele Angreifer noch am Leben *
				if(players[i].pers["team"] == other_team && !isDefined(players[i].pers["imabot_automatic"])) {
				
					if(players[i].sessionstate == "playing") other_player_alive_count++;					
				}
			}
		}
		

		// * Wenn alle Angreifer Tod dann Submission erfolgreich *
		if(other_player_alive_count == 0)  {
		
		
			if(other_team == "allies") {
			
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
			
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}

			level.submission["done"] = 1;	
			level notify("submission_end");

			
			break;		
		}
		

		
		
		// * Wenn alle Verteidiger Tod und Bombe noch nicht gelegt dann Submission gescheitert *
		if(order_player_alive_count == 0 && !isDefined(level.bomb_planted))  {
		
			if(order_team == "allies") {
			
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
			
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}
			
			level.submission["done"] = 0;	
			level notify("submission_end");

			break;		
		}
		
		
		
		// * Wenn Turret zerstört, dann Submission erfolgreich *		
		if(isDefined(level.bomb_destroyed))  {
		
			level.submission["done"] = 1;	
			level notify("submission_end");
			
			break;		
		}
		
		
		// * Wenn Turret-Bomb defused dann Submission gescheitert *
		if(isDefined(level.bomb_defused))  {
		
			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;		
		}		
		
		
		
		wait 1;
	}	

}



CheckGotDocument() {


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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");

	
	
	
	order_team 	= level.submission["order_for"];	
	other_team 	= GetOtherTeam(level.submission["order_for"]);

	if(isDefined(level.DocumentObject)) level.DocumentObject delete();

	level.DocumentObject = spawn("script_model", level.submission["position"]);
	level.DocumentObject.angles = level.submission["angles"];
	level.DocumentObject setmodel("xmodel/prop_map_4_obj");


	wait 2;

	
	level.DocumentObject thread DocumentThink(order_team);


	while(1) {
	
		other_player_in_target_range	= 0;
		other_player_alive_count 		= 0;
		order_player_alive_count 		= 0;



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

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

			if(isDefined(players[i].pers["team"])) {
				
				if(players[i].pers["team"] == other_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) {
					
						// * zählen wieviele Verteidiger noch am Leben *
						other_player_alive_count++;
				
						// * zählen wieviele Verteidiger noch am Ort *
						if(distance(players[i].origin,level.submission["position"]) <= level.submission["radius"]) other_player_in_target_range++;			
					}
				}

				// * zählen wieviele Angreifer noch am Leben *
				if(players[i].pers["team"] == order_team) {
				
					if(players[i].sessionstate == "playing" && !isDefined(players[i].pers["imabot_automatic"])) order_player_alive_count++;					
				}
			}
		}
		

		// * Wenn alle Angreifer Tod dann Submission gescheitert *
		if(order_player_alive_count == 0)  {
		
			if(order_team == "allies") {
			
				wait 2;
				iprintlnbold(&"MP_ALLIESHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_allieselim");
			}
			else {
				
				wait 2;
				iprintlnbold(&"MP_AXISHAVEBEENELIMINATED");
				level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_axiselim");			
			}


			level.submission["done"] = 0;	
			level notify("submission_end");
			
			break;		
		}



		wait 1;
	}






}


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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");


	while(isDefined(self) && isDefined(level.submission_is_runnning))
	{
		other = undefined;
		
		team = level.submission["order_for"];		
		other = maps\mp\gametypes\_admiral_mod_player::WaitForUseObject(self, team, self.origin, 60, 20, "@AM_MP_LNG_PRESS_USE_TO_GET_DOCUMENTS");
						
		if(isDefined(self) && isDefined(level.submission_is_runnning))
		{
						
			// *  Dokumente an sich genommen *	
			self playsound("paper_grab", self.origin);
			wait .4;

			self delete();

			level.submission["done"] = 1;	
			level notify("submission_end");		

			
			break;				
		}
	}	
}



ActivateBombZone(model) {

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


	if(isDefined(level.BombObject)) level.BombObject delete();
	if(isDefined(level.BombObject2)) level.BombObject2 delete();
	if(isDefined(level.BombObject3)) level.BombObject3 delete();
	if(isDefined(level.BombObject4)) level.BombObject4 delete();


	if(model == "turret") {

		level.BombObject = spawn("script_model", level.submission["position"]);
		level.BombObject.angles = level.submission["angles"];
		level.BombObject setmodel("xmodel/german_artillery_flak88_aa_nm_static");
		
		level.BombObject.isTurret = true;
	}
	
	if(model == "barrels") {

		level.BombObject = spawn("script_model", level.submission["position"]);
		level.BombObject.angles = level.submission["angles"];
		level.BombObject setmodel("xmodel/prop_barrel_benzin");
		
		level.BombObject2 = spawn("script_model", level.submission["position"] + (-30,20,30));
		level.BombObject2.angles = level.submission["angles"];
		level.BombObject2 setmodel("xmodel/prop_barrel_benzin");
		level.BombObject2.origin = maps\mp\gametypes\_admiral_mod_utils::getGround(level.BombObject2.origin);
				
		level.BombObject3 = spawn("script_model", level.submission["position"] + (45,10,30));
		level.BombObject3.angles = level.submission["angles"];
		level.BombObject3 setmodel("xmodel/prop_barrel_benzin");
		level.BombObject3.origin = maps\mp\gametypes\_admiral_mod_utils::getGround(level.BombObject3.origin);
		
		level.BombObject4 = spawn("script_model", level.submission["position"] + (10,-35,30));
		level.BombObject4.angles = level.submission["angles"];
		level.BombObject4 setmodel("xmodel/prop_barrel_benzin");
		level.BombObject4.origin = maps\mp\gametypes\_admiral_mod_utils::getGround(level.BombObject4.origin);
		
		level.BombObject.isBarrels = true;
	}
	
	if(model == "radio") {

		level.BombObject = spawn("script_model", level.submission["position"]);
		level.BombObject.angles = level.submission["angles"];
		level.BombObject setmodel("xmodel/military_german_fieldradio_grey");
		
		level.BombObject.isRadio = true;
	}
	
	
	
	level.BombObject thread BombzoneThink(model);
}


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


	level endon("StartMission");
	level endon("StartSubmission");


	level endon("bomb_planted");
	

	level.barsize = 192;

	level.planttime = 5;		// seconds to plant a bomb
	level.defusetime = 10;		// seconds to defuse a bomb


	level.barincrement = (level.barsize / (20.0 * level.planttime));

	level.bomb_planted 		= undefined;
	level.bomb_defused 		= undefined;
	level.bomb_destroyed 	= undefined;
	


	while(isDefined(self) && isDefined(level.submission_is_runnning))
	{
		other = undefined;
		
		team = level.submission["order_for"];		
		other = maps\mp\gametypes\_admiral_mod_player::WaitForUseObject(self, team, self.origin, 120, 50, "@AM_MP_LNG_PRESS_USE_TO_PLANT");
						
		if(isDefined(self) && isDefined(level.submission_is_runnning))
		{
						
			self.planting = true;
			self PlayerIsPlanting(other, model);			

			self.planting = undefined;			
		}
	}
}


PlayerIsPlanting(other, model) {

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


	level endon("StartMission");
	level endon("StartSubmission");


	
	if(!isDefined(other)) return;

	
	other endon("killed_player");
	other endon("disconnect");

	
	other.do_status = "plant";


	if(!isdefined(other.progressbackground))
	{
		other.progressbackground = newClientHudElem(other);
		other.progressbackground.x = 0;

		if(level.splitscreen)
			other.progressbackground.y = 70;
		else
			other.progressbackground.y = 104;

		other.progressbackground.alignX = "center";
		other.progressbackground.alignY = "middle";
		other.progressbackground.horzAlign = "center_safearea";
		other.progressbackground.vertAlign = "center_safearea";
		other.progressbackground.alpha = 0.5;
	}
	other.progressbackground setShader("black", (level.barsize + 4), 12);

	if(!isdefined(other.progressbar))
	{
		other.progressbar = newClientHudElem(other);
		other.progressbar.x = int(level.barsize / (-2.0));

		if(level.splitscreen)
			other.progressbar.y = 70;
		else
			other.progressbar.y = 104;

		other.progressbar.alignX = "left";
		other.progressbar.alignY = "middle";
		other.progressbar.horzAlign = "center_safearea";
		other.progressbar.vertAlign = "center_safearea";
	}
	other.progressbar setShader("white", 0, 8);
	other.progressbar scaleOverTime(level.planttime, level.barsize, 8);

	other playsound("MP_bomb_plant");
	other linkTo(self);
	other disableWeapon();

	self.progresstime = 0;
	while(isAlive(other) && other useButtonPressed() && (self.progresstime < level.planttime) && isDefined(level.submission_is_runnning))
	{
		self.progresstime += 0.05;
		wait 0.05;
	}


	if(self.progresstime >= level.planttime)
	{
		other.progressbackground destroy();
		other.progressbar destroy();
		other enableWeapon();
		other unlink();

		// * AdmiralMOD *					
		if(other.do_status == "plant") other.do_status = "none";



		plant = other maps\mp\_utility::getPlant();

		level.bombmodel = spawn("script_model", plant.origin);
		level.bombmodel.angles = plant.angles;
		level.bombmodel setmodel("xmodel/mp_tntbomb");
		level.bombmodel playSound("Explo_plant_no_tick");
		level.bombglow = spawn("script_model", plant.origin);
		level.bombglow.angles = plant.angles;
		level.bombglow setmodel("xmodel/mp_tntbomb_obj");


		level.bombplanted = true;
		level.bombtimerstart = gettime();
		level.planting_team = other.pers["team"];

		lpselfnum = other getEntityNumber();
		lpselfguid = other getGuid();
		logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.pers["team"] + ";" + other.name + ";" + "bomb_plant" + "\n");

		iprintln(&"MP_EXPLOSIVESPLANTED");
		level thread soundPlanted(other);

		level.bombmodel thread BombThink(model);
		level.bombmodel thread BombCountdown(model);

		level.bomb_planted = true;
		level notify("bomb_planted");
		

		return;	//TEMP, script should stop after the wait .05
	}
	else
	{
		if(isdefined(other.progressbackground))
			other.progressbackground destroy();

		if(isdefined(other.progressbar))
			other.progressbar destroy();

		other unlink();
		other enableWeapon();

		// * AdmiralMOD *					
		if(other.do_status == "plant") other.do_status = "none";

	}

}


BombCountdown(model)
{

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


	level endon("StartMission");
	level endon("StartSubmission");

	
	
	thread showBombTimers();
	level.bombmodel playLoopSound("bomb_tick");

	t = 30;
	if(isDefined(level.submission["bomb_time"]) && level.submission["bomb_time"] > 0) t = level.submission["bomb_time"];

	for(i=0;i<t;i++) {
	
		if(!isDefined(level.submission_is_runnning)) {
		
			thread deleteBombTimers();
			if(isDefined(level.bombmodel)) level.bombmodel stopLoopSound();
			if(isDefined(level.bombmodel)) level.bombmodel delete();
			if(isDefined(level.bombglow))  level.bombglow delete();
		
			return;
		}
		wait 1;
	}


	thread deleteBombTimers();

	level.bombexploded = true;
	self notify("bomb_exploded");

	
	
	// explode bomb
	origin = self.origin;
	range = 500;
	maxdamage = 2000;
	mindamage = 1000;

	level.bombmodel stopLoopSound();
	level.bombmodel delete();
	level.bombglow delete();
	
	if(isDefined(level.BombObject)) {
	
		if(model == "turret")	{
		
			if(isDefined(level.BombObject)) level.BombObject setmodel("xmodel/german_artillery_flak88_aa_nm_d_static");
			playfx(level._effect["bombexplosion"], origin);
			if(isDefined(level.BombObject)) level.BombObject playSound("am_flak88_explode", origin);
		}
		if(model == "barrels")	{
					
			level.BombObject playSound("am_flak88_explode", origin);
			playfx(level._effect["bombexplosion"], origin);			
							
			if(isDefined(level.BombObject)) level.BombObject hide();
			if(isDefined(level.BombObject2)) level.BombObject2 hide();
			if(isDefined(level.BombObject3)) level.BombObject3 hide();
			if(isDefined(level.BombObject4)) level.BombObject4 hide();
		}
		if(model == "radio")	{
		
			if(isDefined(level.BombObject)) level.BombObject setmodel("xmodel/military_german_fieldradio_grey_d");
			playfx(level._effect["bombexplosion"], origin);
			if(isDefined(level.BombObject)) level.BombObject playSound("am_flak88_explode", origin);
		}
	}


	
	
	radiusDamage(origin + (0,0,20), range, maxdamage, mindamage);

	level maps\mp\gametypes\_admiral_mod_player::DoQuake(origin, range + 800, 1);

	level thread maps\mp\gametypes\mm::playSoundOnPlayers("mp_announcer_objdest");


	// * Progressbar bei Explosion beim Spieler löschen *
	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
	{
		player = players[i];

		if(isDefined(player.progressbackground)) 	player.progressbackground destroy();
		if(isDefined(player.progressbar)) 			player.progressbar destroy();

	}
	
	wait 0.5;	
	
	level.bomb_destroyed = true;	

	wait 0.1;		
	

	if(model == "barrels")	{

		if(isDefined(level.BombObject))  level.BombObject delete();
		if(isDefined(level.BombObject2)) level.BombObject2 delete();
		if(isDefined(level.BombObject3)) level.BombObject3 delete();
		if(isDefined(level.BombObject4)) level.BombObject4 delete();
	}
	
}


BombThink(model)
{

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


	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");

	self endon("bomb_exploded");
	self endon("bomb_defused");
	

	
	
	level.barincrement = (level.barsize / (20.0 * level.defusetime));

	//self setHintString(&"PLATFORM_HOLD_TO_DEFUSE_EXPLOSIVES");

	while(isDefined(level.submission_is_runnning))
	{
		other = undefined;
		
		team = GetOtherTeam(level.submission["order_for"]);
		other = maps\mp\gametypes\_admiral_mod_player::WaitForLookAtUseObject(self, team, self.origin, 50, 40, "@AM_MP_LNG_PRESS_USE_TO_DEFUSE_LOOKAT");
		

		// check for having been triggered by a valid player
		if(isDefined(self) && isDefined(level.submission_is_runnning))
		{
			self.defusing = true;
						
			self PlayerIsDefusing(other);				
					
			self.defusing = undefined;			
		}
	}
}




PlayerIsDefusing(other) {


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


	level endon("StartMission");
	level endon("StartSubmission");

	
	if(!isDefined(other)) return;


	other endon("killed_player");
	other endon("disconnect");

	
	other.do_status = "defuse";


	if(!isdefined(other.progressbackground))
	{
		other.progressbackground = newClientHudElem(other);
		other.progressbackground.x = 0;

		if(level.splitscreen)
			other.progressbackground.y = 70;
		else
			other.progressbackground.y = 104;

		other.progressbackground.alignX = "center";
		other.progressbackground.alignY = "middle";
		other.progressbackground.horzAlign= "center_safearea";
		other.progressbackground.vertAlign = "center_safearea";
		other.progressbackground.alpha = 0.5;
	}
	other.progressbackground setShader("black", (level.barsize + 4), 12);

	if(!isdefined(other.progressbar))
	{
		other.progressbar = newClientHudElem(other);
		other.progressbar.x = int(level.barsize / (-2.0));

		if(level.splitscreen)
			other.progressbar.y = 70;
		else
			other.progressbar.y = 104;

		other.progressbar.alignX = "left";
		other.progressbar.alignY = "middle";
		other.progressbar.horzAlign = "center_safearea";
		other.progressbar.vertAlign = "center_safearea";
	}
	if(isDefined(other.progressbar)) other.progressbar setShader("white", 0, 8);
	if(isDefined(other.progressbar)) other.progressbar scaleOverTime(level.defusetime, level.barsize, 8);

	other playsound("MP_bomb_defuse");
	other linkTo(self);
	other disableWeapon();

	self.progresstime = 0;
	while(isAlive(other) && other useButtonPressed() && (self.progresstime < level.defusetime) && isDefined(level.submission_is_runnning))
	{
		self.progresstime += 0.05;
		wait 0.05;
	}


	if(self.progresstime >= level.defusetime)
	{
		if(isDefined(other.progressbackground)) other.progressbackground destroy();
		if(isDefined(other.progressbar)) 		other.progressbar destroy();
				
		other unlink();
		other enableWeapon();
			
		
		// * AdmiralMOD *					
		if(other.do_status == "defuse") other.do_status = "none";


		
		level.bombmodel stopLoopSound();
		level.bombglow delete();

		
		iprintln(&"MP_EXPLOSIVESDEFUSED");
		level thread maps\mp\gametypes\mm::playSoundOnPlayers("MP_announcer_bomb_defused");

		lpselfnum = other getEntityNumber();
		lpselfguid = other getGuid();
		logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.pers["team"] + ";" + other.name + ";" + "bomb_defuse" + "\n");


		
		// * DEFUSED!!!! *
		thread deleteBombTimers();

		level.bomb_defused = true;
		self notify("bomb_defused");
		
		
		return;	//TEMP, script should stop after the wait .05
	}
	else
	{
		if(isdefined(other.progressbackground))
			other.progressbackground destroy();

		if(isdefined(other.progressbar))
			other.progressbar destroy();

		other unlink();
		other enableWeapon();


		// * AdmiralMOD *					
		if(other.do_status == "defuse") other.do_status = "none";

	}
}



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


	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
	{
		player = players[i];

		if(isdefined(player.pers["team"]) && player.pers["team"] != "spectator" && player.sessionstate == "playing")
			player showPlayerBombTimer();
	}
}

showPlayerBombTimer()
{

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


	t = 30;
	if(isDefined(level.submission["bomb_time"]) && level.submission["bomb_time"] > 0) t = level.submission["bomb_time"];

	
	self.bombtimer = newClientHudElem(self);
	self.bombtimer.x = 6;
	self.bombtimer.y = 180;
	self.bombtimer.horzAlign = "left";
	self.bombtimer.vertAlign = "top";
	self.bombtimer setClock(t, 60, "hudStopwatch", 48, 48);

	if(game["am_sd_show_bomb_timer"] != 1) self.bombtimer.alpha = 0;	

}

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


	players = getentarray("player", "classname");
	for(i = 0; i < players.size; i++)
		players[i] deletePlayerBombTimer();
}

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


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



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

	
	if(game["allies"] == "british")
		alliedsound = "UK_mp_explosivesplanted";
	else if(game["allies"] == "russian")
		alliedsound = "RU_mp_explosivesplanted";
	else
		alliedsound = "US_mp_explosivesplanted";

	axissound = "GE_mp_explosivesplanted";

	if(level.splitscreen)
	{
		if(player.pers["team"] == "allies")
			player playLocalSound(alliedsound);
		else if(player.pers["team"] == "axis")
			player playLocalSound(axissound);

		return;
	}
	else
	{
		level maps\mp\gametypes\mm::playSoundOnPlayers(alliedsound, "allies");
		level maps\mp\gametypes\mm::playSoundOnPlayers(axissound, "axis");

		wait 1.5;

		if(level.planting_team == "allies")
		{
			if(game["allies"] == "british")
				alliedsound = "UK_mp_defendbomb";
			else if(game["allies"] == "russian")
				alliedsound = "RU_mp_defendbomb";
			else
				alliedsound = "US_mp_defendbomb";

			level maps\mp\gametypes\mm::playSoundOnPlayers(alliedsound, "allies");
			level maps\mp\gametypes\mm::playSoundOnPlayers("GE_mp_defusebomb", "axis");
		}
		else if(level.planting_team == "axis")
		{
			if(game["allies"] == "british")
				alliedsound = "UK_mp_defusebomb";
			else if(game["allies"] == "russian")
				alliedsound = "RU_mp_defusebomb";
			else
				alliedsound = "US_mp_defusebomb";

			level maps\mp\gametypes\mm::playSoundOnPlayers(alliedsound, "allies");
			level maps\mp\gametypes\mm::playSoundOnPlayers("GE_mp_defendbomb", "axis");
		}
	}
	
	
}





GetTeamKuerzel(team) {

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


	if(isDefined(team) && team == "allies") {
		
		team_kurz = "US";
		
		switch(game["allies"]) {

			case "american":
				team_kurz = "US";			
				break;
			case "british":
				team_kurz = "UK";			
				break;		
			case "russian":
				team_kurz = "RU";			
				break;
		}			
		
		return team_kurz;
	}
	else {
	
		return "GE";
	}
}



SaveMissionDatas() {

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


	alliedscore = getTeamScore("allies");
	axisscore = getTeamScore("axis");


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

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


		name = players[i].name;
		
		if(name.size > 16) name = maps\mp\gametypes\_admiral_mod_utils::subStr(name, 0, 16);
		
		team = "0";
		if(isDefined(players[i].pers["team"]) && players[i].pers["team"] == "allies") 	team = "1";
		if(isDefined(players[i].pers["team"]) && players[i].pers["team"] == "axis") 	team = "2";
		
		//name = name + "[d:]" + level.mission_nr + "_" + alliedscore + "_" + axisscore + "_" + players[i].pers["team"] + "_" + players[i].score + "_" + players[i].deaths;
		name = name + "[d:]" + level.mission_nr + "_" + alliedscore + "_" + axisscore + "_" + team;
	
		players[i] setClientCvar("name", name);	
	}	
	
	level thread PrintClearLines();
}



GetSavedMissionDatas() {

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


	self endon("disconnect");


	name = self.name;

	pos = maps\mp\gametypes\_admiral_mod_utils::find_first_string(name,"[d:]");
	

	if(pos > -1) {

	
		data 	= maps\mp\gametypes\_admiral_mod_utils::subStr(name,pos+4,name.size);
		d_split = maps\mp\gametypes\_admiral_mod_utils::str_split(data,"_");

		self_team				= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[3]);
		self_score				= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[4]);
		self_death				= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[5]);
		

		// * Wenn ein Spieler die Team-Daten geliefert hat... dann keine weiteren Team-Daten mehr zulassen *
		if(!isDefined(level.mission_data_already_set)) {

			level.mission_data_already_set = 1;

			level.mission_nr 		= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[0]);
			level.submission_size 	= game["am_mission_submissions"][level.mission_nr].size;


			alliedscore		 		= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[1]);
			axisscore		 		= maps\mp\gametypes\_admiral_mod_utils::strToInt(d_split[2]);

			if(isDefined(alliedscore) && alliedscore > 0 && alliedscore < 999) 			setTeamScore("allies", alliedscore);
			if(isDefined(axisscore) && axisscore > 0 && alliedscore < 999) 				setTeamScore("axis", axisscore);
								
		}
		
		// * Spieler-Daten *
		if(isDefined(self_team) && (self_team == 0 || self_team == 1 || self_team == 2)) 	{
			
			if(self_team == 0) 		self_team = undefined;
			else if(self_team == 1) self_team = "allies";
			else if(self_team == 2) self_team = "axis";
			
			self.pers["team"] 	= self_team;
			self.pers["weapon"] = undefined;
			self.pers["savedmodel"] = undefined;


			self.pers["remember_player_class"] 		= -1;
			self.pers["preselected_player_class"] 	= -1;
			self.pers["player_class"] 				= -1;	
			
		}
		if(isDefined(self_score) && self_score > - 999 && self_score < 999) 		self.score	= self_score;
		if(isDefined(self_death) && self_death > - 999 && self_death < 999) 		self.death	= self_death;
				
	
		// * Multiplayer-Namen bereinigen *
		self thread maps\mp\gametypes\_admiral_mod_xmission_engine::DeleteMissionAddon();	
		
		
		//iprintln("Team: " + self_team);
		//iprintln("Score: " + self_score);
		//iprintln("Death: " + self_death); 
		
	}
		
}


PrintClearLines() {

	wait 0.5;

	iprintln(" ");
	iprintln(" ");
	iprintln(" ");
	iprintln(" ");
	iprintln(" ");	
	iprintln(" ");	
}


DeleteMissionAddon() {

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


	name = self.name;

	pos = maps\mp\gametypes\_admiral_mod_utils::find_first_string(name, "[d:]");

	if(pos > -1) name = maps\mp\gametypes\_admiral_mod_utils::subStr(name,0,pos);

	self setClientCvar("name",name);	
	level thread PrintClearLines();
}



GetOtherTeam(team) {

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


	if(team == "allies") 	return "axis";
	if(team == "axis") 		return "allies";
	
	return team;

}


SpawnAllPlayers() {

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


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

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

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

			players[i] suicide();	
			players[i].deaths--;
			players[i] thread maps\mp\gametypes\mm::spawnplayer();
		}
	}
}

SpawnAllDeadPlayers() {

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


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

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

		if(!isDefined(players[i].pers["imabot_automatic"]) && isDefined(players[i].pers["team"]) && players[i].sessionstate != "playing" && (players[i].pers["team"] == "allies" || players[i].pers["team"] == "axis") ) {
			
			players[i] thread maps\mp\gametypes\mm::spawnplayer();
		}
	}
}

SpawnAllPlayersSubmission() {

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

	
	// * Alle toten Player und außerhalb des Radius *


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

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

		// * Alle Player und normale Bots neu Spawnen *
		if(!isDefined(players[i].pers["imabot_automatic"]) && isDefined(players[i].pers["team"])) {
		
			if(players[i].pers["team"] == "allies") {
			
				if(players[i].sessionstate != "playing" || distance(players[i].origin, level.spawnpoint_allies) > level.submission["respawn_away_range"]) {
			
					players[i] notify("killed_player");
					players[i] thread maps\mp\gametypes\mm::spawnplayer();
				}
			}
		
			if(players[i].pers["team"] == "axis") {

				if(players[i].sessionstate != "playing" || distance(players[i].origin, level.spawnpoint_axis) > level.submission["respawn_away_range"]) {
				
					players[i] notify("killed_player");
					players[i] thread maps\mp\gametypes\mm::spawnplayer();	
				}					
			}			
		}
	}
}





ShowMissionTime(mission_timelimit) {

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


	level notify("ShowMissionTime");
	level endon("ShowMissionTime");

	level endon("mission_end");


	mission_starttime = getTime();


	if(mission_timelimit > 0) {

		maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("mission_timer");
		maps\mp\gametypes\_admiral_mod_hud::createLevelTimerHudElement("mission_timer", 8,2,"left","top","fullscreen","fullscreen",false,"default",1.7,50,&"AM_MP_MMISSION_MISSION_TIME",mission_timelimit,1,1,1,1);
	}
		
	
	while(1) {

		if(getTime() > mission_starttime + mission_timelimit * 1000) break;
		
		if(isDefined(level.submission_is_runnning) && isDefined(level.submission_nr) && level.submission_nr == level.submission_size) break;
		
		wait 1;
	}

	maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("mission_timer");
	maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("submission_timer");

	
	// * Zeit abgelaufen *	
	
	
	// * Wenn bereits alle Sub-Missionen gespielt dann zurück *
	if(isDefined(level.submission_nr) && level.submission_nr == level.submission_size) return;
	
	
	
	// * Alle Submissionen als beendet deklarieren (keine Zeit mehr) *
	level.submission_nr = level.submission_size;
	
	
	// * Mission Ende einleiten (... dazu laufende Submission beenden) *
	level notify("submission_end");	


}


ShowSubMissionTime(submission_timelimit) {

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


	level notify("ShowSubMissionTime");
	level endon("ShowSubMissionTime");

	level endon("submission_end");


	wait 5;


	submission_starttime = getTime();

	if(submission_timelimit > 0) {

		maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("submission_timer");
		maps\mp\gametypes\_admiral_mod_hud::createLevelTimerHudElement("submission_timer", 8,30,"left","top","fullscreen","fullscreen",false,"default",1,50,&"AM_MP_MMISSION_SUBMISSION_TIME",submission_timelimit,0,1,1,1);
	
		thread maps\mp\gametypes\_admiral_mod_hud::fadeOverLevelHudElement("submission_timer",3,1);
	}
		
	
	// * Wenn Bombe geplanted ... dann Zeitanzeige ausschalten *   
	while(!isDefined(level.bomb_planted)) {

		if(getTime() > submission_starttime + submission_timelimit * 1000) break;
			
		wait 1;
	}

	maps\mp\gametypes\_admiral_mod_hud::deleteLevelHudElementByName("submission_timer");
	
	
	// * Zeit abgelaufen (und keine Bombe liegt) *
	if(!isDefined(level.bomb_planted)) {
	
		iprintlnbold(&"MP_TIMEHASEXPIRED");
		wait 0.1;

		level notify("submission_end");
	}

}


PlaceBombs() {

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


}


PlayEffects() {

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


	for(i=0;i<level.submission_effects.size;i++) {
			
		if(level.submission_effects[i]["effect_type"] == "artillery_attack") {
				
			thread StartEffectArtillery(level.submission_effects[i]);			
		}		
				
		if(level.submission_effects[i]["effect_type"] == "panzer_is_driving") {
		
			thread StartEffectPanzer(level.submission_effects[i]);						
		}		
	}
}


WaitForWalkActivation(team, effect_activa_position, range) { 

	level endon("StartMission");
	level endon("StartSubmission");

	level endon("submission_end");
	
	
	while(1) {
			
		
		maps\mp\gametypes\_admiral_mod_player::WaitForPlayerReachPosition(team, effect_activa_position, range, 200);
		
		return true;
		
		wait 2;
	}		
}


WaitForSubmissionEnd() {

	level endon("StartMission");
	level endon("StartSubmission");

	level waittill("submission_end");
	
	return true;	
}

WaitForMissionEnd() {

	level endon("StartMission");
	level endon("StartSubmission");

	level waittill("mission_end");
	
	return true;	
}


StartEffectArtillery(effect) {

	if(game["am_error_logfile"] == 1) logPrint("StartEffectArtillery\n");
	
	
	if(effect["effect_activator"] == "time") {
			
		wait 0.1 + effect["effect_starttime"];
	}
	if(effect["effect_activator"] == "position_range") {

		WaitForWalkActivation(effect["effect_activa_team"], effect["effect_activa_position"], effect["effect_activa_range"]); 
	}		
	if(effect["effect_activator"] == "submission_end") {

		WaitForSubmissionEnd(); 
	}		
	
			
	thread maps\mp\gametypes\_admiral_mod_ambient::ArtilleryAttack(0,"none",effect["effect_position_end"], effect["effect_radius"], effect["effect_damage_range"], effect["effect_player_damage"]);
}


StartEffectPanzer(effect) {

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



	if(effect["effect_activator"] == "time") {
			
		wait 0.1 + effect["effect_starttime"];
	}
	if(effect["effect_activator"] == "position_range") {

		WaitForWalkActivation(effect["effect_activa_team"], effect["effect_activa_position"], effect["effect_activa_range"]); 
	}		
	if(effect["effect_activator"] == "submission_end") {

		WaitForSubmissionEnd(); 
	}		
	
			
	thread PanzerDrive(effect);


}

PanzerDrive(effect) {


	tank_nr = 2;
	
	
	pmodel[1]["idle"] 		= "xmodel/vehicle_panzer_ii_static";
	pmodel[1]["drive"] 		= "xmodel/vehicle_panzer_ii";
	pmodel[1]["destroyed"] 	= "xmodel/vehicle_panzer_ii_destroyed";

	pmodel[2]["idle"] 		= "xmodel/vehicle_american_sherman_static";
	pmodel[2]["drive"] 		= "xmodel/vehicle_american_sherman";
	pmodel[2]["destroyed"] 	= "xmodel/vehicle_american_sherman_d";

	pmodel[3]["idle"] 		= "xmodel/vehicle_tiger_woodland_static";
	pmodel[3]["drive"] 		= "xmodel/vehicle_tiger_woodland";
	pmodel[3]["destroyed"] 	= "xmodel/vehicle_tiger_woodland_d";
	


	
	panzer = spawn("script_model", (0,0,0));
		
	
	while(1) {
	
		panzer.origin = effect["effect_position_points"][0];
	
			
		
		test = spawn("script_model", panzer.origin + (0,0,40));	
		test setmodel("xmodel/mp_tntbomb");
		
				
		// * Warten auf Player *
		player = maps\mp\gametypes\_admiral_mod_player::WaitForLookAtUseObject(test, "all", panzer.origin + (0,0,20), 100, 80, "Look at and press USE-Button");
		
		
	
	
	
		blickwinkel = vectortoangles(vectornormalize(effect["effect_position_points"][0] - effect["effect_position_points"][1]));
		winkel = blickwinkel + (0,180,0);

		panzer playloopsound("am_tank_"+tank_nr+"_idle");
		panzer setmodel(pmodel[tank_nr]["idle"]);	
		panzer.angles = winkel;
		wait 5;

		
		for(i=1;i<effect["effect_position_points"].size;i++) {
		
			zeit = maps\mp\gametypes\_admiral_mod_utils::ZeitSpeedBerechnung(6.8, effect["effect_position_points"][i-1], effect["effect_position_points"][i]);

			panzer setmodel(pmodel[tank_nr]["drive"]);
			panzer playloopsound("am_tank_"+tank_nr+"_engine_high");

			
			panzer moveto(effect["effect_position_points"][i],zeit,0.5,0.5);
			wait zeit;
		

			if(i<effect["effect_position_points"].size -1) {
			
				self thread ShotShell(undefined, effect["effect_position_points"][i], winkel, effect["effect_activa_team"][i]);

			
				blickwinkel = vectortoangles(vectornormalize(effect["effect_position_points"][i] - effect["effect_position_points"][i+1]));
				winkel = blickwinkel + (0,180,0);

				panzer playloopsound("am_tank_"+tank_nr+"_engine_low");
				panzer rotateto(winkel, 6,0.5,0.5);
				wait 6;

				/*
				panzer playloopsound("am_tank_"+tank_nr+"_idle");
				panzer setmodel(pmodel[tank_nr]["idle"]);				
				wait 1;
				*/
			}
		}
		
		
		playfx(level._effect["panzer_explosion"], panzer.origin);		
		panzer stoploopsound();
		panzer hide();
		wait 10;
		
		panzer show();

	}
	
	panzer delete();
	
		
	
}




PlantSticky() {

/*
	
	bomb setmodel("xmodel/weapon_stickybomb_obj");
	
	bomb setmodel ("xmodel/weapon_stickybomb");
	bomb playsound ("stickybomb_plant");
	bomb playloopsound ("bomb_tick");


	level waittill("one left");
	level waittill_any("sticky planted","regroup");
	musicplay("soviet_victory_light02");

	self playsound ("grenade_explode_default");
	level maps\_fx::OneShotfx("sticky_explosion", bomb.origin, 0.1);
	self thread maps\_fx::loopfx("sticky_explosion_smoke",self gettagorigin("tag_engine_left"), 2,undefined);
*/



}



ShotTurret(client_id, origin, angles, team) {

	//precacheturret("mg42_tank_panzer2");
	//level._effect[model+"tank_fire_turret"] = loadfx("fx/fire/panzer2_fire_turret_small.efx");
	//level._effect[model+"tank_fire_engine"] = loadfx("fx/fire/tank_fire_engine.efx");


	//level.damagefiretag[model][level.damagefiretag[model].size] = "tag_engine_left";
	
		/*
		case "tiger":
			self.mgturret[0] = spawnTurret("misc_turret", (0,0,0), "mg42_tank_tiger");
			self.mgturret[0] linkto(self, "tag_turret2", (0, 0, 0), (0, 0, 0));
			self.mgturret[0] setmodel("xmodel/weapon_machinegun_tiger");
			break;
		case "panzer2":
			self.mgturret[0] = spawnTurret("misc_turret", (0,0,0), "mg42_tank_panzer2");
			self.mgturret[0] linkto(self, "tag_turret2", (0, 0, 0), (0, 0, 0));
			self.mgturret[0] setmodel("xmodel/weapon_machinegun_panzer2");
			break;
		case "sherman":
			if (self.model == "xmodel/vehicle_american_sherman_desert")
				return;
			self.mgturret[0] = spawnTurret("misc_turret", (0,0,0), "mg42_tank_crusader");
			self.mgturret[0] linkto(self, "tag_turret2", (0, 0, 0), (0, 0, 0));
			self.mgturret[0] setmodel("xmodel/vehicle_sherman__tank_machinegun");
			break;
		*/
}




ShotShell(client_id, origin, angles, team) {

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



	shell = spawn("script_model", (0,0,0));
	shell setModel("xmodel/prop_mortar_ammunition");
	shell.origin = origin;	
	shell.angles = angles;	
	shell show();


	
	imrohr = maps\mp\_utility::vectorScale(anglestoforward((shell.angles)),220);
	
	shell.origin = origin + imrohr + (0,0,95);	

	
	shell playsound("am_tank_fire", origin);


	forward = anglesToForward( shell.angles );
	position = shell.origin + forward;

	speed = maps\mp\_utility::vectorScale(forward, 2.7);


	playfx(level._effect["panzer_flash"], position, forward);	
	earthquake(0.35, 0.3, origin, 700);
			
	
	shell maps\mp\gametypes\_admiral_mod_utils::ThrowObject(client_id, team, "mortar", speed, undefined);


    o = RandomInt(3);
    playfx(game["motar_explosions_fx"][o], shell.origin);            
                    
    shell playSound("am_mortar_explosion");    
    
    shell hide();
           
           
    // * do the damage *
    points = game["am_points_for_artillerie_kill"];
    maps\mp\gametypes\_admiral_mod_player::DamageToPlayers(points, client_id, team, shell.origin + (0,0,12), 1000, game["am_player_artillerie_damage_range"], game["am_player_artillerie_player_damage"], 1, 1, "MOD_EXPLOSIVE","mortar_cannon_walk_mp");
                 
	 
 	wait 3; // Sound ending   
   
    if(isDefined(shell)) shell delete();
	
}


