contributed by: Vulgrin
Ok, now that we've got our environment setup, its
time to actually do something with it. To do this we're
going to put together a VERY simple server side mod. I
decided that instead of changing a weapon to shoot
faster and so on, we'd start with something simple but
more interesting. We're going to do a simple Vampire
mod.
Vampire:
Everytime a client shoots another player
and causes damage, we will give the shooter an equal
amount of health back. To keep it from getting too
crazy, we'll cap it off at a maximum of 500 points. Plus
we'll leave in the code to slowly decrement the health
back to the normal level of 100.
Project(s) involved:
game
Files(s) involved:
g_combat.c
Functions involved:
G_Damage()
There's a lot of stuff being done in G_Damage() to
calculate exactly how many points of damage to be done.
Since all we care about is the final number of points
done, lets skip down the function to around this point:
// do the damage
if (take)
{
targ->health =
targ->health - take;
if (
targ->client )
{
targ->client->ps.stats[STAT_HEALTH] =
targ->health;
}
if ( targ->health <= 0
) {
if ( client
)
targ->flags
|=
FL_NO_KNOCKBACK;
if (targ->health <
-999)
targ->health
=
-999;
targ->enemy =
attacker;
targ->die (targ, inflictor, attacker, take,
mod);
return;
} else if (
targ->pain )
{
targ->pain (targ, attacker,
take);
}
}
take is the amount of damage that is going to be done
to the target, as shown in this IF statement. Basically
the line "targ->health = targ->health - take;"
decrements the targets health. The next if statement
checks to see if the target is a client and tells the
client that it took the damage. The next IF statement
then checks to see if the target is toast and to act
appropriately.
So, lets add a few lines in after the client is
updated and before we check to see if the target is now
a chunky stew:
// Vampire mod
attacker->health =
attacker->health + take;
if (attacker->health
> 500)
{
attacker->health
= 500;
}
// end Vampire
First thing to notice is that I wrapped my code in
comments. THIS IS VERY IMPORTANT. It is my personal
method to NEVER delete a line of Id's code, but rather
to comment it out and put my code right next to it.
In this case we are only adding new code, so save
yourself the headache later and wrapper it in comments.
This will make it easier to find out what the hell you
changed in a mad fit of debugging. (On an aside, I often
add a comment of // ##VULGRIN around the code I change,
so I have a constant string I can search for later.)
So, the bottom line is that this mod is pretty easy
to code for a first time coder. We ADD the take
value to the attacker's health value and then do a
simple IF statement to keep the maximum health at
00. After all, we don't want any 1000 point vampire's
running around our mods now do we?
Now let's actually test this puppy out. To test, we
need to compile everything and run it. So, in your menu
go to Build...Build qagamex86.dll. This will
compile any changed files and create the DLL in
your Quake III Arena directory. (Providing you
set it up properly in the Prologue tutorial.)
Once the DLL is compiled, run the mod by
selecting Build...Execute quake3.exe from your
menu. Quake 3 should start up as normal. Go jump into a
single player game and see if you can Vampire the bot.
Oh, and since this is server side, and it modifies the
health of ANY client that takes damage, the bots will
benefit from this mod as well.
Well, that wraps up the first tutorial and setup.
Keep checking back for our next tutorial or tell us
about what you would like to see in future chapters of
Quake 3 Coding for Utter Morons!