posted 03-02-2000 07:10 PM
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!