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



// max. 2-6 Spieler je Einheit


// jeder neue Spieler der connected wird automatisch zu
// einem Squad entweder der Aliierten oder Achsenmächten zugeordnet
// jedes Squad muß komplett in einem Transportmittel transportiert
// werden, hat ein komplettes Squad keinen Platz mehr in einem
// Transportmittel, wird ein neues Transportmittel erstellt, oder
// das Squad spawned zu Fuß.



// am_squads = 1
// am_max_players_in_squad 			= 3			(2,6)
// am_max_dist_from_squad 			= 1000   	(500,1500)
// am_max_seconds_away_from_squad 	= 10;		(10,30)
// am_clanmember_squads_enabled		= 1;		(0/1)


InitSquads() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


	if(!isDefined(game["squad_allies"])) {

		game["squad_allies"]		= [];
		game["squad_axis"] 			= [];


		game["squad_count_allies"] 	= 0;
		game["squad_count_axis"] 	= 0;
	}
}




AddPlayerToSquad() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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

	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;



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


	
	if(!isDefined(self.pers["team"])) return;	
	if(self.pers["team"] != "allies" && self.pers["team"] != "axis") return;

	
	
	while(isDefined(level.add_player_in_squad)) wait 0.1;
	level.add_player_in_squad = true;

	

	// * Wenn schon im Squad, dann schauen ob Team gewechselt *
	if(isDefined(self.pers["squad_team"])) {

		now_squad_team = "squad_" + self.pers["team"];
		
		
		// * Spieler wechselt das Team *
		if(now_squad_team != self.pers["squad_team"]) {
		
			old_team = "";
		
			if(self.pers["team"] == "axis") 	old_team = "allies";
			if(self.pers["team"] == "allies") 	old_team = "axis";
		
			if(old_team != "") self RemovePlayerFromSquad(old_team);
		}
		else {
	
			level.add_player_in_squad = undefined; 	
			return;
		}
	}





	player_team = self.pers["team"];	
	squad_team 	= "squad_" + player_team;


	squad_nr 	= self FindSquadToJoin();

	if(squad_nr == -1) 	squad_nr = self CreateSquad();
	else {
	
	
		// * Wenn dieser Squad keinen Anführer hat, dann selbst ... *
		if(!isDefined(game[squad_team][squad_nr]["squad_leader"])) self SetLeader(squad_team,squad_nr);
		
		// * Dem SQUAD beitreten *
		self JoinSquad(squad_team,squad_nr);
	}


	// * Kein Squad Team möglich *
	if(squad_nr == -1) return;




	// * Playernamen ändern * 
	
	// "SQUAD AL3: Name"
	// "SQUAD AX1: Name"

			
	
	squad_name = "[" + game["am_squadnames_" + self.pers["team"]][squad_nr] + "]";
	
	

	level.add_player_in_squad = undefined; 	
}


FindSquadToJoin() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


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


	player_team 		= self.pers["team"];	
	squad_team 			= "squad_" + player_team;
	squad_team_count 	= "squad_count_" + player_team;


	
	for(i=0;i<game[squad_team_count];i++) {
	
		if(game[squad_team][i]["player_count"] < game["am_max_players_in_squad"]) {
					
			// * Wenn Clanmember Option *
			if(game["am_clanmember_squads_enabled"] == 1) {
				
				// * wenn Player Clanmember, dann nach Clan-Squad suchen *
				if(isDefined(self.pers["clanmember"]) && self.pers["clanmember"]) {
				
					// * Wenn Clan-Squad *
					if(game[squad_team][i]["clansquad"] == true) return i;
				}
				else {
				
					if(game[squad_team][i]["clansquad"] == false) return i;				
				}
			}	
			else return i;			
		}
	}

	return -1;
}



SquadMemberKilled() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;

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


	self endon("disconnect");


	
	if(!isDefined(self.pers["squad_team"]) || !isDefined(self.pers["squad_nr"])) return;


	// * Message an Squad Members und TeamLeader *	
	if(isDefined(self.pers["squad_leader"])) 	self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_LEADER_KILLED", self);
	else										self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_MEMBER_KILLED", self);


	
	// * Für den Fall das Spieler in den Spectator-Modus gewechselt hat *
	self.pers["old_team"] = self.pers["team"];
	
}


