don't trigger armor:punch when max_hp decreases

This commit is contained in:
flux 2023-04-19 14:02:29 -07:00 committed by Buckaroo Banzai
parent dc7fbce09a
commit 053c30b8b1
1 changed files with 21 additions and 13 deletions

View File

@ -414,21 +414,29 @@ if armor.config.punch_damage == true then
end end
minetest.register_on_player_hpchange(function(player, hp_change, reason) minetest.register_on_player_hpchange(function(player, hp_change, reason)
if player and reason.type ~= "drown" and reason.hunger == nil if not minetest.is_player(player) then
and hp_change < 0 then return hp_change
local name = player:get_player_name() end
if name then
local heal = armor.def[name].heal if reason.type == "drown" or reason.hunger or hp_change >= 0 then
if heal >= math.random(100) then return hp_change
hp_change = 0 end
end
-- check if armor damage was handled by fire or on_punchplayer local name = player:get_player_name()
local time = last_punch_time[name] or 0 local properties = player:get_properties()
if time == 0 or time + 1 < minetest.get_gametime() then local hp = player:get_hp()
armor:punch(player) if hp + hp_change < properties.hp_max then
end local heal = armor.def[name].heal
if heal >= math.random(100) then
hp_change = 0
end
-- check if armor damage was handled by fire or on_punchplayer
local time = last_punch_time[name] or 0
if time == 0 or time + 1 < minetest.get_gametime() then
armor:punch(player)
end end
end end
return hp_change return hp_change
end, true) end, true)