Beispiel #1
0
//DHL - Skillet - Fix ammo exploits
void CWeaponFrag::Drop( const Vector &vecVelocity )
{
    if ( !HasPrimaryAmmo() )
    {
        //BaseClass::Drop( vecVelocity );
        SUB_Remove();
        return;
    }

    if ( !GetOwner() )
        return;

    DecrementAmmo( GetOwner() );
    Reload(); //Do draw animation and stuff

#ifndef CLIENT_DLL
    CBasePlayer *owner = ToBasePlayer(GetOwner());

    Vector vThrowPos = owner->Weapon_ShootPosition() - Vector(0,0,12);
    //Create a grenade
    CBaseCombatWeapon* pGrenade;
    pGrenade = (CBaseCombatWeapon *)CBaseEntity::Create( "weapon_frag", vThrowPos, vec3_angle, NULL );
    if ( !pGrenade )
        return;

    pGrenade->SetRemoveable( true );

    //If it was dropped then there's no need to respawn it.
    pGrenade->AddSpawnFlags( SF_NORESPAWN );

    pGrenade->StopAnimation();
    pGrenade->StopFollowingEntity( );
    pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY );
    // clear follow stuff, setup for collision
    pGrenade->SetGravity(1.0);
    pGrenade->m_iState = WEAPON_NOT_CARRIED;
    pGrenade->RemoveEffects( EF_NODRAW );
    pGrenade->FallInit();
    pGrenade->SetGroundEntity( NULL );
    pGrenade->SetTouch(NULL);

    pGrenade->SetOwnerEntity( NULL );
    pGrenade->SetOwner( NULL );

    //Toss it in the direction of the player's view
    Vector vecNewVelocity;
    Vector vecDir;
    owner->EyeVectors( &vecDir );
    vecNewVelocity = ( vecDir * 500.0f );

    IPhysicsObject *pObj = pGrenade->VPhysicsGetObject();
    if ( pObj != NULL )
    {
        AngularImpulse angImp( 200, 200, 200 );
        pObj->AddVelocity( &vecNewVelocity, &angImp );
    }
#endif
}