Manual shotgun pumping: Difference between revisions
m (pov) |
(Page Update) |
||
Line 1: | Line 1: | ||
{{pov}} | {{pov}} | ||
If you want to modify the shotgun to be more like a manual pump shotgun, here's what you can do. Its not difficult, but has a really cool outcome. | |||
== Requirements == | |||
* A repository for storing your code changes. (GitHub, Subversion, etc) | |||
* Visual Studio for changing and compiling your code. | |||
== Tutorial == | |||
Now, first | Open {{file|weapon_shotgun.cpp}} | ||
Now, the first step is to remove auto reload. If the user runs out of bullets and forgets to reload, too bad. | |||
Should be about line 543 (645 in newer versions of the Source SDK). | Should be about line 543 (645 in newer versions of the Source SDK). | ||
Line 23: | Line 27: | ||
}</pre> | }</pre> | ||
Comment it out using comment block (/* ... */) instead of the single line (//). | {{tip|Comment it out using comment block (/* ... */) instead of the single line (//).}} | ||
<pre>/* | <pre>/* | ||
Line 39: | Line 43: | ||
}*/</pre> | }*/</pre> | ||
Now | Now the shotgun will not automatically reload if all bullets are expended. You could have also looked at ITEM_FLAG_NOAUTORELOAD, but this requires less work and has a smaller chance of messing something up. However, you will be leaving code in your source which adds a small amount of bloat (although minuscule in size). | ||
Let's get to the nitty gritty. Making a real pump action shotty. | Let's get to the nitty gritty. Making a real pump action shotty. | ||
Line 57: | Line 61: | ||
}</pre> | }</pre> | ||
Analyze this for a minute, that way we are learning something instead of copy paste coding. Realize that the compiler follows PEMDAS (Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction) | Analyze this code for a minute, that way we are learning something instead of copy paste coding. Realize that the compiler follows PEMDAS (Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction) order when looking at 'if' statements, so a statement inside a parenthesis is going to be analyzed first. | ||
First 'if' statement says this: If you need to pump the shotty, and the next attack time is less than or equal to the current time, pump the gun. | First 'if' statement says this: If you need to pump the shotty, and the next attack time is less than or equal to the current time, pump the gun. | ||
Our change says this: If the user is pressing the attack or attack2 button and you need to pump and attack time is less than or equal to current time, let's pump | Our change says this: If the user is pressing the attack or attack2 button ''and'' you need to pump ''and'' attack time is less than or equal to current time, let's pump. Basically, this logic is what is making the gun into a manual action. | ||
Now, I also wanted to be able to pump after you reload ONLY if you expend all your ammunition. This is because if you expend all your ammo now, you want to reload immediately, but you will have an expended round in the chamber, so pump it out. | Now, I also wanted to be able to pump after you reload ONLY if you expend all your ammunition. This is because if you expend all your ammo now, you want to reload immediately, but you will have an expended round in the chamber, so pump it out. | ||
Scroll up to line 146(246 in newer versions) (inside bool CWeaponShotgun::StartReload( void ))and <b>after</b>: | Scroll up to line 146 (line 246 in newer versions) (inside bool CWeaponShotgun::StartReload( void ))and <b>after</b>: | ||
<pre>if (j <= 0) | <pre>if (j <= 0) |
Revision as of 14:42, 30 November 2023

If you want to modify the shotgun to be more like a manual pump shotgun, here's what you can do. Its not difficult, but has a really cool outcome.
Requirements
- A repository for storing your code changes. (GitHub, Subversion, etc)
- Visual Studio for changing and compiling your code.
Tutorial
Open weapon_shotgun.cpp
Now, the first step is to remove auto reload. If the user runs out of bullets and forgets to reload, too bad.
Should be about line 543 (645 in newer versions of the Source SDK).
else { // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing if ( m_iClip1 <= 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime ) { if (StartReload()) { // if we've successfully started to reload, we're done return; } } }

/* else { // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing if ( m_iClip1 <= 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime ) { if (StartReload()) { // if we've successfully started to reload, we're done return; } } }*/
Now the shotgun will not automatically reload if all bullets are expended. You could have also looked at ITEM_FLAG_NOAUTORELOAD, but this requires less work and has a smaller chance of messing something up. However, you will be leaving code in your source which adds a small amount of bloat (although minuscule in size).
Let's get to the nitty gritty. Making a real pump action shotty. Scroll to line 446 (547 in newer versions of the Source SDK). Change this:
if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime)) { Pump(); return; }
To this:
if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime) && (pOwner->m_nButtons & IN_ATTACK || pOwner->m_nButtons & IN_ATTACK2)) { Pump(); return; }
Analyze this code for a minute, that way we are learning something instead of copy paste coding. Realize that the compiler follows PEMDAS (Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction) order when looking at 'if' statements, so a statement inside a parenthesis is going to be analyzed first.
First 'if' statement says this: If you need to pump the shotty, and the next attack time is less than or equal to the current time, pump the gun. Our change says this: If the user is pressing the attack or attack2 button and you need to pump and attack time is less than or equal to current time, let's pump. Basically, this logic is what is making the gun into a manual action.
Now, I also wanted to be able to pump after you reload ONLY if you expend all your ammunition. This is because if you expend all your ammo now, you want to reload immediately, but you will have an expended round in the chamber, so pump it out. Scroll up to line 146 (line 246 in newer versions) (inside bool CWeaponShotgun::StartReload( void ))and after:
if (j <= 0) return false;
Insert this:
if( m_iClip1 == 0 ) { m_bNeedPump = true ; }
Compile, load up, enjoy. Any problems send me a PM to otisranson on Steam forums, or send me an email OtisRanson2@gmail.com.