backguard compatibility of hp_max in older clients, (missing breath_max)

* honoring customizations of hp_max its not so valid in older
  clients becouse of a bug in older lients of hardcoded healt player
  at f7d50a8078
  long time ago user requested https://github.com/minetest/minetest/issues/2246
  the value was hardcoded into engine and do not allow to be
  customized by mods until the commit above, this patch
  takes that into consideration and set the value to 20.
* NOTE: as side effect if you started a server that support
  hp_max modification and try to connect using a older client,
  client will perfectly supports the already configured healt
  from client, but will start at 20 initialy, of course with
  max_hp supported over the value of 20
master
mckaygerhard 2023-07-18 23:07:28 -04:00
parent c219b708f8
commit 0edeb5599e
2 changed files with 20 additions and 0 deletions

View File

@ -50,3 +50,8 @@ end
hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 20)
hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 10)
if minetest.has_feature("object_use_texture_alpha") then
core.PLAYER_MAX_HP_DEFAULT = hb.settings.hp_player_maximun
else
core.PLAYER_MAX_HP = hb.settings.hp_player_maximun
end

View File

@ -74,6 +74,19 @@ local function player_exists(player)
return player ~= nil and player:is_player()
end
local function checksupportmax(player)
local statusinfo = minetest.get_server_status()
if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.5") then
hb.settings.hp_player_maximun = 20
hb.settings.br_player_maximun = 10
if player_exists(player) then
player:set_properties({hp_max = 20})
else
minetest.log("error","[hudbars] WARNING! minetest version do not support customization of hp_max healt player values")
end
end
end
local function make_label(format_string, format_string_config, label, start_value, max_value)
local params = {}
local order = format_string_config.order
@ -143,6 +156,7 @@ function hb.get_hudbar_position_index(identifier)
end
function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string, format_string_config)
checksupportmax()
minetest.log("action", "hb.register_hudbar: "..tostring(identifier))
local hudtable = {}
local pos, offset
@ -331,6 +345,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
end
function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)
checksupportmax(player)
if not player_exists(player) then return false end
local hudtable = hb.get_hudtable(identifier)
hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden)