Beispiel #1
0
VOID WriteTargetDataForPed ( CPedSAInterface * pPed, DWORD vecTargetPos, CVector * origin )
{
    vecLastOrigin = *origin;

    // vecTargetPosition is a pointer to a vecTargetPosition*
    CPed * pTargetingPed = m_pools->GetPed ( (DWORD *)pPed );
    CPlayerPed* pTargetingPlayerPed = dynamic_cast < CPlayerPed* > ( pTargetingPed );
    if ( !pTargetingPlayerPed ) return;

    if ( m_pPreWeaponFireHandler && pTargetingPed )
    {
        m_pPreWeaponFireHandler ( pTargetingPlayerPed );
    }

    if ( !IsLocalPlayer( pTargetingPed ) )
    {
        CRemoteDataStorageSA * data = CRemoteDataSA::GetRemoteDataStorage ( pTargetingPlayerPed );
        if ( data )
        {
            if ( data->ProcessPlayerWeapon () )
            {
                DWORD dwPointerToVector = (DWORD)&data->m_shotSyncData.m_vecShotTarget;
                *(DWORD *)vecTargetPos = dwPointerToVector;
                if ( data->m_shotSyncData.m_bUseOrigin )
                    *origin = data->m_shotSyncData.m_vecShotOrigin;
            }
        }
    }
    else
    {
        // local ped firing
        LocalShotSyncData.m_vecShotOrigin = *origin;
    }
}
static void Event_BulletImpact ( void )
{
    if ( m_pBulletImpactHandler )
    {
        CPed * pInitiator = m_pools->GetPed ( (DWORD *)pBulletImpactInitiator );
        if ( pInitiator )
        {
            CEntity* pVictim = m_pools->GetEntity ( (DWORD *)pBulletImpactVictim );

            if ( IsLocalPlayer ( pInitiator ) )
            {
                // Correct weapon range if local player
                float fRange = pInitiator->GetCurrentWeaponRange ();
                CVector vecDir = *pBulletImpactEndPosition - *pBulletImpactStartPosition;
                float fLength = vecDir.Length ();
                if ( fRange < fLength )
                {
                    vecDir.Normalize ();
                    *pBulletImpactEndPosition = *pBulletImpactStartPosition + vecDir * fRange;
                }
                // These two will be the same when shooting without aiming, so correct them
                if ( vecLastLocalPlayerBulletStart == vecLastLocalPlayerBulletEnd )
                {
                    vecLastLocalPlayerBulletStart = *pBulletImpactStartPosition;
                    vecLastLocalPlayerBulletEnd = *pBulletImpactEndPosition;
                }
                m_pBulletImpactHandler ( pInitiator, pVictim, &vecLastLocalPlayerBulletStart, &vecLastLocalPlayerBulletEnd );
            }
            else
            {
                // Correct start postion if remote player
                CRemoteDataStorageSA * data = CRemoteDataSA::GetRemoteDataStorage ( pBulletImpactInitiator );
                if ( data )
                {
                    if ( data->ProcessPlayerWeapon () )
                    {
                        if ( data->m_shotSyncData.m_bRemoteBulletSyncVectorsValid )
                        {
                            *pBulletImpactStartPosition = data->m_shotSyncData.m_vecRemoteBulletSyncStart;
                            data->m_shotSyncData.m_bRemoteBulletSyncVectorsValid = false;

                            // Ensure weapon fire event gets the correct vectors
                            data->m_shotSyncData.m_vecShotOrigin = data->m_shotSyncData.m_vecRemoteBulletSyncStart;
                            data->m_shotSyncData.m_vecShotTarget = data->m_shotSyncData.m_vecRemoteBulletSyncEnd;
                        }
                        else
                            *pBulletImpactStartPosition = data->m_shotSyncData.m_vecShotOrigin;
                    }
                }
                m_pBulletImpactHandler ( pInitiator, pVictim, pBulletImpactStartPosition, pBulletImpactEndPosition );
            }
        }
        vecSavedBulletImpactEndPosition = *pBulletImpactEndPosition;    // Saved for vehicle damage event parameters
    }
}
// Return false to stop bullet impact to being calculated here
//   (False also assumes lag compensation movement has not been performed)
bool WriteTargetDataForPed ( CPedSAInterface * pPed, DWORD vecTargetPos, CVector * origin )
{
    bool bDoBulletTraceHere = true;
    vecLastOrigin = *origin;

    // vecTargetPosition is a pointer to a vecTargetPosition*
    CPed * pTargetingPed = m_pools->GetPed ( (DWORD *)pPed );
    CPlayerPed* pTargetingPlayerPed = dynamic_cast < CPlayerPed* > ( pTargetingPed );
    if ( !pTargetingPlayerPed ) return true;

    if ( m_pPreWeaponFireHandler && pTargetingPed )
    {
        bDoBulletTraceHere = m_pPreWeaponFireHandler ( pTargetingPlayerPed, true );
    }

    if ( !IsLocalPlayer( pTargetingPed ) )
    {
        CRemoteDataStorageSA * data = CRemoteDataSA::GetRemoteDataStorage ( pTargetingPlayerPed );
        if ( data )
        {
            if ( data->ProcessPlayerWeapon () )
            {
                DWORD dwPointerToVector = (DWORD)&data->m_shotSyncData.m_vecShotTarget;
                MemPutFast < DWORD > ( vecTargetPos, dwPointerToVector );
                if ( data->m_shotSyncData.m_bUseOrigin )
                    *origin = data->m_shotSyncData.m_vecShotOrigin;
            }

            // If current weapon has bullet sync enabled, don't allow firing
            return bDoBulletTraceHere;
        }
    }
    else
    {
        // local ped firing
        LocalShotSyncData.m_vecShotOrigin = *origin;
    }

    // Allow shot to be fired here
    return true;
}
Beispiel #4
0
VOID WriteGunDirectionDataForPed ( CPedSAInterface * pPedInterface, float * fGunDirectionX, float * fGunDirectionY, char * cGunDirection )
{        
    if ( !IsLocalPlayer ( pPedInterface ) )
    {
        CRemoteDataStorageSA * data = CRemoteDataSA::GetRemoteDataStorage ( pPedInterface );
        if ( data )
        {
            if ( data->ProcessPlayerWeapon () )
            {
                if ( fGunDirectionX && fGunDirectionY )
                {                
                    *fGunDirectionX = data->m_shotSyncData.m_fArmDirectionX;
                    *fGunDirectionY = data->m_shotSyncData.m_fArmDirectionY;
                }

                if ( cGunDirection )
                {
                    *cGunDirection = data->m_shotSyncData.m_cInVehicleAimDirection;
                }
            }
        }
    }
    else
    {
        // store it
        if ( fGunDirectionX && fGunDirectionY )
        {
            // Make sure our pitch is updated (fixes first-person weapons not moving)
            *fGunDirectionY = pGameInterface->GetCamera ()->Find3rdPersonQuickAimPitch ();

            LocalShotSyncData.m_fArmDirectionX = *fGunDirectionX;
            LocalShotSyncData.m_fArmDirectionY = *fGunDirectionY;
        }

        if ( cGunDirection )
        {
            LocalShotSyncData.m_cInVehicleAimDirection = *cGunDirection;
        }
    }
}