SquadMemberDisconnect() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;

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

	
	if(!isDefined(self.pers["squad_team"]) || !isDefined(self.pers["squad_nr"])) return;


	// * Message an Squad Members und TeamLeader *	
	if(isDefined(self.pers["squad_leader"])) 	self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_LEADER_KILLED", self);
	else										self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_MEMBER_KILLED", self);


	squad_team 	= self.pers["squad_team"];
	squad_nr 	= self.pers["squad_nr"];

	if(!isDefined(squad_team) || !isDefined(squad_nr)) return;


	// * Message an Squad Members *
	if(isDefined(self.pers["squad_leader"]))	self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_LEADER_LEFT", self);
	else										self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_MEMBER_LEFT", self);


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


	// * TeamLeader? *
	if(isDefined(self.pers["squad_leader"])) {

		self.pers["squad_leader"] 	= undefined;
	
		game[squad_team][squad_nr]["squad_leader"] = undefined;		
	
	
		// * der nächste der ins Team kommt, der wird Teamleader *
		
	}
	
	game[squad_team][squad_nr]["player_count"]--;
	
}


SquadMemberSpectator() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


	self endon("disconnect");
	

}


SquadRespawnTimer() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;

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


	self endon("disconnect");
	
	
	time = game["am_squad_respawn_time"];


	self.WaitingToSpawn = true;
	
	wait 2;
	self maps\mp\gametypes\_admiral_mod_hud::createPlayerTimerHudElement("squad_respawn_timer", 0,-30,"center","middle","center_safearea","center_safearea",0,false,"default",2,&"AM_MP_SQUAD_RESPAWN",time);
	self thread SquadRespawnTimerUpdate();


	wait time;	

	
	self.WaitingToSpawn = undefined;
	wait 0.05;
	
	
	self maps\mp\gametypes\_admiral_mod_hud::deletePlayerHudElementByName("squad_respawn_timer");    			
		
}

SquadRespawnTimerUpdate() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


	self endon("disconnect");

	// * Wenn Player nicht Spectator *
	if(isDefined(self.pers["team"]) && (self.pers["team"] == "spectator")) {
		
		// * Respawn Timer anzeigen *
		self thread maps\mp\gametypes\_admiral_mod_hud::changePlayerTimerHudElementByName("squad_respawn_timer",0);		
	}
	else {
	
		// * Respawn Timer verstecken *
		self thread maps\mp\gametypes\_admiral_mod_hud::changePlayerTimerHudElementByName("squad_respawn_timer",1);		
	}
}



RemovePlayerFromSquad(old_team) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;

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

	self endon("disconnect");

	
	squad_team 	= self.pers["squad_team"];
	squad_nr 	= self.pers["squad_nr"];

	if(!isDefined(squad_team) || !isDefined(squad_nr)) return;


	// * Message an Squad Members *
	if(isDefined(self.pers["squad_leader"]))	self thread SquadMessage("", old_team,  self.pers["squad_nr"], &"AM_MP_LEADER_LEFT", self);
	else										self thread SquadMessage("", old_team,  self.pers["squad_nr"], &"AM_MP_MEMBER_LEFT", self);


	// * TeamLeader? *
	if(isDefined(self.pers["squad_leader"])) {

		self.pers["squad_leader"] 	= undefined;
	
		game[squad_team][squad_nr]["squad_leader"] = undefined;		
	
	
		// * der nächste der ins Team kommt, der wird Teamleader *
		
	}
	
	game[squad_team][squad_nr]["player_count"]--;
	
	
	// * Wenn SQUAD Member Count < 1 *
	if(game[squad_team][squad_nr]["player_count"] < 1) {
			
			
	}


	self.pers["squad_team"] 	= undefined;
	self.pers["squad_nr"] 		= undefined;


}



CreateSquad() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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

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


	player_team 		= self.pers["team"];	
	squad_team 			= "squad_" + player_team;
	squad_team_count 	= "squad_count_" + player_team;
	


	if(game[squad_team_count] == 9) return;

	squad_nr = game[squad_team_count];
	
	
	// * Wenn kein Squadname für diese Squad-Nr, dann keinen Squad erstellen *
	if(!isDefined(game["am_squadnames_allies"][squad_nr]) || !isDefined(game["am_squadnames_axis"][squad_nr])) return;
	

	// * Clan Members / Public Members *   
	if(isDefined(self.pers["clanmember"])) 	game[squad_team][squad_nr]["clansquad"] = true;
	else									game[squad_team][squad_nr]["clansquad"] = false;	
		

	game[squad_team][squad_nr]["player_count"] = 0;
	
	self SetLeader(squad_team,squad_nr);
	self JoinSquad(squad_team,squad_nr);


	game[squad_team_count]++;	
	
	
	return squad_nr;
}



