Posted by: minmaijd
Date posted: Mar 18 2005 User Rating: 4 out of 5.0 | Number of views: 6314 Number of comments: 2 | Description: Explains how to create 3 firing modes for the pistol: semi-automatic, burst-fire, and fully-automatic. |
The purpose of this tutorial is to explain how to create 3 firing modes for the pistol: semi-automatic,
burst-fire, and fully-automatic. The way it works in gameplay is, primary attack fires semi, and secondary
can fire either full-auto or burst, based on firing mode.
Also, I started this tutorial before I found out about 'CHLSelectFireMachineGun'... either way, it functions far different and allows for as many
firing modes as you would like with my method.
So, to begin, a control needs to be set-up for changing firing modes. The following link is a great
tutorial for creating the key. It also goes into setting up the RPG for using the mode, but that half of
his tutorial does not apply to this tutorial naturally as we are dealing with the pistol.
Implementing Rate of Fire or Change Fire Mode
Once you have initialized a key for firing mode switch, you must implement that key within the weapon file
which will be utilizing it. In our case the file is weapon_pistol.cpp
Step 1 Initialization:
Go to the following piece of code:
| | | private: float m_flSoonestPrimaryAttack; float m_flLastAttackTime; float m_flAccuracyPenalty; int m_nNumShotsFired; |
Below this insert the following:
| | | float m_flNextFireModeChange; int nFireCount; bool bFiring; bool bFireMode;
void checkCount(); void FireMode(); |
Next go to the data description initializations:
| | | BEGIN_DATADESC( CWeaponPistol )
DEFINE_FIELD( m_flSoonestPrimaryAttack, FIELD_TIME ), DEFINE_FIELD( m_flLastAttackTime, FIELD_TIME ),
DEFINE_FIELD( m_flAccuracyPenalty, FIELD_FLOAT ), DEFINE_FIELD( m_nNumShotsFired, FIELD_INTEGER ), |
Add the following to the data description:
| | | DEFINE_FIELD( m_flNextFireModeChange, FIELD_TIME ), DEFINE_FIELD( nFireCount, FIELD_INTEGER ), DEFINE_FIELD( bFiring, FIELD_BOOLEAN ), DEFINE_FIELD( bFireMode, FIELD_BOOLEAN ), |
It's still unclear to me why exactly this is necessary, but it is necessary.
Last, give values to the variables. After the following:
| | | CWeaponPistol::CWeaponPistol( void ) { m_flSoonestPrimaryAttack = gpGlobals->curtime; m_flAccuracyPenalty = 0.0f;
m_fMinRange1 = 24; m_fMaxRange1 = 1500; m_fMinRange2 = 24; m_fMaxRange2 = 200;
m_bFiresUnderwater = true; |
Add this:
| | | nFireCount = 3; bFiring = false; bFireMode = false; m_flNextFireModeChange = gpGlobals->curtime; |
Step 2 Calling checkCount():
Checkcount must be checked every frame so include a call to it from CWeaponPistol::ItemPostFrame
like so:
| | | void CWeaponPistol::ItemPostFrame( void ) { ... ... checkCount(); } |
Step 3 Setting up the functions:
Goto the very bottom of the file and inlude the following:
| | | void CWeaponPistol::FireMode( void ) { if ( m_flNextFireModeChange < gpGlobals->curtime ) { nFireCount = 3; bFireMode = !bFireMode; m_flNextFireModeChange = gpGlobals->curtime + 0.5f; } } |
And below this add:
| | | void CWeaponPistol::checkCount( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if (pPlayer == NULL) return;
if (pPlayer->m_afButtonPressed & IN_ATTACK2) { if(bFireMode) bFiring = true; nFireCount = 0; }else if (pPlayer->m_afButtonReleased & IN_ATTACK2) { bFiring = false; } if((bFireMode==false)&&(gpGlobals->curtime - m_flLastAttackTime >= 0.1f)){ if(nFireCount < 3){ PrimaryAttack(); nFireCount++; } } if((bFiring)&&(gpGlobals->curtime - m_flLastAttackTime >= 0.1f)) PrimaryAttack(); } |
Step 4: Find the reload function and add 'bFiring = false':
| | | bool CWeaponPistol::Reload( void ) { bool fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD ); if ( fRet ) { bFiring = false; WeaponSound( RELOAD ); m_flAccuracyPenalty = 0.0f; }
return fRet; } |
So! That's it! However, to ensure that the fireMode key is to work properly open
"/SourceMods/ModName/cfg/config.cfg" and make sure that "x" or whichever key you want is bound to
"+firemode". Another note... sort of glitch/feature is when you press and hold primary fire, then hold
secondary, when you release secondary several bullets will be released at once. If you have a fix, please
comment. |
|
User Comments
Showing comments 1-2
I actually did a similar firing mode to the machine guns. I had the same bug where if you held the primary fire and touched the firing mode button, the guns would unload the entirety of their clips, until i was out of ammo. Give this link a try
http://www.hl2coding.com/forums/viewtopic.php?t=438 |
|
Very Nice...
A few things to note:
- If you follow the tutorial you posted in addition to this article, implementing the check for IN_FIREMODE inside the basecombatweapon_shared is not only unnessessary but it will not compile. Instead of doing the input check on baseweapon's ItemPostFrame, do it in each weapon's individual ItemPostFrame that have FireModes. - Secondly, if you do follow the mentioned article, then you do not need the function prototype void FireMode();
Also, it took me some time to realize just what your modifcation did... so obviously in game instruction would be needed if this were to be added to a mod of sorts. I plan on adding a small glow effect (can be found in the ar2 combine ball attack code ar2.cpp, where it flashes the screen white) to make the screen go slightly yellow for a split second and play a sound effect when weapon mode is changed.
Thanks for the useful information ^^ I appriciate your time and effortEdited by Drakeling on Apr 10 2005, 23:45:11
|
|
You must register to post a comment. If you have already registered, you must login.
|
297 Approved Articless
6 Pending Articles
3940 Registered Members
0 People Online (14 guests)
|
|