The Place to Start


Advanced Silenced Glock  
Atomizer
Easy


Ok, what we will be doing here is creating two modes of fire for the Glock:

Silenced and Non-Silenced

By pressing your Secondary fire button, you will switch from being normal to silenced, and instead of just morphing the silencer in, we will add the extra animation provided in the Glocks model that screws the silencer on.

Old code = GREEN
Code to be deleted = RED
New code = BLUE

Ok, firstly we have to declare the new variable used.
Open up glock.cpp and at the end of the "class CGlock : public CBasePlayerWeapon" function add this line:

int m_iSilenced;


Now goto around line 110 and change this code:

void CGlock::SecondaryAttack( void )
{
    GlockFire( 0.1, 0.2, FALSE );
}

to this:

void CGlock::SecondaryAttack( void )
{
      if (m_iSilenced != 1) //checks to see if the glock is silenced
      {
//And if it isnt,add the silencer:
           pev->body = 1; // this displays the silenced verion of the Glock
           SendWeaponAnim( GLOCK_ADD_SILENCER ); // Displays the animation of the player screwing on the silencer
           m_iSilenced = 1; // This is to keep track of whether its silenced or not
           m_flNextPrimaryAttack = gpGlobals->time + 3.5; // Delays primary fire mode by 3.5 seconds
           gSkillData.plrDmg9MM = 50; // Changes the Glocks damage to 50
      }
      else //and if it is:
      {
           SendWeaponAnim( GLOCK_HOLSTER ); // Displays the Holster animation
           pev->body = 0; // then takes off the silencer
           SendWeaponAnim( GLOCK_DRAW ); // and brings it back up again
           m_iSilenced = 0; // This is to keep track of whether its silenced or not
           m_flNextPrimaryAttack = gpGlobals->time + 1; // Delays Primary fire mode by 1 second
           gSkillData.plrDmg9MM = 30; // Changes the Glocks damage to 30
      }
      m_flNextSecondaryAttack = gpGlobals->time + 3; //Delays switching modes by 3 seconds
      m_flTimeWeaponIdle = gpGlobals->time + 4; //Tells it to wait 4 seconds before idleing
}


Having that done, we have to make sure the primary attack works correctly, so around line 133, change this code:

void CGlock::PrimaryAttack( void )
{
      GlockFire( 0.01, 0.3, TRUE );
}

to this:

void CGlock::PrimaryAttack( void )
{
      if (pev->body == 1) //Checks to see if it has the silencer attached
      {
           GlockFire( 0.01, 0.7, TRUE );
      }
      else
      {
           GlockFire( 0.1, 0.2, FALSE );
      }
}

Ok, now lets look at the GlockFire function:

GlockFire( 0.01, 0.7, TRUE );

The first variable 0.01 is the acuracy in which the Glock fires, the higher the number the less acuracy,
the second variable 0.7 is the delay in seconds before fireing the next shot, and
the last variable TRUE tells it weither to use autoaim or not, as you can see, I have autoaim on for silenced mode, and have it turned off for the non_silenced version.

Thats all, just compile(F7) and run.



Any questions or suggestions should be sent to me: metroid74@hotmail.com