void CClientVehicleManager::DoPulse ( void )
{
    CClientVehicle * pVehicle = NULL;
    // Loop through our streamed-in vehicles
    vector < CClientVehicle * > cloneList = m_StreamedIn;
    vector < CClientVehicle* > ::iterator iter = cloneList.begin ();
    for ( ; iter != cloneList.end (); ++iter )
    {
        pVehicle = *iter;
        // We should have a game vehicle here
        assert ( pVehicle->GetGameVehicle () );
        pVehicle->StreamedInPulse ();
    }
}
Beispiel #2
0
CVehicle* CClientTask::GetParameterVehicle ( const char* szKey )
{
    // Grab the parameter, is it userdata?
    CLuaArgument* pArgument = GetParameter ( szKey );
    if ( pArgument && pArgument->GetType () == LUA_TLIGHTUSERDATA )
    {
        // Grab the player and verify it
        CClientVehicle* pVehicle = reinterpret_cast < CClientVehicle* > ( pArgument->GetLightUserData () );
        if ( VERIFY_VEHICLE ( pVehicle ) )
        {
            // Return the game vehicle
            return pVehicle->GetGameVehicle ();
        }
    }

    // Non-existing
    return NULL;
}
Beispiel #3
0
CClientVehicle * CStreamer::GetVehicleFromGameVehicle(IVVehicle * pGameVehicle)
{
	// Get the streamed in vehicles list
	std::list <CStreamableEntity *> * m_streamedVehicles = &m_streamedElements[ENTITY_TYPE_VEHICLE];

	// Loop through the streamed in vehicles list
	for(std::list<CStreamableEntity *>::iterator iter = m_streamedVehicles->begin(); iter != m_streamedVehicles->end(); iter++)
	{
		// Get the vehicle pointer
		CClientVehicle * pTestVehicle = reinterpret_cast<CClientVehicle *>(*iter);

		// Is this the vehicle we are looking for?
		if(pTestVehicle->GetGameVehicle()->GetVehicle() == pGameVehicle)
			return pTestVehicle;
	}

	// No vehicle found
	return NULL;
}
Beispiel #4
0
void CFoo::Test ( const char* szString )
{
    CClientManager* pManager = g_pClientGame->GetManager ();
    CClientPlayer* pLocal = pManager->GetPlayerManager ()->GetLocalPlayer ();
    CClientVehicleManager* pVehicleManager = pManager->GetVehicleManager ();
    CVector vecLocal;
    pLocal->GetPosition ( vecLocal );
    CClientCamera* pCamera = pManager->GetCamera ();



    // ChrML: Trying to reproduce mantis issue #2760
    if ( stricmp ( szString, "2760" ) == 0 )
    {
        vecLocal = CVector ( 0.0f, 0.0f, 5.0f );

        for ( int i = 0; i < 20; i++ )
        {
            vecLocal.fX += 5.0f;
            CClientPlayer* pPlayer = new CClientPlayer ( pManager, i + 50 );
            pPlayer->SetDeadOnNetwork ( false );
            pPlayer->SetModel ( 168 + i );
            pPlayer->AttachTo ( NULL );
            pPlayer->SetFrozen ( false );
            pPlayer->RemoveAllWeapons ();
            pPlayer->Teleport ( vecLocal );
            pPlayer->SetCameraRotation ( 0 );
            pPlayer->ResetInterpolation ();
            pPlayer->SetMoveSpeed ( CVector () );
            pPlayer->SetHealth ( 100.0f );
            pPlayer->SetArmor ( 0 );
            pPlayer->SetCurrentRotation ( 0 );
            pPlayer->SetInterior ( 0 );
            pPlayer->SetDimension ( 0 );
        }

        pLocal->SetDeadOnNetwork ( false );
        pLocal->SetModel ( 145 );
        pLocal->AttachTo ( NULL );
        pLocal->SetFrozen ( false );
        pLocal->RemoveAllWeapons ();
        pLocal->Teleport ( vecLocal );
        pLocal->SetCameraRotation ( 0 );
        pLocal->ResetInterpolation ();
        pLocal->SetMoveSpeed ( CVector () );
        pLocal->SetHealth ( 100.0f );
        pLocal->SetArmor ( 0 );
        pLocal->SetCurrentRotation ( 0 );
        pLocal->SetInterior ( 0 );
        pLocal->SetDimension ( 0 );
        g_pClientGame->SetAllDimensions ( 0 );

        // Reset return position so we can't warp back to where we were if local player
        g_pClientGame->GetNetAPI ()->ResetReturnPosition ();

        // Make sure the camera is normal
        pCamera->SetFocusToLocalPlayer ();
        pCamera->FadeIn ( 0.0f );
    }
    




    // Player load crash
    else if ( stricmp ( szString, "2741" ) == 0 )
    {
        bFoo_PlayerLimitCrash = true;
    }


    // 
    else if ( strnicmp ( szString, "interp", 6 ) == 0 )
    {
        if ( pVehicleManager->Count () > 0 )
        {
            CClientVehicle* pVehicle = *pVehicleManager->IterBegin ();

            float fdelta = atof ( szString + 7 );

            CVector vecT;
            pVehicle->GetPosition ( vecT );
            vecT.fZ = fdelta;
            pVehicle->SetTargetPosition ( vecT, TICK_RATE );

            g_pCore->ChatPrintf ( "Done %f", false, fdelta );

            static_cast < CDeathmatchVehicle* > ( pVehicle )->SetIsSyncing ( false );
        }
    }


    // 
    else if ( strnicmp ( szString, "interr", 6 ) == 0 )
    {
        if ( pVehicleManager->Count () > 0 )
        {
            CClientVehicle* pVehicle = *pVehicleManager->IterBegin ();

            CVector vecT;
            pVehicle->GetRotationDegrees ( vecT );
            vecT.fZ = atof ( szString + 7 );
            pVehicle->SetTargetRotation ( vecT, TICK_RATE );

            g_pCore->ChatPrintf ( "Done %f", false, atof ( szString + 7 ) );

            static_cast < CDeathmatchVehicle* > ( pVehicle )->SetIsSyncing ( false );
        }
    }


    else if ( stricmp ( szString, "choke" ) == 0 )
    {
        g_pClientGame->GetLocalPlayer ()->SetChoking ( true );
    }


    // 
    else if ( strnicmp ( szString, "static", 6 ) == 0 )
    {
        if ( pVehicleManager->Count () > 0 )
        {
            CClientVehicle* pVehicle = *pVehicleManager->IterBegin ();

            pVehicle->GetGameVehicle ()->SetRemap ( atoi ( szString + 7 ) );
            g_pCore->ChatPrintf ( "Set %i", false, atoi ( szString + 7 ) );
        }
    }


    // 
    else if ( strnicmp ( szString, "getmass", 7 ) == 0 )
    {
        CClientVehicle* pVehicle = pLocal->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            g_pCore->ChatPrintf ( "Mass == %f", false, pVehicle->GetGameVehicle ()->GetMass () );
        }
    }

    else if ( strnicmp ( szString, "setmass", 7 ) == 0 )
    {
        CClientVehicle* pVehicle = pLocal->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            pVehicle->GetGameVehicle ()->SetMass ( atof ( szString + 8 ) );
            g_pCore->ChatPrintf ( "Set mass to %f", false, pVehicle->GetGameVehicle ()->GetMass () );
        }
    }


    // 
    /*
    else if ( strnicmp ( szString, "setmm", 5 ) == 0 )
    {
        CClientVehicle* pVehicle = pLocal->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            float fVal = atof ( szString + 6);
            szString += 4;
            float* fMass = (float*) atoi ( szString + 6 );
            *fMass = fVal;
            g_pCore->ChatPrintf ( "Set %X to %f", false, fMass, fVal );
        }
    }
    */

    /*
    else if ( stricmp ( szString, "getmm" ) == 0 )
    {
        CClientVehicle* pVehicle = pLocal->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            float* fMass = (float*) atoi ( szString );
            g_pCore->ChatPrintf ( "Get %f", false, *fMass );
        }
    }
    */



    /*
    else if ( stricmp ( szString, "dump" ) == 0 )
    {
        FILE* poo = fopen ( "vehs.txt", "w+" );
        if ( poo )
        {
            tHandlingData* pHandling = (tHandlingData*) 0xC2B9E0;
            unsigned int uiIndex = 0;
            for ( ; uiIndex < 219; uiIndex++ )
            {
                fprintf ( poo, "\n\n\n\n####### VEHICLE ID %u #######\n", uiIndex );

                fprintf ( poo, "fMass = %f\n", pHandling->fMass );
                fprintf ( poo, "fUnknown1 = %f\n", pHandling->fUnknown1 );
                fprintf ( poo, "fTurnMass = %f\n", pHandling->fTurnMass );

                fprintf ( poo, "fDragCoeff = %f\n", pHandling->fDragCoeff );
                fprintf ( poo, "vecCenterOfMass = %f, %f, %f\n", pHandling->vecCenterOfMass.fX, pHandling->vecCenterOfMass.fY, pHandling->vecCenterOfMass.fZ );
                fprintf ( poo, "uiPercentSubmerged = %u\n", pHandling->uiPercentSubmerged );

                fprintf ( poo, "fUnknown2 = %f\n", pHandling->fUnknown2 );

                fprintf ( poo, "fTractionMultiplier = %f\n", pHandling->fTractionMultiplier );

                fprintf ( poo, "Transmission.fUnknown [0] = %f\n", pHandling->Transmission.fUnknown [0] );
                fprintf ( poo, "Transmission.fUnknown [1] = %f\n", pHandling->Transmission.fUnknown [1] );
                fprintf ( poo, "Transmission.fUnknown [2] = %f\n", pHandling->Transmission.fUnknown [2] );
                fprintf ( poo, "Transmission.fUnknown [3] = %f\n", pHandling->Transmission.fUnknown [3] );
                fprintf ( poo, "Transmission.fUnknown [4] = %f\n", pHandling->Transmission.fUnknown [4] );
                fprintf ( poo, "Transmission.fUnknown [5] = %f\n", pHandling->Transmission.fUnknown [5] );
                fprintf ( poo, "Transmission.fUnknown [6] = %f\n", pHandling->Transmission.fUnknown [6] );
                fprintf ( poo, "Transmission.fUnknown [7] = %f\n", pHandling->Transmission.fUnknown [7] );
                fprintf ( poo, "Transmission.fUnknown [8] = %f\n", pHandling->Transmission.fUnknown [8] );
                fprintf ( poo, "Transmission.fUnknown [9] = %f\n", pHandling->Transmission.fUnknown [9] );
                fprintf ( poo, "Transmission.fUnknown [10] = %f\n", pHandling->Transmission.fUnknown [10] );
                fprintf ( poo, "Transmission.fUnknown [11] = %f\n", pHandling->Transmission.fUnknown [11] );
                fprintf ( poo, "Transmission.fUnknown [12] = %f\n", pHandling->Transmission.fUnknown [12] );
                fprintf ( poo, "Transmission.fUnknown [13] = %f\n", pHandling->Transmission.fUnknown [13] );
                fprintf ( poo, "Transmission.fUnknown [14] = %f\n", pHandling->Transmission.fUnknown [14] );
                fprintf ( poo, "Transmission.fUnknown [15] = %f\n", pHandling->Transmission.fUnknown [15] );
                fprintf ( poo, "Transmission.fUnknown [16] = %f\n", pHandling->Transmission.fUnknown [16] );
                fprintf ( poo, "Transmission.fUnknown [17] = %f\n", pHandling->Transmission.fUnknown [17]  );

                fprintf ( poo, "Transmission.ucDriveType = %c\n", pHandling->Transmission.ucDriveType );
                fprintf ( poo, "Transmission.ucEngineType = %c\n", pHandling->Transmission.ucEngineType );
                fprintf ( poo, "Transmission.ucNumberOfGears = %u\n", pHandling->Transmission.ucNumberOfGears );
                fprintf ( poo, "Transmission.ucUnknown = %u\n", pHandling->Transmission.ucUnknown );

                fprintf ( poo, "Transmission.uiHandlingFlags = 0x%X\n", pHandling->Transmission.uiHandlingFlags );

                fprintf ( poo, "Transmission.fEngineAccelleration = %f\n", pHandling->Transmission.fEngineAccelleration );
                fprintf ( poo, "Transmission.fEngineInertia = %f\n", pHandling->Transmission.fEngineInertia );
                fprintf ( poo, "Transmission.fMaxVelocity = %f\n", pHandling->Transmission.fMaxVelocity );

                fprintf ( poo, "Transmission.fUnknown2 [0] = %f\n", pHandling->Transmission.fUnknown2 [0]  );
                fprintf ( poo, "Transmission.fUnknown2 [1] = %f\n", pHandling->Transmission.fUnknown2 [1]  );
                fprintf ( poo, "Transmission.fUnknown2 [2] = %f\n", pHandling->Transmission.fUnknown2 [2]  );

                fprintf ( poo, "fBrakeDecelleration = %f\n", pHandling->fBrakeDecelleration );
                fprintf ( poo, "fBrakeBias = %f\n", pHandling->fBrakeBias );
                fprintf ( poo, "bABS = %u\n", pHandling->bABS );

                fprintf ( poo, "fSteeringLock = %f\n", pHandling->fSteeringLock );
                fprintf ( poo, "fTractionLoss = %f\n", pHandling->fTractionLoss );
                fprintf ( poo, "fTractionBias = %f\n", pHandling->fTractionBias );

                fprintf ( poo, "fSuspensionForceLevel = %f\n", pHandling->fSuspensionForceLevel );
                fprintf ( poo, "fSuspensionDamping = %f\n", pHandling->fSuspensionDamping );
                fprintf ( poo, "fSuspensionHighSpdDamping = %f\n", pHandling->fSuspensionHighSpdDamping );
                fprintf ( poo, "fSuspensionUpperLimit = %f\n", pHandling->fSuspensionUpperLimit );
                fprintf ( poo, "fSuspensionLowerLimit = %f\n", pHandling->fSuspensionLowerLimit );
                fprintf ( poo, "fSuspensionFrontRearBias = %f\n", pHandling->fSuspensionFrontRearBias );
                fprintf ( poo, "fSuspensionAntidiveMultiplier = %f\n", pHandling->fSuspensionAntidiveMultiplier );

                fprintf ( poo, "fCollisionDamageMultiplier = %f\n", pHandling->fCollisionDamageMultiplier );

                fprintf ( poo, "uiModelFlags = %X\n", pHandling->uiModelFlags );
                fprintf ( poo, "uiHandlingFlags = %X\n", pHandling->uiHandlingFlags );
                fprintf ( poo, "fSeatOffsetDistance = %f\n", pHandling->fSeatOffsetDistance );
                fprintf ( poo, "uiMonetary = %u\n", pHandling->uiMonetary );

                fprintf ( poo, "ucHeadLight = 0x%X\n", pHandling->ucHeadLight );
                fprintf ( poo, "ucTailLight = 0x%X\n", pHandling->ucTailLight );
                fprintf ( poo, "ucAnimGroup = 0x%X\n", pHandling->ucAnimGroup );
                fprintf ( poo, "ucUnused = 0x%X\n", pHandling->ucUnused );

                fprintf ( poo, "iUnknown7 = %f, %X\n", pHandling->iUnknown7, pHandling->iUnknown7 );

                pHandling += 1;
            }


            g_pCore->ChatPrintf ( "Dumped", false );
            fclose ( poo );
        }
    }
    */



    else if ( strnicmp ( szString, "moveug", 6 ) == 0 )
    {
        if ( pVehicleManager->Count () > 0 )
        {
            CClientVehicle* pVehicle = *pVehicleManager->IterBegin ();

            /*
            CClientPed* pModel = pVehicle->GetOccupant ( 0 );
            if ( !pModel )
            {
                CClientPlayer* pPlayer = new CClientPlayer ( g_pClientGame->GetManager (), 50 );
                pModel = pPlayer->LoadModel ( 0 );
                pModel->WarpIntoVehicle ( pVehicle );
            }
            */

            

            pVehicle->RemoveTargetPosition ();
            pVehicle->RemoveTargetRotation ();


            CVector vecT;
            pVehicle->GetPosition ( vecT );
            vecT.fZ = atof ( szString + 7 );
            pVehicle->SetPosition ( vecT );

            g_pCore->ChatPrintf ( "Done", false );
        }
    }

    else if ( strnicmp ( szString, "nocol", 5 ) == 0 )
    {
        if ( pVehicleManager->Count () > 0 )
        {
            CClientVehicle* pVehicle = *pVehicleManager->IterBegin ();
            pVehicle->SetCollisionEnabled ( false );

            g_pCore->ChatPrintf ( "Done", false );
        }
    }

    else if ( stricmp ( szString, "resetdamage" ) == 0 )
    {
        g_pClientGame->GetPlayerManager ()->GetLocalPlayer ()->GetGamePlayer ()->ResetLastDamage ();
    }


    else if ( strnicmp ( szString, "fuckveh", 7 ) == 0 )
    {
        CClientVehicle* pVehicle = pLocal->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            pVehicle->SetTargetPosition ( CVector ( 0, 0, 0 ), TICK_RATE );
            pVehicle->SetTargetRotation ( CVector ( 0, 0, 0 ), TICK_RATE );

            g_pCore->ChatPrintf ( "Done", false );
        }
    }

    else if ( stricmp ( szString, "ped" ) == 0 )
    {
        CClientPed* pPed = new CClientPed ( g_pClientGame->GetManager (), INVALID_ELEMENT_ID, 9 );
        vecLocal.fX += 5.0f;
        pPed->SetPosition ( vecLocal );
    }

    else if ( strnicmp ( szString, "callit", 6 ) == 0 )
    {
        FILE* pFile = fopen ( "C:/dump.txt", "w+" );

        for ( int i = 0; i < 400; i++ )
        {
            int iIndex = i;
            const char* szName = NULL;
            _asm
            {
                mov     eax, 0x4D3A30
                push    iIndex
                call    eax
                mov     szName, eax
                add     esp, 4
            }

            fprintf ( pFile, "%i: %s\n", iIndex, szName );
        }

        fclose ( pFile );
    }


    else if ( strnicmp ( szString, "veh", 3 ) == 0 )
    {
        int i = 600;
        FILE* p = fopen ( "C:/dump.txt", "w+" );

        for ( int a = 0; a < 13; a++ )
        {
            g_pGame->GetModelInfo ( i )->AddRef ( true );

            CVehicle* pVehicle = g_pGame->GetPools ()->AddVehicle ( (eVehicleTypes)i );
            DWORD* dw2 = (DWORD*)(((DWORD)pVehicle->GetVehicleInterface ()) + 0xE1 * 4 );
            DWORD dw = *dw2;
            dw = dw + 4;
            dw = dw - 0xC2B9E0;
            dw = dw / 224;
            fprintf ( p, "Array [%u] = %u;\n", i, dw );

            g_pGame->GetPools ()->RemoveVehicle ( pVehicle );

            fflush ( p );

            g_pGame->GetModelInfo ( i )->RemoveRef ( );

            i++;
        }

        fclose ( p );
    }


    else if ( strnicmp ( szString, "groups", 6 ) == 0 )
    {
        FILE* pFile = fopen ( "C:/dump.txt", "w+" );


        int i = 0;
        for ( ; i < 139; i++ )
        {
            fprintf ( pFile, "==%s [%s] (%i)==\n", pGroups [i].szGroupName, pGroups [i].szSomething, i );
            int i2 = 0;
            for ( ; i2 < pGroups [i].ulAnimCount; i2++ )
            {
                const char* szAnimName = pGroups [i].pAnimNames [i2];
                if ( szAnimName [0] )
                {
                    fprintf ( pFile, "''%i'': %s<br>\n", i2, szAnimName );
                }
            }

            fprintf ( pFile, "\n" );
        }

        fclose ( pFile );
    }


    else if ( strnicmp ( szString, "getshot", 7 ) == 0 )
    {
        if ( pLocal->GetGamePlayer ()->GetCanBeShotInVehicle () )
        {
            g_pCore->ChatEcho ( "true" );
        }
        else
        {
            g_pCore->ChatEcho ( "false" );
        }
    }

    else if ( strnicmp ( szString, "gettest", 7 ) == 0 )
    {
        if ( pLocal->GetGamePlayer ()->GetTestForShotInVehicle () )
        {
            g_pCore->ChatEcho ( "true" );
        }
        else
        {
            g_pCore->ChatEcho ( "false" );
        }
    }


    else if ( strnicmp ( szString, "setshot", 7 ) == 0 )
    {
        pLocal->GetGamePlayer ()->SetCanBeShotInVehicle ( true );
    }


    else if ( strnicmp ( szString, "settest", 8 ) == 0 )
    {
        pLocal->GetGamePlayer ()->SetTestForShotInVehicle ( true );
    }


    else if ( stricmp ( szString, "applytest" ) == 0 )
    {
        DWORD oldProt, oldProt2;
        VirtualProtect((LPVOID)0x5E8FFB,6,PAGE_EXECUTE_READWRITE,&oldProt);		

        *(unsigned char*) (0x5E8FFB ) = 0x90;
        *(unsigned char*) (0x5E8FFC ) = 0x90;
        *(unsigned char*) (0x5E8FFD ) = 0x90;
        *(unsigned char*) (0x5E8FFE ) = 0x90;
        *(unsigned char*) (0x5E8FFF ) = 0x90;
        *(unsigned char*) (0x5E9000 ) = 0x90;

        VirtualProtect((LPVOID)0x5E8FFB,6,oldProt,&oldProt2); 
    }
}
Beispiel #5
0
void CNametags::DrawDefault()
{
    // Grab the resolution width and height
    static float fResWidth = static_cast<float>(g_pCore->GetGraphics()->GetViewportWidth());
    static float fResHeight = static_cast<float>(g_pCore->GetGraphics()->GetViewportHeight());

    // Got any players that are not local?
    if (m_pPlayerManager->Count() <= 1)
        return;

    list<CClientPlayer*> playerTags;

    // Grab the local player
    CClientPlayer* pLocalPlayer = m_pPlayerManager->GetLocalPlayer();
    if (!pLocalPlayer)
        return;

    CClientVehicle* pSniperTargetedVehicle = NULL;
    CClientPlayer*  pSniperTargetedPlayer = NULL;

    // Grab our current weapon slot. Use screen center if melee or none
    eWeaponSlot eSlot = pLocalPlayer->GetCurrentWeaponSlot();
    if (eSlot >= WEAPONSLOT_TYPE_HANDGUN && eSlot <= WEAPONSLOT_TYPE_RIFLE)
    {
        CVector vecOrigin, vecTarget;
        pLocalPlayer->GetShotData(&vecOrigin, &vecTarget);

        // Ignore the local player for this
        pLocalPlayer->WorldIgnore(true);

        // Do the raycast
        CColPoint*        pColPoint = NULL;
        CEntity*          pEntity = NULL;
        SLineOfSightFlags flags;
        flags.bCheckBuildings = true;
        flags.bCheckVehicles = true;
        flags.bCheckPeds = true;
        flags.bCheckObjects = true;
        flags.bCheckDummies = true;
        flags.bSeeThroughStuff = true;
        flags.bIgnoreSomeObjectsForCamera = false;
        flags.bShootThroughStuff = true;
        g_pGame->GetWorld()->ProcessLineOfSight(&vecOrigin, &vecTarget, &pColPoint, &pEntity, flags);
        if (pColPoint)
            pColPoint->Destroy();

        // Un-ignore the local player
        pLocalPlayer->WorldIgnore(false);

        // Did we find an entity?
        if (pEntity)
        {
            // Grab the CClientEntity belonging to this game_sa entity
            CClientEntity* pClientEntity = reinterpret_cast<CClientEntity*>(pEntity->GetStoredPointer());
            if (pClientEntity)
            {
                // Is it a vehicle? Is it a ped?
                eClientEntityType EntityType = pClientEntity->GetType();
                switch (EntityType)
                {
                    case CCLIENTVEHICLE:
                    {
                        pSniperTargetedVehicle = static_cast<CClientVehicle*>(pClientEntity);
                        break;
                    }
                    case CCLIENTPLAYER:
                    {
                        pSniperTargetedPlayer = static_cast<CClientPlayer*>(pClientEntity);
                        break;
                    }
                    default:
                        break;
                }
            }
        }
    }

    // Grab the local player vehicle
    CClientVehicle* pLocalVehicle = pLocalPlayer->GetOccupiedVehicle();
    CVehicle*       pLocalGameVehicle = NULL;
    if (pLocalVehicle)
        pLocalGameVehicle = pLocalVehicle->GetGameVehicle();

    CMatrix CameraMatrix;
    g_pGame->GetCamera()->GetMatrix(&CameraMatrix);

    // Remove collision from our local vehicle (if we have one)
    if (pLocalVehicle)
        pLocalVehicle->WorldIgnore(true);

    // Draw the nametags we need to
    CVector                                     vecPlayerPosition;
    CClientVehicle*                             pPlayerVehicle = NULL;
    float                                       fDistanceExp;
    bool                                        bCollision;
    CColPoint*                                  pColPoint = NULL;
    CEntity*                                    pGameEntity = NULL;
    CClientEntity*                              pEntity = NULL;
    CClientPlayer*                              pPlayer;
    CClientStreamElement*                       pElement;
    list<CClientStreamElement*>::const_iterator iter = m_pPlayerStreamer->ActiveElementsBegin();
    for (; iter != m_pPlayerStreamer->ActiveElementsEnd(); ++iter)
    {
        pElement = *iter;
        if (!pElement->IsStreamedIn())
            continue;
        if (pElement->GetType() != CCLIENTPLAYER)
            continue;
        pPlayer = static_cast<CClientPlayer*>(pElement);
        if (pPlayer->IsLocalPlayer())
            continue;

        // Get the distance from the camera
        pPlayer->GetPosition(vecPlayerPosition);
        fDistanceExp = pPlayer->GetExpDistance();
        pPlayerVehicle = pPlayer->GetOccupiedVehicle();

        // Is he in the same vehicle as the local player?
        if ((pSniperTargetedPlayer == pPlayer) || (pSniperTargetedVehicle && pSniperTargetedVehicle == pPlayerVehicle) ||
            (pLocalVehicle && pLocalVehicle == pPlayerVehicle) || (fDistanceExp < DEFAULT_VIEW_RANGE_EXP && pPlayer->IsOnScreen()))
        {
            SLineOfSightFlags flags;
            flags.bCheckBuildings = true;
            flags.bCheckVehicles = true;
            flags.bCheckPeds = false;
            flags.bCheckObjects = true;
            bCollision = g_pCore->GetGame()->GetWorld()->ProcessLineOfSight(&CameraMatrix.vPos, &vecPlayerPosition, &pColPoint, &pGameEntity, flags);
            if (!bCollision || (pGameEntity && pPlayerVehicle && pGameEntity == pPlayerVehicle->GetGameEntity()))
            {
                pPlayer->SetNametagDistance(sqrt(fDistanceExp));
                playerTags.push_front(pPlayer);
            }

            // Destroy the colpoint
            if (pColPoint)
                pColPoint->Destroy();
        }
    }

    // Readd collision from our local vehicle (if we have one)
    if (pLocalVehicle)
        pLocalVehicle->WorldIgnore(false);

    // Draw each player's nametag
    float                          fAlphaModifier;
    unsigned char                  ucAlpha;
    float                          fDistance;
    list<CClientPlayer*>::iterator iterTags = playerTags.begin();
    for (; iterTags != playerTags.end(); ++iterTags)
    {
        pPlayer = *iterTags;
        fDistance = pPlayer->GetNametagDistance();

        static float fFullAlphaDistance = 7.0f;
        if ((fDistance < fFullAlphaDistance) || (pSniperTargetedPlayer && pSniperTargetedPlayer == pPlayer) ||
            (pSniperTargetedVehicle && pSniperTargetedVehicle == pPlayer->GetOccupiedVehicle()))
        {
            fAlphaModifier = 1.0f;
        }
        else
        {
            fAlphaModifier = 1.0f - ((fDistance - fFullAlphaDistance) / (DEFAULT_VIEW_RANGE - fFullAlphaDistance));
        }

        // Calculate the alpha for the nametag
        ucAlpha = static_cast<unsigned char>(180.0f * fAlphaModifier);

        // Draw the tag
        DrawTagForPlayer(pPlayer, ucAlpha);
    }
}
void CClientWeapon::Fire ( bool bServerFire )
{

    if ( !m_pWeapon || !m_pObject || ( !IsLocalEntity ( ) && m_pOwner != g_pClientGame->GetLocalPlayer ( ) && bServerFire == false ) ) return;
    switch ( m_Type )
    {
        case WEAPONTYPE_PISTOL:
        case WEAPONTYPE_PISTOL_SILENCED:
        case WEAPONTYPE_DESERT_EAGLE:
#ifdef SHOTGUN_TEST
        case WEAPONTYPE_SHOTGUN: 
        case WEAPONTYPE_SAWNOFF_SHOTGUN:
        case WEAPONTYPE_SPAS12_SHOTGUN:
#endif
        case WEAPONTYPE_MICRO_UZI:
        case WEAPONTYPE_MP5:
        case WEAPONTYPE_AK47:
        case WEAPONTYPE_M4:
        case WEAPONTYPE_TEC9:
        case WEAPONTYPE_COUNTRYRIFLE:
        case WEAPONTYPE_SNIPERRIFLE:
        case WEAPONTYPE_MINIGUN:
        {
            CMatrix matOrigin;
            GetMatrix ( matOrigin );

            CVector vecTarget;
            float fDistance = m_pWeaponInfo->GetWeaponRange ();
            if ( m_targetType == TARGET_TYPE_ENTITY )
            {
                if ( m_pTarget )
                {
                    if ( m_pTarget->GetType ( ) == CCLIENTPED || m_pTarget->GetType ( ) == CCLIENTPLAYER )
                    {
                        CClientPed * pPed = (CClientPed *) (CClientEntity *) m_pTarget;
                        pPed->GetBonePosition( m_targetBone, vecTarget );
                    }
                    else
                    {
                        if ( m_pTarget->GetType() == CCLIENTVEHICLE )
                        {
                            if ( m_itargetWheel <= MAX_WHEELS )
                            {
                                CClientVehicle * pTarget = (CClientVehicle*)(CClientEntity *)m_pTarget;
                                vecTarget = pTarget->GetGameVehicle()->GetWheelPosition ( (eWheels)m_itargetWheel );
                            }
                            else
                                m_pTarget->GetPosition( vecTarget );
                        }
                        else
                            m_pTarget->GetPosition( vecTarget );
                    }
                    if ( m_weaponConfig.bShootIfTargetOutOfRange == false && (matOrigin.GetPosition() - vecTarget).Length() >= fDistance )
                    {
                        return;
                    }
                }
                else
                {
                    ResetWeaponTarget ( );
                }
            }
            else if ( m_targetType == TARGET_TYPE_VECTOR )
            {
                vecTarget = m_vecTarget;
                if ( m_weaponConfig.bShootIfTargetOutOfRange == false && (matOrigin.GetPosition() - vecTarget).Length() >= fDistance )
                {
                    return;
                }
            }
            else
            {
#ifndef SHOTGUN_TEST
                CVector vecFireOffset = *m_pWeaponInfo->GetFireOffset ();
                matOrigin = CMatrix( vecFireOffset, m_vecFireRotationNoTarget ) * matOrigin;
#endif
                CVector vecDirection ( 1, 0, 0 );
                vecDirection *= fDistance;
                vecTarget = matOrigin.TransformVector( vecDirection );
            }


            // Save
            short sDamage = m_pWeaponInfo->GetDamagePerHit ( );
            float fAccuracy = m_pWeaponInfo->GetAccuracy ( );
            float fTargetRange = m_pWeaponInfo->GetTargetRange ( );
            float fRange = m_pWeaponInfo->GetWeaponRange ( );

            // Set new
            m_pWeaponInfo->SetDamagePerHit ( m_pWeaponStat->GetDamagePerHit ( ) );
            m_pWeaponInfo->SetAccuracy ( m_pWeaponStat->GetAccuracy ( ) );
            m_pWeaponInfo->SetTargetRange ( m_pWeaponStat->GetTargetRange ( ) );
            m_pWeaponInfo->SetWeaponRange ( m_pWeaponStat->GetWeaponRange ( ) );

#ifdef SHOTGUN_TEST
            CVector vecFireOffset = *m_pWeaponInfo->GetFireOffset ();
            CMatrix matTemp = CMatrix( vecFireOffset ) * matOrigin;
#ifdef MARKER_DEBUG
            // Process
            m_pMarker->SetPosition ( matOrigin.GetPosition() );
#endif
            CVector vecTemp2;
            GetRotationDegrees(vecTemp2);
            vecTemp2.fZ -= 84.6f;
            SetRotationDegrees(vecTemp2);
            FireInstantHit ( matOrigin.GetPosition(), vecTarget-matOrigin.GetPosition(), matTemp.GetPosition() );
            vecTemp2.fZ += 84.6f;
            SetRotationDegrees(vecTemp2);
#else
            FireInstantHit ( matOrigin.GetPosition(), vecTarget, bServerFire );
#endif
            // Restore
            m_pWeaponInfo->SetDamagePerHit ( sDamage );
            m_pWeaponInfo->SetAccuracy ( fAccuracy );
            m_pWeaponInfo->SetTargetRange ( fTargetRange );
            m_pWeaponInfo->SetWeaponRange ( fRange );
            m_nAmmoInClip--;
            m_fireTimer.Reset();
            break;
        }
        default: break;
    }
}
Beispiel #7
0
void CClientWeapon::Fire ( void )
{       

    if ( !m_pWeapon || !m_pObject ) return;
    switch ( m_Type )
    {
        case WEAPONTYPE_PISTOL:
        case WEAPONTYPE_PISTOL_SILENCED:
        case WEAPONTYPE_DESERT_EAGLE:
#ifdef SHOTGUN_TEST
        case WEAPONTYPE_SHOTGUN: 
        case WEAPONTYPE_SAWNOFF_SHOTGUN:
        case WEAPONTYPE_SPAS12_SHOTGUN:
#endif
        case WEAPONTYPE_MICRO_UZI:
        case WEAPONTYPE_MP5:
        case WEAPONTYPE_AK47:
        case WEAPONTYPE_M4:
        case WEAPONTYPE_TEC9:
        case WEAPONTYPE_COUNTRYRIFLE:
        case WEAPONTYPE_SNIPERRIFLE:
        case WEAPONTYPE_MINIGUN:
        {
            CVector vecOrigin, vecRotation;
            GetPosition ( vecOrigin );

            if ( m_pAttachedToEntity )
            {

                GetRotationRadians ( vecRotation );

            }
            else
            {
                GetRotationRadians ( vecRotation );

                vecRotation = -vecRotation;
            }
            CVector vecTarget;
            float fDistance = m_pWeaponInfo->GetWeaponRange ();
            if ( m_targetType == TARGET_TYPE_ENTITY )
            {
                if ( m_pTarget )
                {
                    if ( m_pTarget->GetType ( ) == CCLIENTPED || m_pTarget->GetType ( ) == CCLIENTPLAYER )
                    {
                        CClientPed * pPed = (CClientPed *) (CClientEntity *) m_pTarget;
                        pPed->GetBonePosition( m_targetBone, vecTarget );
                    }
                    else
                    {
                        if ( m_pTarget->GetType() == CCLIENTVEHICLE )
                        {
                            if ( m_itargetWheel <= MAX_WHEELS )
                            {
                                CClientVehicle * pTarget = (CClientVehicle*)(CClientEntity *)m_pTarget;
                                vecTarget = pTarget->GetGameVehicle()->GetWheelPosition ( (eWheels)m_itargetWheel );
                            }
                            else
                                m_pTarget->GetPosition( vecTarget );
                        }
                        else
                            m_pTarget->GetPosition( vecTarget );
                    }
                    if ( m_weaponConfig.bShootIfTargetOutOfRange == false && (vecOrigin - vecTarget).Length() >= fDistance )
                    {
                        return;
                    }
                }
                else
                {
                    ResetWeaponTarget ( );
                }
            }
            else if ( m_targetType == TARGET_TYPE_VECTOR )
            {
                vecTarget = m_vecTarget;
                if ( m_weaponConfig.bShootIfTargetOutOfRange == false && (vecOrigin - vecTarget).Length() >= fDistance )
                {
                    return;
                }
            }
            else
            {
                CVector vecFireOffset = *m_pWeaponInfo->GetFireOffset ();
                RotateVector ( vecFireOffset, vecRotation );
#ifndef SHOTGUN_TEST
                vecOrigin += vecFireOffset;
#endif
                CVector vecDirection ( 1, 0, 0 );
                vecDirection *= fDistance;
                RotateVector ( vecDirection, vecRotation );
                vecTarget = vecOrigin + vecDirection;
            }


            // Save
            short sDamage = m_pWeaponInfo->GetDamagePerHit ( );
            float fAccuracy = m_pWeaponInfo->GetAccuracy ( );
            float fTargetRange = m_pWeaponInfo->GetTargetRange ( );
            float fRange = m_pWeaponInfo->GetWeaponRange ( );

            // Set new
            m_pWeaponInfo->SetDamagePerHit ( m_pWeaponStat->GetDamagePerHit ( ) );
            m_pWeaponInfo->SetAccuracy ( m_pWeaponStat->GetAccuracy ( ) );
            m_pWeaponInfo->SetTargetRange ( m_pWeaponStat->GetTargetRange ( ) );
            m_pWeaponInfo->SetWeaponRange ( m_pWeaponStat->GetWeaponRange ( ) );

            // Begin our lag compensation
            CPlayerPed* pOwnerPed = NULL;
            if ( m_pOwner && !m_pTarget && g_pClientGame->GetPlayerManager()->Exists(m_pOwner) ) // No need for compensation if we're hitting a target directly
            {
                pOwnerPed = m_pOwner->GetGamePlayer();
                //if ( g_pGame->m_pPreWeaponFireHandler && pOwnerPed )
                    //g_pGame->m_pPreWeaponFireHandler ( pOwnerPed, false );
            }
#ifdef SHOTGUN_TEST
            CVector vecTemp;
            CVector vecFireOffset = *m_pWeaponInfo->GetFireOffset ();
            RotateVector ( vecFireOffset, vecRotation );
            vecTemp = vecFireOffset;
            vecTemp += vecOrigin;
#ifdef MARKER_DEBUG
            // Process
            m_pMarker->SetPosition ( vecOrigin );
#endif
            CVector vecTemp2;
            GetRotationDegrees(vecTemp2);
            vecTemp2.fZ -= 84.6f;
            SetRotationDegrees(vecTemp2);
            FireInstantHit ( vecOrigin, vecTarget-vecOrigin, vecTemp );
            vecTemp2.fZ += 84.6f;
            SetRotationDegrees(vecTemp2);
#else
            FireInstantHit ( vecOrigin, vecTarget );
#endif
            // Restore
            m_pWeaponInfo->SetDamagePerHit ( sDamage );
            m_pWeaponInfo->SetAccuracy ( fAccuracy );
            m_pWeaponInfo->SetTargetRange ( fTargetRange );
            m_pWeaponInfo->SetWeaponRange ( fRange );

            // End our lag compensation
            //if ( g_pGame->m_pPostWeaponFireHandler && pOwnerPed )
                //g_pGame->m_pPostWeaponFireHandler ();

            m_nAmmoInClip--;
            m_fireTimer.Reset();
            break;
        }
        default: break;
    }
}