]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc
LMS: jitter waypoint repeat time to make it less predictable
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / lms / sv_lms.qc
index aceb66e0310db714e640c16250b7bcd8d4a547c5..aa8cdc5381f364a0d61b7939686005f8416604eb 100644 (file)
@@ -3,18 +3,39 @@
 #include <common/mutators/mutator/instagib/items.qh>
 #include <server/campaign.qh>
 #include <server/command/_mod.qh>
+#include <server/world.qh>
+#include <server/items/items.qh>
 
 int autocvar_g_lms_extra_lives;
 bool autocvar_g_lms_join_anytime;
 int autocvar_g_lms_last_join;
 bool autocvar_g_lms_regenerate;
+int autocvar_g_lms_leader_wp_lives = 2;
+float autocvar_g_lms_leader_wp_max_relative = 0.5;
+float autocvar_g_lms_leader_wp_time = 5;
+float autocvar_g_lms_leader_wp_time_jitter = 10;
+float autocvar_g_lms_leader_wp_time_repeat = 25;
+float autocvar_g_lms_dynamic_respawn_delay = 1;
+float autocvar_g_lms_dynamic_respawn_delay_base = 2;
+float autocvar_g_lms_dynamic_respawn_delay_increase = 3;
+float autocvar_g_lms_dynamic_respawn_delay_max = 20;
+bool autocvar_g_lms_dynamic_vampire = 1;
+float autocvar_g_lms_dynamic_vampire_factor_base = 0.1;
+float autocvar_g_lms_dynamic_vampire_factor_increase = 0.1;
+float autocvar_g_lms_dynamic_vampire_factor_max = 0.5;
+int autocvar_g_lms_dynamic_vampire_min_lives_diff = 2;
+
+.float lms_leader;
+int lms_leaders;
+bool lms_visible_leaders;
+bool lms_visible_leaders_prev;
+float lms_leader_time_jitter;
 
 // main functions
-float LMS_NewPlayerLives()
+int LMS_NewPlayerLives()
 {
-       float fl;
-       fl = autocvar_fraglimit;
-       if(fl == 0)
+       int fl = floor(autocvar_fraglimit);
+       if(fl == 0 || fl > 999)
                fl = 999;
 
        // first player has left the game for dying too much? Nobody else can get in.
@@ -22,7 +43,7 @@ float LMS_NewPlayerLives()
                return 0;
 
        if(!autocvar_g_lms_join_anytime)
-               if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
+               if(lms_lowest_lives < fl - max(0, floor(autocvar_g_lms_last_join)))
                        return 0;
 
        return bound(1, lms_lowest_lives, fl);
@@ -35,9 +56,12 @@ void ClearWinners();
 // limit.
 int WinningCondition_LMS()
 {
+       if (warmup_stage || time <= game_starttime)
+               return WINNING_NO;
+
        entity first_player = NULL;
        int totalplayers = 0;
-       FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+       FOREACH_CLIENT(IS_PLAYER(it) && it.frags == FRAGS_PLAYER, {
                if (!totalplayers)
                        first_player = it;
                ++totalplayers;
@@ -76,10 +100,7 @@ int WinningCondition_LMS()
                                // a winner!
                                // and assign him his first place
                                GameRules_scoring_add(first_player, LMS_RANK, 1);
-                               if(warmup_stage)
-                                       return WINNING_NO;
-                               else
-                                       return WINNING_YES;
+                               return WINNING_YES;
                        }
                }
        }
@@ -113,6 +134,62 @@ int WinningCondition_LMS()
        return WINNING_NO;
 }
 
