Ensure minimum value of 0

master
Wuzzy 2016-11-10 15:57:51 +01:00
parent d4bc5dc190
commit c4ddb7b344
1 changed files with 3 additions and 3 deletions

View File

@ -84,7 +84,7 @@ if(minetest.setting_getbool("enable_damage") == true) then
minetest.chat_send_player(name, S("This is not a number.")) minetest.chat_send_player(name, S("This is not a number."))
return return
end 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)) player:set_hp(tonumber(hp))
end, end,
}) })
@ -107,7 +107,7 @@ if(minetest.setting_getbool("enable_damage") == true) then
return return
end end
local hp = tonumber(hearts) * 2 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) player:set_hp(hp)
end, end,
}) })
@ -129,7 +129,7 @@ if(minetest.setting_getbool("enable_damage") == true) then
minetest.chat_send_player(name, S("This is not a number.")) minetest.chat_send_player(name, S("This is not a number."))
return return
end end
local bp = tonumber(breath) local bp = math.max(0, tonumber(breath)) -- ensure minimum value of 0
player:set_breath(bp) player:set_breath(bp)
end, end,
}) })