Semi or Burst fire: Difference between revisions
Jump to navigation
Jump to search
m (pov) |
TomEdwards (talk | contribs) (removed first person) |
||
Line 1: | Line 1: | ||
This is a simple tutorial about adding semi-auto or burst fire mode to a weapon. we 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. | |||
private: | private: | ||
Line 39: | Line 35: | ||
END_PREDICTION_DATA() | END_PREDICTION_DATA() | ||
This created the m_iSemi variable. | This created the m_iSemi variable. The exact purpose of the code above is not currently clear (please amend this if you can). 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. | 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. | ||
Revision as of 13:52, 25 July 2006
This is a simple tutorial about adding semi-auto or burst fire mode to a weapon. we 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. The exact purpose of the code above is not currently clear (please amend this if you can). 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