+// runs on waypoints which are attached to leaders, updates once per frame
+bool lms_waypointsprite_visible_for_player(entity this, entity player, entity view)
+{
+       if(view.lms_leader)
+               if(IS_SPEC(player))
+                       return false; // we don't want spectators of leaders to see the attached waypoint on the top of their screen
+
+       if (!lms_visible_leaders)
+               return false;
+
+       return true;
+}
+
+void lms_UpdateLeaders()
+{
+       int max_lives = 0;
+       int pl_cnt = 0;
+       FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+               int lives = GameRules_scoring_add(it, LMS_LIVES, 0);
+               if (lives > max_lives)
+                       max_lives = lives;
+               pl_cnt++;
+       });
+
+       int second_max_lives = 0;
+       int pl_cnt_with_max_lives = 0;
+       FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+               int lives = GameRules_scoring_add(it, LMS_LIVES, 0);
+               if (lives == max_lives)
+                       pl_cnt_with_max_lives++;
+               else if (lives > second_max_lives)
+                       second_max_lives = lives;
+       });
+
+       int lives_diff = autocvar_g_lms_leader_wp_lives;
+       if (max_lives - second_max_lives >= lives_diff && pl_cnt_with_max_lives <= pl_cnt * autocvar_g_lms_leader_wp_max_relative)
+               FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+                       int lives = GameRules_scoring_add(it, LMS_LIVES, 0);
+                       if (lives == max_lives)
+                       {
+                               if (!it.lms_leader)
+                                       it.lms_leader = true;
+                       }
+                       else
+                       {
+                               it.lms_leader = false;
+                       }
+               });
+       else
+               FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+                       if (it.waypointsprite_attachedforcarrier)
+                               WaypointSprite_Kill(it.waypointsprite_attachedforcarrier);
+                       it.lms_leader = false;
+               });
+}
+
 // mutator hooks
 MUTATOR_HOOKFUNCTION(lms, reset_map_global)
 {
@@ -122,10 +199,29 @@ MUTATOR_HOOKFUNCTION(lms, reset_map_global)
 MUTATOR_HOOKFUNCTION(lms, reset_map_players)
 {
        FOREACH_CLIENT(true, {
+               if (it.frags == FRAGS_PLAYER_OUT_OF_GAME)
+               {
+                       // players who forfeited (rank >= 256) become spectators
+                       if (it.lms_spectate_warning == 2)
+                               it.frags = FRAGS_SPECTATOR;
+                       else
+                               it.frags = FRAGS_PLAYER;
+               }
+
+               CS(it).killcount = 0;
+               it.lmsplayer = 0;
+               it.lms_spectate_warning = 0;
+               GameRules_scoring_add(it, LMS_RANK, -GameRules_scoring_add(it, LMS_RANK, 0));
+               GameRules_scoring_add(it, LMS_LIVES, -GameRules_scoring_add(it, LMS_LIVES, 0));
+
+               if (it.frags != FRAGS_PLAYER)
+                       continue;
+
                TRANSMUTE(Player, it);
-               it.frags = FRAGS_PLAYER;
-               GameRules_scoring_add(it, LMS_LIVES, LMS_NewPlayerLives());
                PutClientInServer(it);
+               it.lms_leader = false;
+               if (it.waypointsprite_attachedforcarrier)
+                       WaypointSprite_Kill(it.waypointsprite_attachedforcarrier);
        });
 }
 
@@ -137,74 +233,115 @@ MUTATOR_HOOKFUNCTION(lms, ReadLevelCvars)
        sv_ready_restart_after_countdown = 0;
 }
 
