mod - hudbars+hbarmor+hbhunger - make check for max_hp witout segfault old engines

* upstream minenux upgrade updated, do not segfault on old engines
* use right supported check for version string
* do not make redundant checks and set of hp_max
* property set log warning notification when parts of mod are not used
* autodetect armor mod and able to work without it
master
mckaygerhard 2023-07-26 01:08:57 -04:00
parent 93f17cd1f6
commit c3edca70aa
2 changed files with 44 additions and 44 deletions

View File

@ -50,12 +50,6 @@ end
hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 40)
hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 20)
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
hbarmor.autohide = (true and not hb.settings.forceload_default_hudbars)
hbhunger.HUD_TICK = 0.2

View File

@ -24,6 +24,10 @@ end
local N = function(s) return s end
local modarmors = minetest.get_modpath("3d_armor")
local modhbarm = minetest.get_modpath("hbarmor")
local modhbhung = minetest.get_modpath("hbhunger")
if (not armor) or (not armor.def) then
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
end
@ -65,9 +69,6 @@ hbarmor.autohide = true
hb.settings = {}
hb.hba = minetest.get_modpath("hbarmor")
hb.hbh = minetest.get_modpath("hbhunger")
function hb.load_setting(sname, stype, defaultval, valid_values)
local sval
if stype == "string" then
@ -102,7 +103,20 @@ end
-- Load default settings
dofile(minetest.get_modpath("hudbars").."/default_settings.lua")
if not hb.hbh then
local serverinfo = minetest.get_version()
local statusinfo = serverinfo.string
if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.3") then
hb.settings.hp_player_maximun = 20
hb.settings.br_player_maximun = 10
minetest.log("error","[hudbars] minetest version do not support customization of hp_max healt player values")
minetest.PLAYER_MAX_HP = hb.settings.hp_player_maximun
else
minetest.PLAYER_MAX_HP_DEFAULT = hb.settings.hp_player_maximun
end
-- all settings configured
if not modhbhung then
-- due lackof global hbhunger these need to be first
hbhunger.get_hunger_raw = function(player)
@ -142,25 +156,16 @@ local function player_exists(player)
end
local must_hide = function(playername, arm)
return ((not armor.def[playername].count or armor.def[playername].count == 0 or not hb.settings.forceload_default_hudbars) and arm == 0)
if modarmors then
return ((not armor.def[playername].count or armor.def[playername].count == 0 or not hb.settings.forceload_default_hudbars) and arm == 0)
end
return (modarmors and hbarmor.autohide)
end
local arm_printable = function(arm)
return math.ceil(math.floor(arm+0.5))
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.3") 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 = {}
@ -228,7 +233,6 @@ 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
@ -417,7 +421,6 @@ 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)
@ -607,10 +610,10 @@ if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_
end
hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = hicon, bgicon = nil }, hb.settings.hp_player_maximun, hb.settings.hp_player_maximun, false)
hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = bicon, bgicon = nil }, hb.settings.br_player_maximun, hb.settings.br_player_maximun, false)
if not hb.hba then
if not modhbarm then
hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { bar = "hbarmor_bar.png", icon = aicon, bgicon = nil }, 0, 100, hbarmor.autohide, N("@1: @2%"), { order = { "label", "value" } } )
end
if not hb.hbh then
if not modhbhung then
hb.register_hudbar("satiation", 0xFFFFFF, S("Satiation"), { bar = "hbhunger_bar.png", icon = sicon, bgicon = nil }, hbhunger.SAT_INIT, hbhunger.SAT_MAX, false, nil, { format_value = "%02d", format_max_value = "%02d" })
end
end
@ -622,13 +625,14 @@ local function hide_builtin(player)
player:hud_set_flags(flags)
end
if not hb.hba then
if not modhbarm and modarmors then
function hbarmor.get_armor(player)
if not player or not armor.def then
return false
end
local name = player:get_player_name()
local def = armor.def[name] or nil
if def and def.state and def.count then
hbarmor.set_armor(name, def.state, def.count)
@ -670,7 +674,7 @@ local function custom_hud(player)
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)
if not hb.hba then
if not modhbarm and modarmors then
local arm = tonumber(hbarmor.armor[name])
if not arm then arm = 0 end
local hide_ar = hbarmor.autohide and must_hide(name, arm)
@ -679,7 +683,7 @@ local function custom_hud(player)
hb.init_hudbar(player, "armor", arm_printable(arm), 100, hide_ar)
end
if not hb.hbh then
if not modhbhung then
hb.init_hudbar(player, "satiation", hbhunger.get_hunger_raw(player), nil, (not hb.settings.forceload_default_hudbars) )
end
end
@ -714,7 +718,7 @@ local function update_hud(player)
--health
update_health(player)
-- armor
if not hb.hba then
if not modhbarm and modarmors then
local larmor = hbarmor.armor[name]
local arm = tonumber(larmor)
if not arm then arm = 0; hbarmor.armor[name] = 0 end
@ -731,7 +735,7 @@ local function update_hud(player)
end
end
-- hunger
if not hb.hbh then
if not modhbhung then
local h_out = tonumber(hbhunger.hunger_out[name])
local h = tonumber(hbhunger.hunger[name])
if h_out ~= h then
@ -759,7 +763,7 @@ minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
update_health(player)
if not hb.hbh then
if not modhbhung then
hbhunger.hunger[name] = hbhunger.SAT_INIT
hbhunger.set_hunger_raw(player)
hbhunger.exhaustion[name] = 0
@ -772,7 +776,7 @@ minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local inv = player:get_inventory()
if not hb.hbh then
if not modhbhung then
inv:set_size("hunger",1)
hbhunger.hunger[name] = hbhunger.get_hunger_raw(player)
hbhunger.hunger_out[name] = hbhunger.hunger[name]
@ -782,10 +786,10 @@ minetest.register_on_joinplayer(function(player)
hide_builtin(player)
custom_hud(player)
hb.players[name] = player
if not hb.hba then
if not modhbarm then
hbarmor.player_active[name] = true
end
if not hb.hbh then
if not modhbhung then
hbhunger.set_hunger_raw(player)
end
end)
@ -795,18 +799,20 @@ minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
hb.players[name] = nil
if not hb.hba then
if not modhbarm then
hbarmor.player_active[name] = false
end
end)
local modresult = ""
if modhbarm then
minetest.log("warning","[hudbars] not using build-in hbarmor")
end
if hb.hba then modresult = modresult .. " without build-in hbarmor" end
if hb.hbh then modresult = modresult .. " without build-in hbhunger" end
minetest.log("[MOD] hudbars"..modresult.." loaded" )
if modhbhung then
minetest.log("warning","[hudbars] not using build-in hbarmor")
end
minetest.log("[MOD] hudbars loaded" )
local main_timer = 0
local timer = 0
@ -824,7 +830,7 @@ minetest.register_globalstep(function(dtime)
for _, player in pairs(hb.players) do
update_hud(player)
end
if not hb.hba then
if not modhbarm and modarmors then
-- update all hud elements
for _,player in ipairs(minetest.get_connected_players()) do
if player_exists(player) then
@ -838,7 +844,7 @@ minetest.register_globalstep(function(dtime)
end
end
end
if not hb.hbh then
if not modhbhung then
-- satiaton are internal properties, so update live (not hb) player properties
if timer > 4 or timer2 > hbhunger.HUNGER_TICK then
for _,player in ipairs(minetest.get_connected_players()) do