void CClientPlayerManager::DoPulse ( void )
{
    unsigned long ulCurrentTime = CClientTime::GetTime ();
    CClientPlayer * pPlayer = NULL;
    vector < CClientPlayer* > ::const_iterator iter = m_Players.begin ();
    for ( ; iter != m_Players.end (); ++iter )
    {
        pPlayer = *iter;

        if ( !pPlayer->IsLocalPlayer () )
        {
            // Pulse voice data if voice is enabled
            if ( g_pClientGame->GetVoiceRecorder()->IsEnabled() && pPlayer->GetVoice() )
                pPlayer->GetVoice()->DoPulse();

            // Flag him with connection error if its been too long since last puresync and force his position
            unsigned long ulLastPuresyncTime = pPlayer->GetLastPuresyncTime ();
            bool bHasConnectionTrouble = ( ulLastPuresyncTime != 0 && ulCurrentTime >= ulLastPuresyncTime + REMOTE_PLAYER_CONNECTION_TROUBLE_TIME );
            if ( bHasConnectionTrouble && !g_pClientGame->IsDownloadingBigPacket () && !pPlayer->IsDeadOnNetwork () )
            {
                pPlayer->SetHasConnectionTrouble ( true );

                // Reset his controller so he doesn't get stuck shooting or something
                CControllerState State;
                memset ( &State, 0, sizeof ( CControllerState ) );
                pPlayer->SetControllerState ( State );

                // Grab his vehicle if any and force the position to where he was last sync
                CClientVehicle* pVehicle = pPlayer->GetOccupiedVehicle ();
                if ( pVehicle )
                {
                    // Is he driving the vehicle?
                    if ( pPlayer->GetOccupiedVehicleSeat () == 0 )
                    {
                        // Force his position to where he was last sync
                        pVehicle->SetPosition ( pPlayer->GetLastPuresyncPosition () );
                        pVehicle->SetMoveSpeed ( CVector ( 0, 0, 0 ) );
                        pVehicle->SetTurnSpeed ( CVector ( 0, 0, 0 ) );
                        pPlayer->ResetInterpolation ();
                    }
                }
                else
                {
                    // Force his position to where he was last sync
                    pPlayer->SetPosition ( pPlayer->GetLastPuresyncPosition () );
                    pPlayer->ResetInterpolation ();
                    pPlayer->SetMoveSpeed ( CVector ( 0, 0, 0 ) );
                    pPlayer->ResetInterpolation ();
                }
            }
            else
            {
                pPlayer->SetHasConnectionTrouble ( false );
            }
        }
    }
}
int CLuaFunctionDefs::GetSoundEffects ( lua_State* luaVM )
{
    CClientPlayer* pPlayer = NULL;
    CClientSound* pSound = NULL;
    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserDataOfType < CClientSound > ( ) )
    {
        argStream.ReadUserData ( pSound );
    }
    else if ( argStream.NextIsUserDataOfType < CClientPlayer > ( ) )
    {
        argStream.ReadUserData ( pPlayer );
    }
    else
    {
        m_pScriptDebugging->LogBadPointer ( luaVM, "sound/player", 1 );
        lua_pushboolean ( luaVM, false );
        return false;
    }

    if ( !argStream.HasErrors() )
    {
        if ( pSound )
        {
            std::map < std::string, int > iFxEffects = m_pManager->GetSoundManager()->GetFxEffects();
            lua_newtable ( luaVM );
            for ( std::map < std::string, int >::const_iterator iter = iFxEffects.begin(); iter != iFxEffects.end(); ++iter )
            {
                lua_pushboolean ( luaVM, pSound->IsFxEffectEnabled ( (*iter).second ) );
                lua_setfield ( luaVM, -2, (*iter).first.c_str () );
            }
            return 1;
        }
        else if ( pPlayer )
        {
            CClientPlayerVoice * pPlayerVoice = pPlayer->GetVoice ( );
            std::map < std::string, int > iFxEffects = m_pManager->GetSoundManager()->GetFxEffects();
            lua_newtable ( luaVM );
            for ( std::map < std::string, int >::const_iterator iter = iFxEffects.begin(); iter != iFxEffects.end(); ++iter )
            {
                lua_pushboolean ( luaVM, pPlayerVoice->IsFxEffectEnabled ( (*iter).second ) );
                lua_setfield ( luaVM, -2, (*iter).first.c_str () );
            }
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #3
0
CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsLocalPlayer ) : ClassInit ( this ), CClientPed ( pManager, 0, ID, bIsLocalPlayer )
{
    // Initialize
    m_pManager = pManager;
    m_bIsLocalPlayer = bIsLocalPlayer;

    SetTypeName ( "player" );

    m_bNametagColorOverridden = false;
    m_uiPing = 0;

    m_usLatency = 0;

    m_uiPlayerSyncCount = 0;
    m_uiKeySyncCount = 0;
    m_uiVehicleSyncCount = 0;

    m_ulLastPuresyncTime = 0;
    m_bHasConnectionTrouble = false;    

    m_bForce = false;
    m_bDoExtrapolatingAim = false;

    m_bNetworkDead = false;

    m_voice = NULL;

    // If it's the local player, add the model
    if ( m_bIsLocalPlayer )
    {
        // Set us as the local player in the player manager
        if ( !pManager->GetPlayerManager ()->GetLocalPlayer () )
        {
            pManager->GetPlayerManager ()->SetLocalPlayer ( this );
        }

        CClientPlayer * pLocalPlayer = this;
        // Enable voice playback for local player
        if ( pLocalPlayer->GetVoice() == NULL )
        {
            //If voice is enabled
            CClientPlayerVoice * pVoice = new CClientPlayerVoice ( this, g_pClientGame->GetVoiceRecorder() );
            pLocalPlayer->SetPlayerVoice ( pVoice );
        }
    }
    else
    {
        // Enable weapon processing for players
        m_remoteDataStorage->SetProcessPlayerWeapon ( true );

        // Enable voice playback for remote players
        if ( g_pClientGame->GetVoiceRecorder()->IsEnabled() ) //If voice is enabled
            m_voice = new CClientPlayerVoice ( this, g_pClientGame->GetVoiceRecorder() );
    }

    // Set all our default stats
    m_pTeam = NULL;

    m_bNametagShowing = true;
    m_ucNametagColorR = 255;
    m_ucNametagColorG = 255;
    m_ucNametagColorB = 255;
    m_ulLastNametagShow = 0;
    SetNametagText ( m_strNick );

    // Add us to the player list
    m_pManager->GetPlayerManager ()->AddToList ( this );

#ifdef MTA_DEBUG
    m_bShowingWepdata = false;
#endif
    m_LastPuresyncType = PURESYNC_TYPE_NONE;
}