I am making a Kill The King mod and it worked fine in all of my tests in private matches.
BUT in public matches the team switching doesn't really work like I want it.
Here are some things that are pretty weird:
- Enemies show up as teammates and teammates show up as enemies in a mixed order.
- The scoreboard and mini-map do not update after switching.
- Sentry guns are confused.
- The player models are wrong.
- You spawn at the original spawn place. So if you got switched you spawn at your enemies.
Here's the code I wrote to set the player to the right team:
Code:
onspawn()
{
self endon( "death" );
self endon( "disconnect" );
self takeAllWeapons();
self clearPerks();
if( self.type == "undefined" )
{
if( level.teamsset == 1 )
{
self.type = "assassin";
self.weapon = "cheytac_mp";
}
else
{
level waittill( "teamset" );
}
}
if( self.type == "king" )
{
if( self.team != "allies" )
{
self maps\mp\gametypes\_menus::addToTeam( "allies", true );
self.team = "allies";
self notify("menuresponse", game["menu_team"], "allies");
}
self.maxhealth = 400;
self.health = 400;
}
if( self.type == "assassin" )
{
if( self.team != "axis" )
{
self maps\mp\gametypes\_menus::addToTeam( "axis", true );
self.team = "axis";
self notify("menuresponse", game["menu_team"], "axis");
}
}
if( self.type == "guard" )
{
if( self.team != "allies" )
{
self maps\mp\gametypes\_menus::addToTeam( "allies", true );
self.team = "allies";
self notify("menuresponse", game["menu_team"], "allies");
}
}
self giveWeapon( self.weapon, 0, false );
wait ( 0.05 );
self switchToWeapon( self.weapon, 0, false );
}