diff --git a/dlls/client.cpp b/dlls/client.cpp index 569b1a53..32b6bebd 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -556,20 +556,30 @@ void ClientCommand( edict_t *pEntity ) } else if( FStrEq( pcmd, "spectate" ) ) // clients wants to become a spectator { - // always allow proxies to become a spectator - if( ( pev->flags & FL_PROXY ) || allow_spectators.value ) + CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev ); + if( !pPlayer->IsObserver() ) { - CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev ); - - edict_t *pentSpawnSpot = g_pGameRules->GetPlayerSpawnSpot( pPlayer ); - pPlayer->StartObserver( pev->origin, VARS( pentSpawnSpot )->angles ); + // always allow proxies to become a spectator + if( ( pev->flags & FL_PROXY ) || allow_spectators.value ) + { + edict_t *pentSpawnSpot = g_pGameRules->GetPlayerSpawnSpot( pPlayer ); + pPlayer->StartObserver( pev->origin, VARS( pentSpawnSpot )->angles ); - // notify other clients of player switching to spectator mode - UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s switched to spectator mode\n", + // notify other clients of player switching to spectator mode + UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s switched to spectator mode\n", ( pev->netname && ( STRING( pev->netname ) )[0] != 0 ) ? STRING( pev->netname ) : "unconnected" ) ); + } + else + ClientPrint( pev, HUD_PRINTCONSOLE, "Spectator mode is disabled.\n" ); } else - ClientPrint( pev, HUD_PRINTCONSOLE, "Spectator mode is disabled.\n" ); + { + pPlayer->StopObserver(); + + // notify other clients of player left spectators + UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s has left spectator mode\n", + ( pev->netname && ( STRING( pev->netname ) )[0] != 0 ) ? STRING( pev->netname ) : "unconnected" ) ); + } } else if( FStrEq( pcmd, "specmode" ) ) // new spectator mode { diff --git a/dlls/observer.cpp b/dlls/observer.cpp index f3fc54a0..22fa3818 100644 --- a/dlls/observer.cpp +++ b/dlls/observer.cpp @@ -24,6 +24,10 @@ extern int gmsgCurWeapon; extern int gmsgSetFOV; +extern int gmsgTeamInfo; + +extern int g_teamplay; + // Find the next client in the game for this player to spectate void CBasePlayer::Observer_FindNextPlayer( bool bReverse ) { @@ -266,3 +270,22 @@ void CBasePlayer::Observer_SetMode( int iMode ) m_iObserverLastMode = iMode; } + +void CBasePlayer::StopObserver() +{ + // Turn off spectator + pev->iuser1 = pev->iuser2 = 0; + m_iHideHUD = 0; + + GetClassPtr( (CBasePlayer *)pev )->Spawn(); + pev->nextthink = -1; + + // Update Team Status + MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo ); + WRITE_BYTE( ENTINDEX( edict() ) ); // index number of primary entity + if( g_teamplay ) + WRITE_STRING( TeamID() ); + else + WRITE_STRING( "Players" ); + MESSAGE_END(); +} diff --git a/dlls/player.h b/dlls/player.h index 1c17556c..54e7fa85 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -255,6 +255,7 @@ public: void StartDeathCam( void ); void StartObserver( Vector vecPosition, Vector vecViewAngle ); + void StopObserver(); void AddPoints( int score, BOOL bAllowNegativeScore ); void AddPointsToTeam( int score, BOOL bAllowNegativeScore );