hpchange: add (nonworking) potential change marker
This commit is contained in:
parent
1ff64b4fa1
commit
bce8e36fc3
@ -15,7 +15,7 @@ local function show_widget()
|
||||
})
|
||||
end
|
||||
|
||||
local function update_hud(delta)
|
||||
local function update_hud(delta, potential)
|
||||
if minetest.localplayer ~= nil and delta ~= 0 then
|
||||
if widget == nil then
|
||||
show_widget()
|
||||
@ -28,7 +28,11 @@ local function update_hud(delta)
|
||||
num = "+" .. num
|
||||
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
|
||||
minetest.localplayer:hud_change(widget, "number", 0x00FF00)
|
||||
@ -42,16 +46,30 @@ local function update_hud(delta)
|
||||
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)
|
||||
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)
|
||||
|
||||
-- health increase
|
||||
minetest.register_on_hp_modification(function(hp)
|
||||
if last_hp == nil and minetest.localplayer ~= nil then
|
||||
last_hp = minetest.localplayer:get_hp()
|
||||
end
|
||||
init_last()
|
||||
|
||||
if last_hp ~= nil and last_hp <= hp then
|
||||
update_hud(hp - last_hp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user