SetLeader(squad_team, squad_nr) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


	game[squad_team][squad_nr]["squad_leader"] = self;
	self.pers["squad_leader"] = true;
	
	
	message = game["am_squad_new_leader_text"];

	
	message = maps\mp\gametypes\_admiral_mod_utils::replace_string("#squadname#",game["am_squadnames_" + self.pers["team"]][squad_nr],message);
	message = maps\mp\gametypes\_admiral_mod_utils::replace_string("#teamname#",maps\mp\gametypes\_admiral_mod_utils::firstToUpper(self.pers["team"]),message);
	message = maps\mp\gametypes\_admiral_mod_utils::replace_string("#playername#",self.name,message);
	
	
    
    if(isDefined(squad_nr) && squad_nr >= 0 && squad_nr <= 9) {
 	
 		self thread TeamMessage("", self.pers["team"], message, self);            	
    }	
	
	
}


JoinSquad(squad_team, squad_nr) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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

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


	self.pers["squad_team"] = squad_team;
	self.pers["squad_nr"] 	= squad_nr;
	
	if(!isDefined(self.pers["squad_leader"])) {
	
		messages[0] = " ";		
		
		if(self.pers["team"] == "allies") {

			switch(squad_nr) {
 				
 				case 0:
					messages[1] = &"AM_MP_JOINSQUAD_0_ALLIES";				
					break;
 				case 1:
					messages[1] = &"AM_MP_JOINSQUAD_1_ALLIES";				
					break;
 				case 2:
					messages[1] = &"AM_MP_JOINSQUAD_2_ALLIES";				
					break;
 				case 3:
					messages[1] = &"AM_MP_JOINSQUAD_3_ALLIES";				
					break;
 				case 4:
					messages[1] = &"AM_MP_JOINSQUAD_4_ALLIES";				
					break;
 				case 5:
					messages[1] = &"AM_MP_JOINSQUAD_5_ALLIES";				
					break;
 				case 6:
					messages[1] = &"AM_MP_JOINSQUAD_6_ALLIES";				
					break;
 				case 7:
					messages[1] = &"AM_MP_JOINSQUAD_7_ALLIES";				
					break;
 				case 8:
					messages[1] = &"AM_MP_JOINSQUAD_8_ALLIES";				
					break;
 				case 9:
					messages[1] = &"AM_MP_JOINSQUAD_9_ALLIES";	
					break;
			}
		}
		if(self.pers["team"] == "axis") {

			switch(squad_nr) {
 				
 				case 0:
					messages[1] = &"AM_MP_JOINSQUAD_0_AXIS";				
					break;
 				case 1:
					messages[1] = &"AM_MP_JOINSQUAD_1_AXIS";				
					break;
 				case 2:
					messages[1] = &"AM_MP_JOINSQUAD_2_AXIS";				
					break;
 				case 3:
					messages[1] = &"AM_MP_JOINSQUAD_3_AXIS";				
					break;
 				case 4:
					messages[1] = &"AM_MP_JOINSQUAD_4_AXIS";				
					break;
 				case 5:
					messages[1] = &"AM_MP_JOINSQUAD_5_AXIS";				
					break;
 				case 6:
					messages[1] = &"AM_MP_JOINSQUAD_6_AXIS";				
					break;
 				case 7:
					messages[1] = &"AM_MP_JOINSQUAD_7_AXIS";				
					break;
 				case 8:
					messages[1] = &"AM_MP_JOINSQUAD_8_AXIS";				
					break;
 				case 9:
					messages[1] = &"AM_MP_JOINSQUAD_9_AXIS";	
					break;
			}
		}		
		
		self thread SquadMemberMessage("", messages[0], undefined);	
		wait 0.05;
		self thread SquadMemberMessage("", messages[1], undefined);		
		wait 0.05;
		self thread SquadMemberMessage("bold", &"AM_MP_FOLLOW_LEADER", undefined);		
		wait 0.05;	
		self thread SquadMemberMessage("bold", &"AM_MP_FOLLOW_LEADER_NAME", game[squad_team][squad_nr]["squad_leader"]);		


		// * Message an Squad Members und TeamLeader *
		self thread SquadMessage("", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_MEMBER_JOINED", self);
				

		
	}
	else {
	
		messages[0] = " ";	

		message = game["am_squad_you_leader_text"];

	
		message = maps\mp\gametypes\_admiral_mod_utils::replace_string("#squadname#",game["am_squadnames_" + self.pers["team"]][squad_nr],message);
		message = maps\mp\gametypes\_admiral_mod_utils::replace_string("#teamname#",maps\mp\gametypes\_admiral_mod_utils::firstToUpper(self.pers["team"]),message);
		
		messages[1] = message;


		messages[2] = &"AM_MP_LEADER_INSTRUCTIONS";

		self thread SquadMemberMessage("bold", messages[0], undefined);	
		wait 0.05;
		self thread SquadMemberMessage("bold", messages[1], undefined);		
		wait 0.05;
		self thread SquadMemberMessage("bold", messages[2], undefined);		


		wait 0.05;	
	
		// * Message an Squad Members *
		self thread SquadMessage("bold", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_FOLLOW_LEADER", undefined);	
		wait 0.05;	
		self thread SquadMessage("bold", self.pers["team"],  self.pers["squad_nr"], &"AM_MP_FOLLOW_LEADER_NAME", self);	
		
	}
	
		

	
	game[squad_team][squad_nr]["player_count"]++;
}




IndicateLeader() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


	self notify("IndicateLeader");
	self endon("IndicateLeader");



	// * IndicateLeader wird bei jedem Spawn aufgerufen, deshalb alten vorher beenden *
	self endon("spawned");
	self endon("disconnect");
	self endon("killed_player");

	
	

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


	// * wenn Spieler selber Leader, dann kein Check *
	if(isDefined(self.pers["squad_leader"])) return;



	
	if(!isDefined(self.pers["squad_team"]) || !isDefined(self.pers["squad_nr"])) return;
	
	squad_team 	= self.pers["squad_team"];
	squad_nr	= self.pers["squad_nr"];
	
	
	
	while(1) {
	
		wait 1;
	
	
		squad_leader = self GetSquadLeader();
		
		if(!isDefined(squad_leader)) continue;
	
	
 		if(!isDefined(self.squadleader_indicator))  {
 
			self.squadleader_indicator = newClientHudElem(self);
			self.squadleader_indicator.name = "Testindicator";
			self.squadleader_indicator.x = squad_leader.origin[0];
			self.squadleader_indicator.y = squad_leader.origin[1];
			self.squadleader_indicator.z = squad_leader.origin[2] + 80;
			self.squadleader_indicator.alpha = 0;
			self.squadleader_indicator.archived = true;
			self.squadleader_indicator setShader("objpoint_star", 8, 8);
			self.squadleader_indicator setwaypoint(true);
		}

		
		self.squadleader_indicator.alpha = 0.6;
		

		while(1) {


			if(!isDefined(game[squad_team][squad_nr]["squad_leader"])) break;

			if(isDefined(self.squadleader_indicator) && isDefined(game[squad_team][squad_nr]["squad_leader"]) && isDefined(squad_leader) && squad_leader.sessionstate == "playing") self.squadleader_indicator.x = squad_leader.origin[0];
			if(isDefined(self.squadleader_indicator) && isDefined(game[squad_team][squad_nr]["squad_leader"]) && isDefined(squad_leader) && squad_leader.sessionstate == "playing") self.squadleader_indicator.y = squad_leader.origin[1];
			if(isDefined(self.squadleader_indicator) && isDefined(game[squad_team][squad_nr]["squad_leader"]) && isDefined(squad_leader) && squad_leader.sessionstate == "playing") self.squadleader_indicator.z = squad_leader.origin[2] + 80;
			
			wait 1;
		}

		self.squadleader_indicator.alpha = 0;
 	}	
}


