News: SMF - Just Installed!
 
Welcome, Guest. Please login or register.
+  AnthraxBio
|-+  Return to Castle Wolfenstein
| |-+  Coding Tutorials
| | |-+  Enable Firing and Reloading while Leaning
« previous next »
Pages: [1] Print
Author Topic: Enable Firing and Reloading while Leaning  (Read 262 times)
SkreamerVirii
Administrator
Full Member
*****
Posts: 133


View Profile
« on: September 03, 2008, 11:14:36 PM »

Enable Firing and Reloading while Leaning.
In this Tutorial I will show you how you can fire and relaod a weapon while you are leaning around corners.
This tutorial is actually quite easy as it doesn't require adding any new code. All we need to do
is comment out sections of the code that check for leaning when firing a weapon.
To complete this task will need to create 2 dlls, cgame_mp_x86.dll and qagame_mp_x86.dll.
We will create the qagame dll first.
Before we begin make sure that Games is your active project in MSVC.
Then expand your source files folder and open bg_pmove.c for editing.
Most of the changes we need to make will be in this file.
First we will enable reloading while leaning.
Go to line 1814:
you should see this
// no reload when leaning (this includes manual and auto reloads)
if(pm->ps->leanf)
return;
comment out the if and return statements like so:
// no reload when leaning (this includes manual and auto reloads)
// if(pm->ps->leanf)
// return;
Thats it. You can now reload while leaning. Told you this wasn't hard.
Now lets Enable the firing.
Still in bg_pmove go to line 2696:
// player is leaning - no fire
if(pm->ps->leanf != 0 && pm->ps->weapon != WP_GRENADE_LAUNCHER && pm->ps->weapon != WP_GRENADE_PINEAPPLE ) {
return;
}
Comment out the entire if statement, so it looks like this:
// player is leaning - no fire
// if(pm->ps->leanf != 0 && pm->ps->weapon != WP_GRENADE_LAUNCHER && pm->ps->weapon != WP_GRENADE_PINEAPPLE ) {
// return;
// }

Now we need to go to line 3253:
if(ps->eFlags & EF_FIRING)
leaning = 0; // not allowed to lean while firing
once again we comment out the enitre if statement:
// if(ps->eFlags & EF_FIRING)
// leaning = 0; // not allowed to lean while firing
If we did not remove the above line, then you would not be able to hold down the fire button
and lean. It would force your model to go back to an upright position to continue firing. Now
we can hold down a lean button and stay leaning while firing.
Now there is one last section we need to change in this file. And it is the trickiest part so far.
Go to line 3731:
// check for ammo
if(PM_WeaponAmmoAvailable(pm->ps->weapon)) {
// check if zooming
// DHM - Nerve :: Let's use the same flag we just checked above, Ok?
if(!(pm->ps->eFlags & EF_ZOOMING)) {
if(!pm->ps->leanf) {
if ( pm->ps->weaponstate == WEAPON_READY || pm->ps->weaponstate == WEAPON_FIRING ) {
// all clear, fire!
if( pm->cmd.buttons & BUTTON_ATTACK && !(pm->cmd.buttons & BUTTON_TALK) )
pm->ps->eFlags |= EF_FIRING;
}
}
}
}
}
you will notice the line on 3735:
if(!pm->ps->leanf) {
This is the code we need to comment out. Because there are so many nested ifs we need to be careful
not to comment out the wrong ones.
comment out line 3735
//if(!pm->ps->leanf) {
and then line 3742
//}
Looking at the whole code it should look like this:
// check for ammo
if(PM_WeaponAmmoAvailable(pm->ps->weapon)) {
// check if zooming
// DHM - Nerve :: Let's use the same flag we just checked above, Ok?
if(!(pm->ps->eFlags & EF_ZOOMING)) {
// if(!pm->ps->leanf) {
if ( pm->ps->weaponstate == WEAPON_READY || pm->ps->weaponstate == WEAPON_FIRING ) {
// all clear, fire!
if( pm->cmd.buttons & BUTTON_ATTACK && !(pm->cmd.buttons & BUTTON_TALK) )
pm->ps->eFlags |= EF_FIRING;
}
// }
}
}
}

Save all the changes to bg_pmove.c and close it.
Now open g_weapon.c and go to line 2172:
// (SA) actually, this is sort of moot right now since
// you're not allowed to fire when leaning. Leave in
// in case we decide to enable some lean-firing.
// (SA) works with gl now
//AddLean(ent, muzzlePoint);
You can see here that the code is already there for the addlean so that the muzzle flash.
Now that we are allowed to fire when leaning we need to remove the two /'s it looks like this:
// (SA) actually, this is sort of moot right now since
// you're not allowed to fire when leaning. Leave in
// in case we decide to enable some lean-firing.
// (SA) works with gl now
AddLean(ent, muzzlePoint);
Save your changes and close the file. Now build the qagame_mp_x86.dll.
You can now shoot and lean and relaod and lean. But wait we are not done.
There is one more small detail we have overlooked. Have you every noticed in the game
that when you lean, your crosshair disappears. Thats fine when you can't shoot your weapon,
but now that we can, I think I'd like to know where I am aiming.
To add the crosshair make cgame the active project. Then open cg_draw.c .
Go to line 1626:
if(cg.snap->ps.leanf) // no crosshair while leaning
return;
and comment out the if statment:
//if(cg.snap->ps.leanf) // no crosshair while leaning
// return;
The crosshair will now be drawn while leaning. Save the file and build cgame_mp_x86.dll.
Copy the two dlls that you have just created to your mod directory.
One last thing before you try them out. When you run your server to test your changes, set
the pure server option to no or sv_pure "0" in your cfg file. If you do not do this then the
changes to the cgame dll will not work.
I have to give a shoot out to Fretn for that one.
There is one thing that you will notice, like Rhino pointed out in his original tutorial, that
when you fire while leaning the bullet still appears to be coming from its original position.
Until that is figured out, this will atleast get you started. There is one other major issue, and that is
that the player models don't actually lean in the game.
So there you go we got the process started, next we need to figure out how to make the models lean
in the game and change the bullet trail.
Doctair
 
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Free SMF 1.1.5 Forum Theme by Tamuril. © 2008.