Semi or Burst fire: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (pov)
Line 1: Line 1:
{{pov}}
Hi
Hi



Revision as of 13:49, 25 July 2006

Broom icon.png
This article or section should be converted to third person to conform to wiki standards.

Hi

This is a simple tutorial about adding semi-auto or burst fire mode to a weapon. I will use the weapon_pistol.cpp as the basis of the tutorial. Look up this part at the declaration of the pistol class. The extra lines are bold.

private:
CNetworkVar( float,	m_flSoonestPrimaryAttack );
CNetworkVar( float,	m_flLastAttackTime );
CNetworkVar( float,	m_flAccuracyPenalty );
CNetworkVar( int,	m_nNumShotsFired );
CNetworkVar( int,	m_iSemi );


private:
CWeaponPistol( const CWeaponPistol & );
};
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPistol, DT_WeaponPistol )

BEGIN_NETWORK_TABLE( CWeaponPistol, DT_WeaponPistol )
#ifdef CLIENT_DLL
RecvPropTime( RECVINFO( m_flSoonestPrimaryAttack ) ),
RecvPropTime( RECVINFO( m_flLastAttackTime ) ),
RecvPropFloat( RECVINFO( m_flAccuracyPenalty ) ),
RecvPropInt( RECVINFO( m_nNumShotsFired ) ),
RecvPropInt( RECVINFO( m_iSemi ) ),
#else
SendPropTime( SENDINFO( m_flSoonestPrimaryAttack ) ),
SendPropTime( SENDINFO( m_flLastAttackTime ) ),
SendPropFloat( SENDINFO( m_flAccuracyPenalty ) ),
SendPropInt( SENDINFO( m_nNumShotsFired ) ),
SendPropInt( SENDINFO( m_iSemi ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponPistol )
DEFINE_PRED_FIELD( m_iSemi, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
END_PREDICTION_DATA()

This created the m_iSemi variable. However I don't know the exact purpose of the code above. It has something to do with client side prediction, to ease the server load. The important part is that it works :). Now define a constant. That holds the maximum number of bullets to be fired with 1 trigger pull. In semi-auto, you would add 1. For a 3 shot burst add 3 etc.

#define	PISTOL_ACCURACY_SHOT_PENALTY_TIME		0.2f	// Applied amount of time each shot adds to the time we must recover from
#define	PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME	1.5f	// Maximum penalty to deal out
#define	MAXBURST	1