CheckSquadLeaderDistance() {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


	self notify("CheckSquadLeaderDistance");
	self endon("CheckSquadLeaderDistance");

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

	
	// * CheckSquadLeaderDistance wird bei jedem Spawn aufgerufen, deshalb alten vorher beenden *
	self endon("spawned");
	
	
	if(game["am_error_logfile"] == 1) logPrint("CheckSquadLeaderDistance\n");


	// * wenn Spieler selber Leader, dann kein Check *
	if(isDefined(self.pers["squad_leader"])) return;
	



	// * Screen init *
   	self maps\mp\gametypes\_admiral_mod_hud::deletePlayerHudElementByName("squad_black_screen");
	self maps\mp\gametypes\_admiral_mod_hud::createPlayerHudElement("squad_black_screen", 0,0,"left","top","fullscreen","fullscreen",false,"black",640,480,-50,0,0,0,0);
	
	


	
	// * Damit der Member Zeit hat sich zu orientieren *
	wait 6;
	
	
    while(1) {
    
        
        wait 2; // wegen continue
                
 		squad_leader = self GetSquadLeader();
		
		if(!isDefined(squad_leader)) {
		
			self thread maps\mp\gametypes\_admiral_mod_hud::fadeOverPlayerHudElement("squad_black_screen",1,0);
			
			continue;
		}
                   
        
        
        dist = distance(self.origin,squad_leader.origin);
                
        if(dist > game["am_max_dist_from_squad"]) {
                
			self iprintlnbold(" ");
			self iprintlnbold(&"AM_MP_STAY_SQUAD");
		
		}
                

		alpha = (((dist - game["am_max_dist_from_squad"]) + 1) / 1000) * 1.3;

		if(alpha < 0) alpha = 0;
		if(alpha > 0.9) alpha = 0.9;

		self thread maps\mp\gametypes\_admiral_mod_hud::fadeOverPlayerHudElement("squad_black_screen",6,alpha);


                
        wait 8;
	}
}



