Fix crash on `math.round` field as `nil` (#11)

Co-authored-by: sys4 <bricassa@sys4.fr>
This commit is contained in:
sys4-fr 2021-11-10 00:20:25 +00:00 committed by GitHub
parent 7c916f93a0
commit 98f346882d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,10 @@
-- Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - MIT License
-- See `LICENSE.md` included in the source distribution for details.
local function round(v)
return math.floor(v + 0.5)
end
local enabled = minetest.settings:get_bool("health_bars") ~= false
if enabled then
enabled = minetest.settings:get_bool("enable_damage")
@ -36,7 +40,7 @@ local function scaleToDefault(player, field)
-- Scale "hp" or "breath" to supported amount
local current = player["get_" .. field](player)
local max_display = math.max(player:get_properties()[field .. "_max"], current)
return math.round(current / max_display * max[field])
return round(current / max_display * max[field])
end
minetest.register_entity("gauges:hp_bar", {