Wavelength Logo
tl.jpg (2351 bytes) blank.gif (837 bytes) tr.jpg (2446 bytes)
blank.gif (837 bytes)
Holster Animation by Trond
blank.gif (837 bytes)
We wanna see the holster animations!!!

Hasn`t it bothered you all the time playing HL? You never get to see the holster animations... Well, let`s do something about that.

First, check out your crowbar.cpp file and find the function holster. It tells the client to run a specific animation and restrict the player from firing in the next 0.5 seconds.

void CCrowbar::Holster( )
{
    m_pPlayer->m_flNextAttack = gpGlobals->time + 0.5;
    SendWeaponAnim( CROWBAR_HOLSTER );
}

Let`s do something similar in the glock.cpp file. First you need to add a the main name of the function in class Cglock:

class CGlock : public CBasePlayerWeapon
{
public:
    void Spawn( void );
    void Precache( void );
    int iItemSlot( void ) { return 2; }
    int GetItemInfo(ItemInfo *p);

    void PrimaryAttack( void );
    void SecondaryAttack( void );
    void GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim );
    BOOL Deploy( void );
    void Reload( void );
    void Holster( void );//TROND
    void WeaponIdle( void );
    int m_iShell;
};

Now let`s do the actual holster function. You may put this piece of code everywhere I think, I put it under void CGlock::Spawn( )...

void CGlock::Holster( void )
{
m_pPlayer->m_flNextAttack = gpGlobals->time + 0.7;//Tells HL when we will be able to "fire" again.
    SendWeaponAnim(GLOCK_HOLSTER);//Plays the animation
}

Here comes the part that that leaves the holster anim time to play. You should edit the selectitem func in players.cpp. At the bottom of the func, make it look like this:

// FIX, this needs to queue them up and delay
    if (m_pActiveItem)
        m_pActiveItem->Holster( );
   
    //TROND
//    m_pLastItem = m_pActiveItem;
    m_pLastItem = pItem;

    if (!m_pActiveItem)
        m_pActiveItem = pItem;
//    m_pActiveItem = pItem;
    else
        m_pActiveItem = 0;
    //TROND slutt
    if (m_pActiveItem)
    {
        m_pActiveItem->Deploy( );
        m_pActiveItem->UpdateItemInfo( );
    }

Here we made it so that the weapon won`t change to the next weapon immediately as it did before. Now it actually only lets the gun play it`s holster anim and nothing more. The ActiveItem of the player is now 0.

Let`s make it so that it changes gun too... :^) Add this function over the selectitem function:

void CBasePlayer::ChangeGun( const char *pstr )
{
    if (m_pActiveItem)
    {
        m_pActiveItem->Deploy( );
        m_pActiveItem->UpdateItemInfo( );
    }
}

Deploy means "draw"... :^)

Now head over to players.h and add this line into the class CBasePlayer : public CbaseMonster stuff:

void SelectLastItem(void);
void SelectItem(const char *pstr);
void ItemPreFrame( void );
void ItemPostFrame( void );
void GiveNamedItem( const char *szName );
void EnableControl(BOOL fControl);

void ChangeGun(const char *pstr);//TROND

int GiveAmmo( int iAmount, char *szName, int iMax );
void SendAmmoUpdate(void);

Here`s the lines that calls the function that draws the new gun. I just found a function that was updated every frame and added it into there. Make your CBasePlayer::ItemPreFrame() function in player.cpp look like this:

void CBasePlayer::ItemPreFrame()
{
    if ( gpGlobals->time < m_flNextAttack )
{
        return;
    }

    if (!m_pActiveItem)
    {
        m_pActiveItem = m_pLastItem;//We set the chosen weapon to lastitem in selectitem func. //Now we`ll set it to the active weapon and draws it with ChangeGun.
        ChangeGun (0);
    }

    if (!m_pActiveItem)
        return;

    m_pActiveItem->ItemPreFrame( );
}

Now that should be it... But, this only works if you change weapons manually, let`s see if you can make it change when you pick up new guns or run out of ammo too :^) Oh, I almost forgot: if you wanna play the holster anims of all guns, you gotta add a holster func into the file the represents that weapon. As it is now, it only supports the weapons that already have this function, i.e. Glock (we did that!!) and crowbar...

Good luck!
-Trond

 

blank.gif (837 bytes)
bl.jpg (2471 bytes) blank.gif (837 bytes) br.jpg (2132 bytes)