+// returns true if player is added to the game
+bool lms_AddPlayer(entity player)
+{
+       if (!player.lmsplayer)
+       {
+               int lives = GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives());
+               if(lives <= 0)
+                       return false;
+               player.lmsplayer = 2; // temp value indicating player has just joined the game (but not spawned yet)
+       }
+       if (warmup_stage || time <= game_starttime)
+       {
+               if(player.lms_spectate_warning)
+               {
+                       player.lms_spectate_warning = 0;
+                       GameRules_scoring_add(player, LMS_RANK, -GameRules_scoring_add(player, LMS_RANK, 0));
+                       int lives = GameRules_scoring_add(player, LMS_LIVES, 0);
+                       if(lives <= 0)
+                               GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives());
+               }
+       }
+       else
+       {
+               if(GameRules_scoring_add(player, LMS_LIVES, 0) <= 0)
+               {
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_LMS_NOLIVES);
+                       return false;
+               }
+       }
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(lms, PutClientInServer)
 {
        entity player = M_ARGV(0, entity);
-
-       if(player.frags == FRAGS_SPECTATOR)
-               TRANSMUTE(Observer, player);
-       else
+       if (!warmup_stage && (IS_BOT_CLIENT(player) || CS(player).jointime != time))
        {
-               float tl = GameRules_scoring_add(player, LMS_LIVES, 0);
-               if(tl < lms_lowest_lives)
-                       lms_lowest_lives = tl;
-               if(tl <= 0)
+               if (GameRules_scoring_add(player, LMS_RANK, 0) || !lms_AddPlayer(player))
                        TRANSMUTE(Observer, player);
-               if(warmup_stage)
-                       GameRules_scoring_add(player, LMS_RANK, -GameRules_scoring_add(player, LMS_RANK, 0));
        }
 }
 
-MUTATOR_HOOKFUNCTION(lms, ForbidSpawn)
+MUTATOR_HOOKFUNCTION(lms, PlayerSpawn)
 {
        entity player = M_ARGV(0, entity);
 
-       if(warmup_stage)
-               return false;
-       if(player.frags == FRAGS_SPECTATOR)
+       if (warmup_stage || time < game_starttime)
                return true;
-       if(GameRules_scoring_add(player, LMS_LIVES, 0) <= 0)
+
+       if (player.lmsplayer == 2) // just joined the game
        {
-               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_LMS_NOLIVES);
-               return true;
+               // spawn player with the same amount of health / armor
+               // as the least healthy player with the least number of lives
+               int pl_lives = GameRules_scoring_add(player, LMS_LIVES, 0);
+               float min_health = start_health;
+               float min_armorvalue = start_armorvalue;
+               FOREACH_CLIENT(it != player && IS_PLAYER(it) && !IS_DEAD(it) && GameRules_scoring_add(it, LMS_LIVES, 0) == pl_lives, {
+                       if (GetResource(it, RES_HEALTH) < min_health)
+                               min_health = GetResource(it, RES_HEALTH);
+                       if (GetResource(it, RES_ARMOR) < min_armorvalue)
+                               min_armorvalue = GetResource(it, RES_ARMOR);
+               });
+               if (min_health != start_health)
+                       SetResource(player, RES_HEALTH, max(1, min_health));
+               if (min_armorvalue != start_armorvalue)
+                       SetResource(player, RES_ARMOR, min_armorvalue);
+               player.lmsplayer = 1;
        }
-       return false;
 }
 
-MUTATOR_HOOKFUNCTION(lms, PlayerDies)
+MUTATOR_HOOKFUNCTION(lms, ForbidSpawn)
 {
-       entity frag_target = M_ARGV(2, entity);
+       entity player = M_ARGV(0, entity);
+
+       if (warmup_stage || lms_AddPlayer(player))
+               return false;
 
-       frag_target.respawn_flags |= RESPAWN_FORCE;
+       return true;
 }
 
 void lms_RemovePlayer(entity player)
 {
-       static int quitters = 0;
+       if (warmup_stage || time < game_starttime)
+               return;
+
        float player_rank = GameRules_scoring_add(player, LMS_RANK, 0);
        if (!player_rank)
        {
-               int pl_cnt = 0;
-               FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
-                       pl_cnt++;
-               });
                if (player.lms_spectate_warning < 2)
                {
-                       if(IS_BOT_CLIENT(player))
-                               bot_clear(player);
                        player.frags = FRAGS_PLAYER_OUT_OF_GAME;
+                       int pl_cnt = 0;
+                       FOREACH_CLIENT(IS_PLAYER(it) && it.frags == FRAGS_PLAYER, {
+                               pl_cnt++;
+                       });
                        GameRules_scoring_add(player, LMS_RANK, pl_cnt + 1);
                }
                else
                {
-                       lms_lowest_lives = 999;
+                       int min_forfeiter_rank = 665; // different from 666
                        FOREACH_CLIENT(true, {
+                               // update rank of other players that were eliminated
                                if (it.frags == FRAGS_PLAYER_OUT_OF_GAME)
                                {
                                        float it_rank = GameRules_scoring_add(it, LMS_RANK, 0);
                                        if (it_rank > player_rank && it_rank <= 256)
                                                GameRules_scoring_add(it, LMS_RANK, -1);
-                                       lms_lowest_lives = 0;
+                                       if (it_rank > 256 && it_rank <= min_forfeiter_rank)
+                                               min_forfeiter_rank = it_rank - 1;
                                }
                                else if (it.frags != FRAGS_SPECTATOR)
                                {
@@ -213,15 +350,14 @@ void lms_RemovePlayer(entity player)
                                                lms_lowest_lives = tl;
                                }
                        });
-                       GameRules_scoring_add(player, LMS_RANK, 665 - quitters); // different from 666
+                       GameRules_scoring_add(player, LMS_RANK, min_forfeiter_rank);
                        if(!warmup_stage)
-                       {
                                GameRules_scoring_add(player, LMS_LIVES, -GameRules_scoring_add(player, LMS_LIVES, 0));
-                               ++quitters;
-                       }
                        player.frags = FRAGS_PLAYER_OUT_OF_GAME;
                        TRANSMUTE(Observer, player);
                }
