Quake Style - Quake 3
Tutorials Game Enhancements - (Re/De)generation of stats How to add
regenerating or degenerating elements to your mod!
|
This
"quickie" tut will show you how to use an existing function to make
regenerating/degenerating additions to your mod. Open up g_active.c and go to
the ClientTimerActions( gentity_t *ent, int msec ) definition. This function
will run everything in it once a second. It's perfect for regeneration and
degeneration! Here it is in full glory:
void ClientTimerActions( gentity_t *ent, int msec ) {
gclient_t *client;
client = ent->client;
client->timeResidual += msec;
while ( client->timeResidual >= 1000 ) {
client->timeResidual -= 1000;
// regenerate
if ( client->ps.powerups[PW_REGEN] ) {
if ( ent->health < client->ps.stats[STAT_MAX_HEALTH]) {
ent->health += 15;
if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] * 1.1 ) {
ent->health = client->ps.stats[STAT_MAX_HEALTH] * 1.1;
}
G_AddEvent( ent, EV_POWERUP_REGEN, 0 );
} else if ( ent->health < client->ps.stats[STAT_MAX_HEALTH] * 2) {
ent->health += 5;
if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] * 2 ) {
ent->health = client->ps.stats[STAT_MAX_HEALTH] * 2;
}
G_AddEvent( ent, EV_POWERUP_REGEN, 0 );
}
} else {
// count down health when over max
if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] ) {
ent->health--;
}
}
// count down armor when over max
if ( client->ps.stats[STAT_ARMOR] > client->ps.stats[STAT_MAX_HEALTH] ) {
client->ps.stats[STAT_ARMOR]--;
}
}
}
As you my have noticed from looking at it, it handles all the
power ups and the decrementing of armor and health while it's over 100. Let's
add a simple bit that checks the player's weapon and adds ammo every second.
Inside of the while loop, at the bottom (before the last two } ) add these
lines:
// give ammo
client->ps.ammo[client->ps.weapon] += 2;
if (client->ps.ammo[client->ps.weapon] > 200)
client->ps.ammo[client->ps.weapon = 200;
The end of the function should look like this:
// count down armor when over max
if ( client->ps.stats[STAT_ARMOR] > client->ps.stats[STAT_MAX_HEALTH] ) {
client->ps.stats[STAT_ARMOR]--;
}
// give ammo
client->ps.ammo[client->ps.weapon] += 2;
if (client->ps.ammo[client->ps.weapon] > 200)
client->ps.ammo[client->ps.weapon = 200;
}
}
What the above code does is adds 2 units of the correct ammo to
the client every second. It then checks to make sure the ammo doesn't go over
200, and if it does, it resets it back to 200. You can change the
client->ps.weapon to any of the WP_WEAPON enumerated types (they're numbers
if you didn't know). 1 is the WP_GUANTLET, going on up to WP_GRAPPLING_HOOK,
which is 10 (neither of them use ammo though, so don't use them!).
As
you can tell, it's a pretty easy process. Other uses you ask? Well if you create
new power-ups or runes, then you can check and see if the player has the rune in
the above function, and give them ammo or health, or any number of things. You
could also use it for realistic damage, and set a bleeding counter. Maybe if
you're shot in the chest your bleeding counter is set to 10, and for 10 seconds
you lose 3 health each second. You can decrement that bleeding counter in the
ClientTimerActions function easily as well.
Be creative, and enjoy!
-- Credits:
Tutorial by Willi
Return to QS Tutorials
-- Important:
If you
do use something from QuakeStyle in your mod, please give us credit.
Our code is copyrighted, but we give permission to everyone to
use it in any way they see fit, as long as we are recognized.