add automatic map restart upon all players running out of lives

master
an 2019-09-19 20:33:17 -04:00
parent c140ffe07d
commit 3d627c7530
4 changed files with 32 additions and 3 deletions

View File

@ -301,6 +301,9 @@ void() trigger_changelevel = {
*/
void() become_spectator = {
float not_dead;
entity pl;
self.health = self.max_health;
self.armortype = 0;
self.armorvalue = 0;
@ -319,6 +322,16 @@ void() become_spectator = {
self.frame = 0;
self.modelindex = modelindex_eyes;
W_SetCurrentAmmo();
pl = find(world, classname, "player");
while(pl != world) {
not_dead += pl.lives;
pl = find(pl, classname, "player");
}
if(!not_dead) {
all_players_are_dead = time;
}
};
void() respawn = {
@ -339,7 +352,7 @@ void() respawn = {
player_respawned = TRUE;
PutClientInServer();
} else {
// restart the entire server
// restart the map
localcmd("restart\n");
}
};

View File

@ -630,6 +630,7 @@ float sf_lives;
float sf_dist_ammo;
float player_respawned;
float all_players_are_dead;
// fields --------------------------------------------------------------------|

View File

@ -179,7 +179,8 @@ void() worldspawn = {
};
void() StartFrame = {
float temp1flag;
entity pl;
float temp1flag, delta;
teamplay = cvar("teamplay");
skill = cvar("skill");
@ -189,6 +190,20 @@ void() StartFrame = {
sf_cheats = (temp1flag & SF_CHEATS) != 0;
sf_lives = bit_shift_right(temp1flag & SF_LIVES_MSK, SF_LIVES_BEG);
sf_dist_ammo = (temp1flag & SF_DIST_AMMO) != 0;
if(all_players_are_dead) {
delta = time - all_players_are_dead;
if(delta >= 9.95) {
localcmd("restart\n");
} else if(rint(delta * 10) == rint(delta) * 10) {
pl = find(world, classname, "player");
while(pl != world) {
centerprint(pl, "Mission failed.\nRestarting in ",
ftos(10 - rint(delta)), " seconds");
pl = find(pl, classname, "player");
}
}
}
};
/*

2
todo
View File

@ -10,7 +10,6 @@ rename all functions to be lower_underscore
core features:
add registercvar support
restart map after 10 seconds when everyone is dead
useful features:
@ -35,3 +34,4 @@ distributed ammo
enforcers are broken
lives counting
no friendly fire
restart map after 10 seconds when everyone is dead