Fix error when item isn't provided to core.hud_replace_builtin (#12484)

This commit is contained in:
rubenwardy 2022-07-02 18:28:11 +01:00 committed by GitHub
parent 45da0d43fd
commit b095dc4f2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -138,13 +138,15 @@ local function player_event_handler(player,eventname)
end end
function core.hud_replace_builtin(hud_name, definition) function core.hud_replace_builtin(hud_name, definition)
if type(definition) ~= "table" or if type(definition) ~= "table" or
definition.hud_elem_type ~= "statbar" then definition.hud_elem_type ~= "statbar" then
return false return false
end end
definition = table.copy(definition)
if hud_name == "health" then if hud_name == "health" then
definition.item = definition.item or definition.number or core.PLAYER_MAX_HP_DEFAULT
bar_definitions.hp = definition bar_definitions.hp = definition
for name, ids in pairs(hud_ids) do for name, ids in pairs(hud_ids) do
@ -159,6 +161,7 @@ function core.hud_replace_builtin(hud_name, definition)
end end
if hud_name == "breath" then if hud_name == "breath" then
definition.item = definition.item or definition.number or core.PLAYER_MAX_BREATH_DEFAULT
bar_definitions.breath = definition bar_definitions.breath = definition
for name, ids in pairs(hud_ids) do for name, ids in pairs(hud_ids) do