[page=Introduction]
This tutorial takes about 20 seconds, but it is REALLY helpful for those ultimate destruction mods, or a tourney mod.
[page=Making The Change]
Head on over to p_client.c, ClientBeginDeathmatch, which checks for respawns and resets all needed info. Right after the definitons, add this in:
// Do this to add 3 seconds worth of invincibility.
self->client->invincible_framenum = level.framenum + 30; // 10 frames per second.
Change 30 to whatever your hearts desire. 30 = 3, just add a 10 to the desired number. Using Invulnerability item gives you 300 seconds of it.
There you go. Mess around with it. This can be used with Quad too!
-Paril Kalashnikov
You should add how to make this a CVar. Other than that, awsome.
Define your cvar in g_main.c:
cvar_t *respawn_protect; // admin configurable respawn protection
Set it to a reasonable default value in g_save.c:
// the DM respawn invulnerability (defaults to 5 seconds)
respawn_protect = gi.cvar("respawn_protect", "5", 0); //QW// allow admin to control respawn invincibility time
Do some checking of it's value periodically, perhaps in CheckDMRules() to keep it somewhat sane.
if (respawn_protect->modified || initialization) {
//limit value ranges allowed for the respawn protection
if (respawn_protect->value <= 0) gi.cvar_set("respawn_protect","0");
if (respawn_protect->value >= 6) gi.cvar_set("respawn_protect","6");
respawn_protect->modified = false;
}
Setting the spawn protection properly belongs in PutClientInServer():
// start invulnerable for variable seconds in DM, but not teamplay.
if (deathmatch->value && !ctf->value) {
int spawntime;
spawntime = (int) (respawn_protect->value * 10);
ent->client->invincible_framenum = level.framenum + spawntime;
}
If your mod doesn't have a CTF mode then you can eliminate the checks for them:
int spawntime;
spawntime = (int) (respawn_protect->value * 10);
ent->client->invincible_framenum = level.framenum + spawntime;
Note that invincible_framenum and spawntime are integers and respawn_protect->value is a float so we cast it to int to shut the compiler up about the conversion.
Define your cvar in g_main.c:
cvar_t *respawn_protect; // admin configurable respawn protection
Set it to a reasonable default value in g_save.c:
// the DM respawn invulnerability (defaults to 5 seconds)
respawn_protect = gi.cvar("respawn_protect", "5", 0); //QW// allow admin to control respawn invincibility time
Do some checking of it's value periodically, perhaps in CheckDMRules() to keep it somewhat sane.
if (respawn_protect->modified || initialization) {
//limit value ranges allowed for the respawn protection
if (respawn_protect->value <= 0) gi.cvar_set("respawn_protect","0");
if (respawn_protect->value >= 6) gi.cvar_set("respawn_protect","6");
respawn_protect->modified = false;
}
Setting the spawn protection properly belongs in PutClientInServer():
// start invulnerable for variable seconds in DM, but not teamplay.
if (deathmatch->value && !ctf->value) {
int spawntime;
spawntime = (int) (respawn_protect->value * 10);
ent->client->invincible_framenum = level.framenum + spawntime;
}
If your mod doesn't have a CTF mode then you can eliminate the checks for them:
int spawntime;
spawntime = (int) (respawn_protect->value * 10);
ent->client->invincible_framenum = level.framenum + spawntime;
Note that invincible_framenum and spawntime are integers and respawn_protect->value is a float so we cast it to int to shut the compiler up about the conversion.