+               if (autocvar_g_lms_leader_wp_lives > 0)
+                       lms_UpdateLeaders();
        }
 
        if (CS(player).killcount != FRAGS_SPECTATOR && player.lms_spectate_warning < 3)
@@ -241,46 +377,95 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
        player.lms_spectate_warning = 3;
 
        lms_RemovePlayer(player);
+       player.lmsplayer = 0;
 }
 
 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
 {
        entity player = M_ARGV(0, entity);
+       bool is_forced = M_ARGV(1, bool);
 
        if (!IS_PLAYER(player))
                return true;
 
-       lms_RemovePlayer(player);
-       return true;  // prevent team reset
-}
-
-MUTATOR_HOOKFUNCTION(lms, ClientConnect)
-{
-       entity player = M_ARGV(0, entity);
-
-       if(GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives()) <= 0)
+       if (warmup_stage || time <= game_starttime)
        {
-               GameRules_scoring_add(player, LMS_RANK, 666); // mark as forced spectator for the hud code
+               GameRules_scoring_add(player, LMS_LIVES, -GameRules_scoring_add(player, LMS_LIVES, 0));
                player.frags = FRAGS_SPECTATOR;
+               TRANSMUTE(Observer, player);
+               player.lmsplayer = 0;
        }
+       else
+       {
+               if (is_forced)
+                       player.lms_spectate_warning = 2;
+               if (!GameRules_scoring_add(player, LMS_RANK, 0))
+                       lms_RemovePlayer(player);
+       }
+       return true;  // prevent team reset
 }
 
-// FIXME LMS doesn't allow clients to spectate due to its particular implementation
-MUTATOR_HOOKFUNCTION(lms, AutoJoinOnConnection)
+MUTATOR_HOOKFUNCTION(lms, ClientConnect)
 {
-       if(autocvar_g_campaign)
-               return false;
-       return true;
+       entity player = M_ARGV(0, entity);
+       player.frags = FRAGS_SPECTATOR;
 }
 
 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
 
+       // recycled REDALIVE to avoid adding a dedicated stat
+       STAT(REDALIVE, player) = lms_leaders;
+
        if(player.deadflag == DEAD_DYING)
                player.deadflag = DEAD_RESPAWNING;
 }
 
