From 8b706130aa01d95747050c5462bf6a0fb57cdd78 Mon Sep 17 00:00:00 2001 From: Anand S Date: Thu, 7 Mar 2019 10:19:35 +0530 Subject: [PATCH] Fix medkits HP leak due to missing check --- mods/pvp/medkits/init.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mods/pvp/medkits/init.lua b/mods/pvp/medkits/init.lua index 8b208d4..80c8f67 100644 --- a/mods/pvp/medkits/init.lua +++ b/mods/pvp/medkits/init.lua @@ -21,16 +21,17 @@ end -- Aborts if player is already healing local function start_healing(stack, player) if not player then - return stack + return end local name = player:get_player_name() + local hp = player:get_hp() - if players[name] or player:get_hp() >= regen_max then - return stack + if players[name] or hp >= regen_max then + return end players[name] = { - hp = player:get_hp(), + hp = hp, pos = player:get_pos(), hud = player:hud_add({ hud_elem_type = "image", @@ -82,12 +83,14 @@ minetest.register_globalstep(function(dtime) end -- Stop healing if target reached - local hp = player:get_hp() - if hp < regen_max then - player:set_hp(hp + regen_step) - else - player:set_hp(regen_max) - stop_healing(player) + if players[name] then + local hp = player:get_hp() + if hp < regen_max then + player:set_hp(math.min(hp + regen_step, regen_max)) + else + player:set_hp(regen_max) + stop_healing(player) + end end end end