hpchange: add (nonworking) potential change marker

This commit is contained in:
cron 2020-10-04 15:19:56 +00:00
parent 1ff64b4fa1
commit bce8e36fc3

View File

@ -15,7 +15,7 @@ local function show_widget()
}) })
end end
local function update_hud(delta) local function update_hud(delta, potential)
if minetest.localplayer ~= nil and delta ~= 0 then if minetest.localplayer ~= nil and delta ~= 0 then
if widget == nil then if widget == nil then
show_widget() show_widget()
@ -28,7 +28,11 @@ local function update_hud(delta)
num = "+" .. num num = "+" .. num
end end
minetest.localplayer:hud_change(widget, "text", "Last HP change: " .. num) if potential then
minetest.localplayer:hud_change(widget, "text", "Last HP change (potential): " .. num)
else
minetest.localplayer:hud_change(widget, "text", "Last HP change: " .. num)
end
if delta > 0 then if delta > 0 then
minetest.localplayer:hud_change(widget, "number", 0x00FF00) minetest.localplayer:hud_change(widget, "number", 0x00FF00)
@ -42,16 +46,30 @@ local function update_hud(delta)
end end
end end
local function init_last()
if last_hp == nil and minetest.localplayer ~= nil then
last_hp = minetest.localplayer:get_hp()
end
end
-- health decrease (potential) -- health decrease (potential)
minetest.register_on_damage_taken(function(hp) minetest.register_on_damage_taken(function(hp)
update_hud(-hp) if minetest.localplayer ~= nil then
-- this should be true if no fall damage is on
-- the localplayer hp is wrong though
if last_hp == minetest.localplayer:get_hp() then
update_hud(-hp, true)
else
update_hud(-hp)
end
init_last()
end
end) end)
-- health increase -- health increase
minetest.register_on_hp_modification(function(hp) minetest.register_on_hp_modification(function(hp)
if last_hp == nil and minetest.localplayer ~= nil then init_last()
last_hp = minetest.localplayer:get_hp()
end
if last_hp ~= nil and last_hp <= hp then if last_hp ~= nil and last_hp <= hp then
update_hud(hp - last_hp) update_hud(hp - last_hp)