diff --git a/source/client.qc b/source/client.qc index 5c52d9b..5334923 100644 --- a/source/client.qc +++ b/source/client.qc @@ -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"); } }; diff --git a/source/defs.qc b/source/defs.qc index f0bc3b8..99c26af 100644 --- a/source/defs.qc +++ b/source/defs.qc @@ -630,6 +630,7 @@ float sf_lives; float sf_dist_ammo; float player_respawned; +float all_players_are_dead; // fields --------------------------------------------------------------------| diff --git a/source/world.qc b/source/world.qc index cdd6d66..6767499 100644 --- a/source/world.qc +++ b/source/world.qc @@ -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"); + } + } + } }; /* diff --git a/todo b/todo index 9aeb49f..e668344 100644 --- a/todo +++ b/todo @@ -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