diff --git a/init.lua b/init.lua index 52f287f..88ac2ea 100644 --- a/init.lua +++ b/init.lua @@ -84,7 +84,7 @@ if(minetest.setting_getbool("enable_damage") == true) then minetest.chat_send_player(name, S("This is not a number.")) return end - hp = math.floor(hp+0.5) -- round the number + hp = math.max(0, math.floor(hp+0.5)) -- round the number, ensure minimum value of 0 player:set_hp(tonumber(hp)) end, }) @@ -107,7 +107,7 @@ if(minetest.setting_getbool("enable_damage") == true) then return end local hp = tonumber(hearts) * 2 - hp = math.floor(hp+0.5) -- round the number + hp = math.max(0, math.floor(hp+0.5)) -- round the number, ensure minimum value of 0 player:set_hp(hp) end, }) @@ -129,7 +129,7 @@ if(minetest.setting_getbool("enable_damage") == true) then minetest.chat_send_player(name, S("This is not a number.")) return end - local bp = tonumber(breath) + local bp = math.max(0, tonumber(breath)) -- ensure minimum value of 0 player:set_breath(bp) end, })