Index: src/game/g_client.c =================================================================== --- src/game/g_client.c (revision 893) +++ src/game/g_client.c (working copy) @@ -1651,7 +1652,6 @@ { gentity_t *ent; gentity_t *tent; - int i; ent = g_entities + clientNum; @@ -1659,19 +1658,8 @@ return; G_admin_namelog_update( ent->client, -1 ); + G_LeaveTeam( ent ); - // stop any following clients - for( i = 0; i < level.maxclients; i++ ) - { - if( level.clients[ i ].sess.sessionTeam == TEAM_SPECTATOR && - level.clients[ i ].sess.spectatorState == SPECTATOR_FOLLOW && - level.clients[ i ].sess.spectatorClient == clientNum ) - { - if( !G_FollowNewClient( &g_entities[ i ], 1 ) ) - G_StopFollowing( &g_entities[ i ] ); - } - } - // send effect if they were completely connected if( ent->client->pers.connected == CON_CONNECTED && ent->client->sess.sessionTeam != TEAM_SPECTATOR ) @@ -1683,11 +1671,6 @@ G_LogPrintf( "ClientDisconnect: %i [%s] (%s) \"%s\"\n", clientNum, ent->client->pers.ip, ent->client->pers.guid, ent->client->pers.netname ); - if( ent->client->pers.teamSelection == PTE_ALIENS ) - G_RemoveFromSpawnQueue( &level.alienSpawnQueue, ent->client->ps.clientNum ); - else if( ent->client->pers.teamSelection == PTE_HUMANS ) - G_RemoveFromSpawnQueue( &level.humanSpawnQueue, ent->client->ps.clientNum ); - trap_UnlinkEntity( ent ); ent->s.modelindex = 0; ent->inuse = qfalse; Index: src/game/g_cmds.c =================================================================== --- src/game/g_cmds.c (revision 893) +++ src/game/g_cmds.c (working copy) @@ -572,6 +572,54 @@ } /* +================== +G_LeaveTeam +================== +*/ +void G_LeaveTeam( gentity_t *self ) +{ + pTeam_t team = self->client->pers.teamSelection; + gentity_t *ent; + int i; + + // stop following clients + for( i = 0; i < level.maxclients; i++ ) + { + if( level.clients[ i ].sess.sessionTeam == TEAM_SPECTATOR && + level.clients[ i ].sess.spectatorState == SPECTATOR_FOLLOW && + level.clients[ i ].sess.spectatorClient == self->client->ps.clientNum ) + { + if( !G_FollowNewClient( &g_entities[ i ], 1 ) ) + G_StopFollowing( &g_entities[ i ] ); + } + } + + if( team == PTE_ALIENS ) + G_RemoveFromSpawnQueue( &level.alienSpawnQueue, self->client->ps.clientNum ); + else if( team == PTE_HUMANS ) + G_RemoveFromSpawnQueue( &level.humanSpawnQueue, self->client->ps.clientNum ); + + for( i = 0; i < level.num_entities; i++ ) + { + ent = &g_entities[ i ]; + if( !ent->inuse ) + continue; + + if( ent->s.eType == ET_MISSILE && ent->r.ownerNum == self->s.number ) + G_FreeEntity( ent ); + if( ent->client && ent->client->pers.connected == CON_CONNECTED ) + { + if( ent->client->ps.stats[ STAT_STATE ] & SS_POISONCLOUDED && + ent->client->lastPoisonCloudedClient == self ) + ent->client->ps.stats[ STAT_STATE ] &= ~SS_POISONCLOUDED; + if( ent->client->ps.stats[ STAT_STATE ] & SS_POISONED && + ent->client->lastPoisonClient == self ) + ent->client->ps.stats[ STAT_STATE ] &= ~SS_POISONED; + } + } +} + +/* ================= G_ChangeTeam ================= @@ -583,13 +631,9 @@ if( oldTeam == newTeam ) return; + G_LeaveTeam( ent ); ent->client->pers.teamSelection = newTeam; - if( oldTeam == PTE_ALIENS ) - G_RemoveFromSpawnQueue( &level.alienSpawnQueue, ent->client->ps.clientNum ); - else if( oldTeam == PTE_HUMANS ) - G_RemoveFromSpawnQueue( &level.humanSpawnQueue, ent->client->ps.clientNum ); - // under certain circumstances, clients can keep their kills and credits // when switching teams if( G_admin_permission( ent, ADMF_TEAMCHANGEFREE ) || Index: src/game/g_local.h =================================================================== --- src/game/g_local.h (revision 893) +++ src/game/g_local.h (working copy) @@ -678,6 +678,7 @@ qboolean G_SayArgv( int n, char *buffer, int bufferLength ); char *G_SayConcatArgs( int start ); void G_DecolorString( char *in, char *out ); +void G_LeaveTeam( gentity_t *self ); void G_ChangeTeam( gentity_t *ent, pTeam_t newTeam ); void G_SanitiseName( char *in, char *out ); void G_PrivateMessage( gentity_t *ent );