+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;
+}
+