workaround in rare cases for get_properties when join players
* sometimes `player:get_properties().something` returns `nil` if you called inside `minetest.register_on_joinplayer()`, so it triggers an "attempt to index a nil value" error when called * considering the following reports: the second bug is pretty super common, still in 5.5 version of engine minetest, of course its mod update issue but still valid * https://github.com/minetest/minetest/issues/12350 * https://github.com/minetest/minetest/issues/13343 * https://codeberg.org/Wuzzy/minetest_hudbars/issues/4 * this is a merge of https://codeberg.org/Wuzzy/minetest_hudbars/pulls/5master
parent
965a67a9c1
commit
20843d95ce
21
init.lua
21
init.lua
|
@ -489,12 +489,21 @@ local function custom_hud(player)
|
|||
end
|
||||
local hp = player:get_hp()
|
||||
local hp_max = player:get_properties().hp_max
|
||||
hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide)
|
||||
local breath = player:get_breath()
|
||||
local breath_max = player:get_properties().breath_max
|
||||
local hide_breath
|
||||
if breath >= breath_max and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
|
||||
hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath or hide)
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
hb.init_hudbar(player, "health", hp, hp_max, hide)
|
||||
if hp_max then
|
||||
hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide)
|
||||
end
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
if breath == 11 and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
|
||||
hb.init_hudbar(player, "breath", math.min(breath, 10), breath_max, hide_breath or hide)
|
||||
if breath_max then
|
||||
if breath >= breath_max and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
|
||||
hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath or hide)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -512,8 +521,12 @@ local function update_hud(player)
|
|||
hb.unhide_hudbar(player, "health")
|
||||
end
|
||||
--air
|
||||
local breath_max = player:get_properties().breath_max
|
||||
local breath_max = 10
|
||||
local breath = player:get_breath()
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
if player:get_properties() then
|
||||
if player:get_properties().breath_max then breath_max = player:get_properties().breath_max end
|
||||
end
|
||||
|
||||
if breath >= breath_max and hb.settings.autohide_breath == true then
|
||||
hb.hide_hudbar(player, "breath")
|
||||
|
|
Loading…
Reference in New Issue