GetSquadLeader() {
           
	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


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


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

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

		player = players[i];

		if(isAlive(player) && player != self && isDefined(player.pers["squad_leader"]) && player.pers["squad_team"] == self.pers["squad_team"]) {
		
			return players[i];
		}		         
	}
	
	return undefined;
}








TeamMessage(type, team, message, player) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


	if(isDefined(player)) {
	
		player endon("disconnect");
		player endon("killed_player");
	}


	if(!isDefined(team) || !isDefined(message)) return;

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

	wait 5;	

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

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

		if(players[i].sessionstate == "playing" && players[i].pers["team"] == team) {
		
			if(!isDefined(type) || type == "")	{
			
				players[i] iprintln(message);					
			}
			else {
			
				players[i] iprintlnbold(message);					
			}
		}		
	}
}


SquadMessage(type, squad_team, squad_nr, message, player) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


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


	if(isDefined(player)) {
	
		player endon("disconnect");
		player endon("killed_player");
	}


	if(!isDefined(squad_team)) return;
	if(!isDefined(squad_nr)) return;
	if(!isDefined(message)) return;

	
	if(game["am_error_logfile"] == 1) logPrint("SquadMessage\n");
	
	
	players = getentarray("player", "classname");

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

		if(players[i].sessionstate == "playing" && players[i].pers["team"] == squad_team && isDefined(players[i].pers["squad_nr"]) && players[i].pers["squad_nr"] == squad_nr && players[i] != self) {
		
			if(!isDefined(type) || type == "")	{
			
				if(isDefined(player)) 	players[i] iprintln(message, player.name);	
				else					players[i] iprintln(message);	
			}
			else {
			
				if(isDefined(player)) 	players[i] iprintlnbold(message, player.name);	
				else					players[i] iprintlnbold(message);	
			}		
		}		
	}
}


SquadMemberMessage(type, message, player) {

	if(game["am_squads"] != 1) return;
	if(game["am_gametype"] == "dm" || game["am_gametype"] == "sd" || game["am_gametype"] == "sdr" || game["am_gametype"] == "csd") return;


	self endon("disconnect");
	self endon("killed_player");
	
	
	if(isDefined(player)) {
	
		player endon("disconnect");
		player endon("killed_player");
	}


	if(!isDefined(message)) return;


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


	wait 1;	

	
	
	if(!isDefined(type) || type == "")	{
	
		if(isDefined(player))	self iprintln(message, player.name);
		else					self iprintln(message);
	
	}
	if(type == "bold") {
	
		if(isDefined(player))	self iprintlnbold(message, player.name);
		else					self iprintlnbold(message);
	}
		
	wait 0.2;	
}



