Quake3mods.net     [all categories]
  Coding
  Individual weapon knockback

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Individual weapon knockback
CA_Napalm
Junior Member

Posts: 5
Registered: Mar 2000

posted 03-02-2000 11:02 AM     Click Here to See the Profile for CA_Napalm   Click Here to Email CA_Napalm     Edit/Delete Message Reply w/Quote
Just as the subject implies, i'm trying to modify one particular weapon's kick, leaving the rest alone. If someone could perhaps give me a hint? Should I try the weapon code itself, or g_combat.c?

IP: Logged

fliptw
Junior Member

Posts: 17
Registered: Feb 2000

posted 03-02-2000 11:10 AM     Click Here to See the Profile for fliptw   Click Here to Email fliptw     Edit/Delete Message Reply w/Quote
yes, start in g_weapons.c, you'd most likely have to move to bg_pmove.c and maybe more dependant on your definition of kickback.

IP: Logged

ann0yanc3
Junior Member

Posts: 19
Registered: Feb 2000

posted 03-02-2000 07:10 PM     Click Here to See the Profile for ann0yanc3   Click Here to Email ann0yanc3     Edit/Delete Message Reply w/Quote
Ahh, I have already done this to have some fun with my online friends.

Ok, I changed the knockback of the machinegun so that you flew all over the place. It's really fun.

Open up g_combat.c and goto the G_Damage() function. It's around line 447.

Now, if you look down in the function a bit, you'll see a small section dealing with the knockback of each weapon. This section starts around line 500.

If you read the code, you'll notice that the knockback of each weapon is the damage that it does. So, in terms of functions, you don't pass the knockback variable to the function, it's automatically calculated by the function.

Therefore, you have 2 options. One, you can make a new global variable for knockback and implement that into your code, or Two, you can simply change the knockback according to the means of death variable passed into the function.

I chose the more simple number 2. It's faster and a lot more easy to implement. So, here what we're gonna change. You should see this code:

code:

knockback = damage;
if ( knockback > 200 ) {
knockback = 200;
}

if ( targ->flags & FL_NO_KNOCKBACK ) {
knockback = 0;
}

if ( dflags & DAMAGE_NO_KNOCKBACK ) {
knockback = 0;
}


I have classified this as being the "knockback section." All you have to do from here is add one if-statement to the code in order to change the knockback of the desired weapon.

Here's my updated "knockback section":

code:

knockback = damage;

if ( knockback > 200 ) {
knockback = 200;
}

if ( targ->flags & FL_NO_KNOCKBACK ) {
knockback = 0;
}

if ( dflags & DAMAGE_NO_KNOCKBACK ) {
knockback = 0;
}

//change knockback for machinegun
if ( mod == MOD_MACHINEGUN ) {
knockback = 1000;
}


Let me interpret this snippet of code for you guys real quick. It's quite easy to understand.

First, you set the knockback to the amount of damage that the weapon does. Then, it checks to make sure that knockback is not greater than 200, if so, it caps it at 200. Finally, it checks the game flags to see if knockback should be applied. If not, set knockback to zero. Very simple!

Now, as for my added code, all I did was check to see of the means of death that passed to the function was for the machinegun (MOD_MACHINEGUN), if so, I changed the knockback to 1000.

In conclusion, I just want to say that there are many more efficient ways of implementing different knockbacks to eash weapon. But, I chose the easiest as I only wanted to have fun for a little while. Therefore, I suggest a more universal method of applying knockback with the use of a global variable.

Have fun! Good luck!

IP: Logged

CA_Napalm
Junior Member

Posts: 5
Registered: Mar 2000

posted 03-02-2000 10:40 PM     Click Here to See the Profile for CA_Napalm   Click Here to Email CA_Napalm     Edit/Delete Message Reply w/Quote
My thanks to you kindly folks. I had a feeling the easiest way was to fix the "knockback section" I just didn't know how. And actually, this gives me even more info I didn't have that could come in handy again later. Thanks!

IP: Logged

All times are CT(US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | Quake3mods.net

Powered by: Ultimate Bulletin Board, Version 5.43c
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.