Semi or Burst fire: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 3: Line 3:
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.
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:
private:
CNetworkVar( float, m_flSoonestPrimaryAttack );
CNetworkVar( float, m_flSoonestPrimaryAttack );
CNetworkVar( float, m_flLastAttackTime );
CNetworkVar( float, m_flLastAttackTime );
CNetworkVar( float, m_flAccuracyPenalty );
CNetworkVar( float, m_flAccuracyPenalty );
CNetworkVar( int, m_nNumShotsFired );
CNetworkVar( int, m_nNumShotsFired );
'''CNetworkVar( int, m_iSemi );'''


private:
CWeaponPistol( const CWeaponPistol & );
};


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


BEGIN_NETWORK_TABLE( CWeaponPistol, DT_WeaponPistol )
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPistol, DT_WeaponPistol )
#ifdef CLIENT_DLL
RecvPropTime( RECVINFO( m_flSoonestPrimaryAttack ) ),
BEGIN_NETWORK_TABLE( CWeaponPistol, DT_WeaponPistol )
RecvPropTime( RECVINFO( m_flLastAttackTime ) ),
#ifdef CLIENT_DLL
RecvPropFloat( RECVINFO( m_flAccuracyPenalty ) ),
RecvPropTime( RECVINFO( m_flSoonestPrimaryAttack ) ),
RecvPropInt( RECVINFO( m_nNumShotsFired ) ),
RecvPropTime( RECVINFO( m_flLastAttackTime ) ),
#else
RecvPropFloat( RECVINFO( m_flAccuracyPenalty ) ),
SendPropTime( SENDINFO( m_flSoonestPrimaryAttack ) ),
RecvPropInt( RECVINFO( m_nNumShotsFired ) ),
SendPropTime( SENDINFO( m_flLastAttackTime ) ),
'''RecvPropInt( RECVINFO( m_iSemi ) ),'''
SendPropFloat( SENDINFO( m_flAccuracyPenalty ) ),
#else
SendPropInt( SENDINFO( m_nNumShotsFired ) ),
SendPropTime( SENDINFO( m_flSoonestPrimaryAttack ) ),
#endif
SendPropTime( SENDINFO( m_flLastAttackTime ) ),
END_NETWORK_TABLE()
SendPropFloat( SENDINFO( m_flAccuracyPenalty ) ),
SendPropInt( SENDINFO( m_nNumShotsFired ) ),
'''SendPropInt( SENDINFO( m_iSemi ) ),'''
#endif
END_NETWORK_TABLE()


BEGIN_PREDICTION_DATA( CWeaponPistol )
BEGIN_PREDICTION_DATA( CWeaponPistol )
END_PREDICTION_DATA()
'''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'''

Revision as of 13:29, 25 July 2006

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