Go
into glock.cpp and make the following changes: In the CGlock
class declaration at the top of the file add the following line
just under the "public:" statement (About line 40) -
void AddSilencer( void );
This defines a new CGlock member function
AddSilencer. Then replace the CGlock::SecondaryAttack function
(About line 110) with this one:
void CGlock::SecondaryAttack( void )
{
m_flTimeWeaponIdle = gpGlobals->time + 2.0f;
m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->time
+ 2.0f;
SetThink( AddSilencer );
pev->nextthink = gpGlobals->time + 1.0f;
SendWeaponAnim( GLOCK_HOLSTER );
}
This sends the holster animation to the
weapon model (Which causes the weapon to drop out of sight),
sets the think function to AddSilencer (The member function we
just added), and sets the next think time to the current time
plus 1 second. There're a few variables and functions you might
not recognize in the new Secondary attack function, so they're
explained below.
void *m_pfnThink, float nextthink, and the
SetThink macro: for those of you who've never coded Quake 1 or 2
mods before, the think function is a void function pointer. You
can set it to any member function from the current class that
doesn't take any parameters or return a value. You then set the
nextthink value to the time when the think function should be
executed.
float gpGlobals->time: The current time in
seconds. This is a floating point member of gpGlobals.
float m_flNextPrimaryAttack: This should
be set to a time value, much like next think. If gpGlobals->time
is less than m_flNextPrimaryAttack primary fire commands will be
ignored, this prevents the gun from firing as you fit the
silencer on.
float m_flTimeWeaponIdle: If this value is
less than gpGlobals->time (If it's "already happened") then the
weapon idle animation takes over, cancelling any currently
running animations. It's important to set this to the right
value, or the holstering and drawing animations will be
interrupted.
virtual void SendWeaponAnim( int iAnim ):
This function starts a weapon animation. All the weapon
animations are declared in the enum at the top of their
respective cpp files.
entvars_t *pev: This class member of
CBaseEntity (The class pretty much every animated thing is
derived from) stores important entity data.
Okay, now add this just under the function
we've just declared:
void CGlock::AddSilencer( void )
{
if(pev->body == 1)
pev->body = 0;
else
pev->body = 1;
SendWeaponAnim( GLOCK_DRAW );
}
some models have multiple meshes, pev->body
is the current mesh of the weapon. Changes made to pev->body
won't show up until the next animation is run. For the glock,
body 0 is the glock without the silencer, and body 1 is the
glock with the silencer. |