+MUTATOR_HOOKFUNCTION(lms, SV_StartFrame)
+{
+       float leader_time = autocvar_g_lms_leader_wp_time;
+       float leader_repeat_time = leader_time + autocvar_g_lms_leader_wp_time_repeat;
+       lms_visible_leaders_prev = lms_visible_leaders;
+       lms_visible_leaders = (time % leader_repeat_time < leader_time);
+       if (lms_visible_leaders_prev && !lms_visible_leaders)
+               lms_leader_time_jitter = random() * autocvar_g_lms_leader_wp_time_jitter;
+       leader_repeat_time += lms_leader_time_jitter;
+
+       lms_leaders = 0;
+       FOREACH_CLIENT(true, {
+               STAT(OBJECTIVE_STATUS, it) = lms_visible_leaders;
+               if (IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME)
+               {
+                       if (it.lms_leader)
+                       {
+                               if (!it.waypointsprite_attachedforcarrier)
+                               {
+                                       WaypointSprite_AttachCarrier(WP_LmsLeader, it, RADARICON_FLAGCARRIER);
+                                       it.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = lms_waypointsprite_visible_for_player;
+                                       WaypointSprite_UpdateRule(it.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
+                                       vector pl_color = colormapPaletteColor(it.clientcolors & 0x0F, false);
+                                       WaypointSprite_UpdateTeamRadar(it.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, pl_color);
+                                       WaypointSprite_Ping(it.waypointsprite_attachedforcarrier);
+                               }
+                               if (!lms_visible_leaders_prev && lms_visible_leaders && IS_REAL_CLIENT(it))
+                                       Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_LMS_VISIBLE_LEADER);
+                               lms_leaders++;
+                       }
+               }
+               else
+               {
+                       if (IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME)
+                       {
+                               if (!lms_visible_leaders_prev && lms_visible_leaders && IS_REAL_CLIENT(it))
+                                       Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_LMS_VISIBLE_OTHER);
+                       }
+                       if (it.waypointsprite_attachedforcarrier)
+                               WaypointSprite_Kill(it.waypointsprite_attachedforcarrier);
+               }
+       });
+}
+
 MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
 {
        if(autocvar_g_lms_regenerate)
@@ -288,17 +473,97 @@ MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(lms, PlayerPowerups)
+{
+       entity player = M_ARGV(0, entity);
+       if (player.waypointsprite_attachedforcarrier)
+               player.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
+       else
+               player.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
+}
+
 MUTATOR_HOOKFUNCTION(lms, ForbidThrowCurrentWeapon)
 {
        // forbode!
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(lms, Damage_Calculate)
+{
+       if (!autocvar_g_lms_dynamic_vampire)
+               return;
+
+       entity frag_attacker = M_ARGV(1, entity);
+       entity frag_target = M_ARGV(2, entity);
+       float frag_damage = M_ARGV(4, float);
+
+       if (IS_PLAYER(frag_attacker) && !IS_DEAD(frag_attacker)
+               && IS_PLAYER(frag_target) && !IS_DEAD(frag_target) && frag_attacker != frag_target)
+       {
+               float vampire_factor = 0;
+
+               int frag_attacker_lives = GameRules_scoring_add(frag_attacker, LMS_LIVES, 0);
+               int frag_target_lives = GameRules_scoring_add(frag_target, LMS_LIVES, 0);
+               int diff = frag_target_lives - frag_attacker_lives - autocvar_g_lms_dynamic_vampire_min_lives_diff;
+
+               if (diff >= 0)
+                       vampire_factor = autocvar_g_lms_dynamic_vampire_factor_base + diff * autocvar_g_lms_dynamic_vampire_factor_increase;
+               if (vampire_factor > 0)
+               {
+                       vampire_factor = min(vampire_factor, autocvar_g_lms_dynamic_vampire_factor_max);
+                       SetResourceExplicit(frag_attacker, RES_HEALTH,
+                               min(GetResource(frag_attacker, RES_HEALTH) + frag_damage * vampire_factor, start_health));
+               }
+       }
+}
+
+MUTATOR_HOOKFUNCTION(lms, PlayerDied)
+{
+       if (!warmup_stage && autocvar_g_lms_leader_wp_lives > 0)
+               lms_UpdateLeaders();
+}
+
+MUTATOR_HOOKFUNCTION(lms, CalculateRespawnTime)
+{
+       entity player = M_ARGV(0, entity);
+       player.respawn_flags |= RESPAWN_FORCE;
+
+       int pl_lives = GameRules_scoring_add(player, LMS_LIVES, 0);
+       if (pl_lives <= 0)
+       {
+               player.respawn_flags = RESPAWN_SILENT;
+               // prevent unwanted sudden rejoin as spectator and movement of spectator camera
+               player.respawn_time = time + 2;
+               return true;
+       }
+
+       if (autocvar_g_lms_dynamic_respawn_delay <= 0)
+               return false;
+
+       int max_lives = 0;
+       int pl_cnt = 0;
+       FOREACH_CLIENT(it != player && IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+               int lives = GameRules_scoring_add(it, LMS_LIVES, 0);
+               if (lives > max_lives)
+                       max_lives = lives;
+               pl_cnt++;
+       });
+
+       // min delay with only 2 players
+       if (pl_cnt == 1) // player wasn't counted
+               max_lives = 0;
+
+       float dlay = autocvar_g_lms_dynamic_respawn_delay_base +
+               autocvar_g_lms_dynamic_respawn_delay_increase * max(0, max_lives - pl_lives);
+       player.respawn_time = time + min(autocvar_g_lms_dynamic_respawn_delay_max, dlay);
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
 {
        entity frag_target = M_ARGV(1, entity);
 
-       if (!warmup_stage)
+       if (!warmup_stage && time > game_starttime)
        {
                // remove a life
                int tl = GameRules_scoring_add(frag_target, LMS_LIVES, -1);
@@ -307,11 +572,9 @@ MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
                if(tl <= 0)
                {
                        int pl_cnt = 0;
-                       FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
+                       FOREACH_CLIENT(IS_PLAYER(it) && it.frags == FRAGS_PLAYER, {
                                pl_cnt++;
                        });
-                       if(IS_BOT_CLIENT(frag_target))
-                               bot_clear(frag_target);
                        frag_target.frags = FRAGS_PLAYER_OUT_OF_GAME;
                        GameRules_scoring_add(frag_target, LMS_RANK, pl_cnt);
                }
@@ -358,6 +621,7 @@ void lms_extralife(entity this)
 
 MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
 {
+       if (MUTATOR_RETURNVALUE) return false;
        if (!autocvar_g_powerups) return false;
        if (!autocvar_g_lms_extra_lives) return false;
 
@@ -379,12 +643,14 @@ MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
 
 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
 {
+       if(MUTATOR_RETURNVALUE) return false;
+
        entity item = M_ARGV(0, entity);
        entity toucher = M_ARGV(1, entity);
 
        if(item.itemdef == ITEM_ExtraLife)
        {
-               Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
+               Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_lms_extra_lives);
                GameRules_scoring_add(toucher, LMS_LIVES, autocvar_g_lms_extra_lives);
                return MUT_ITEMTOUCH_PICKUP;
        }
@@ -395,7 +661,8 @@ MUTATOR_HOOKFUNCTION(lms, ItemTouch)
 MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
 {
        FOREACH_CLIENT(IS_REAL_CLIENT(it), {
-               ++M_ARGV(0, int); // activerealplayers
+               if (it.lmsplayer && it.lms_spectate_warning < 2)
+                       ++M_ARGV(0, int); // activerealplayers
                ++M_ARGV(1, int); // realplayers
        });
 
@@ -406,7 +673,7 @@ MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
 {
        entity player = M_ARGV(0, entity);
 
-       if(warmup_stage || player.lms_spectate_warning)
+       if(warmup_stage || time < game_starttime || player.lms_spectate_warning)
        {
                // for the forfeit message...
                player.lms_spectate_warning = 2;
@@ -437,7 +704,9 @@ MUTATOR_HOOKFUNCTION(lms, SetWeaponArena)
 
 MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus)
 {
-       return true;
+       entity player = M_ARGV(0, entity);
+
+       return boolean(player.lmsplayer);
 }
 
 MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
@@ -449,5 +718,5 @@ MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
 
 void lms_Initialize()
 {
-       lms_lowest_lives = 9999;
+       lms_lowest_lives = 999;
 }