2018-11-02 21:20:51 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-04 00:52:21 -05:00
|
|
|
local minetest, pairs
|
|
|
|
= minetest, pairs
|
2018-11-02 21:20:51 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2018-10-29 22:37:57 -04:00
|
|
|
local health_bar_definition =
|
|
|
|
{
|
|
|
|
hud_elem_type = "statbar",
|
2019-02-04 20:15:33 -05:00
|
|
|
position = {x = 0.5, y = 1},
|
2019-03-03 16:53:12 -05:00
|
|
|
text = "nc_player_hud_heart_bg.png",
|
2018-10-29 22:37:57 -04:00
|
|
|
number = 20,
|
|
|
|
direction = 0,
|
2019-02-04 20:15:33 -05:00
|
|
|
size = {x = 24, y = 24},
|
|
|
|
offset = { x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
|
2018-10-29 22:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local breath_bar_definition =
|
|
|
|
{
|
|
|
|
hud_elem_type = "statbar",
|
2019-02-04 20:15:33 -05:00
|
|
|
position = {x = 0.5, y = 1},
|
2019-03-03 16:53:12 -05:00
|
|
|
text = "nc_player_hud_bubble_bg.png",
|
2019-03-04 00:52:21 -05:00
|
|
|
number = 0,
|
2018-10-29 22:37:57 -04:00
|
|
|
direction = 0,
|
2019-02-04 20:15:33 -05:00
|
|
|
size = {x = 24, y = 24},
|
|
|
|
offset = {x = 25, y = -(48 + 24 + 16)},
|
2018-10-29 22:37:57 -04:00
|
|
|
}
|
|
|
|
|
2019-03-04 00:52:21 -05:00
|
|
|
local wield_bar_definition =
|
|
|
|
{
|
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x = 0.5, y = 1},
|
|
|
|
text = "",
|
|
|
|
number = 0xFFFFFF,
|
|
|
|
direction = 0,
|
|
|
|
size = {x = 24, y = 24},
|
|
|
|
offset = {x = 25, y = -(48 + 24 + 8)},
|
|
|
|
alignment = {x = 1, y = 0.5}
|
|
|
|
}
|
|
|
|
|
|
|
|
local huds = {}
|
|
|
|
|
|
|
|
local function dohuds(player)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local hud = huds[pname]
|
|
|
|
if not hud then
|
|
|
|
huds[pname] = {
|
|
|
|
healthid = player:hud_add(health_bar_definition),
|
|
|
|
breathid = player:hud_add(breath_bar_definition),
|
|
|
|
wieldid = player:hud_add(wield_bar_definition)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
2018-10-29 22:37:57 -04:00
|
|
|
|
|
|
|
if player:get_breath() < 11 then
|
2019-03-04 00:52:21 -05:00
|
|
|
if hud.val ~= true then
|
|
|
|
hud.val = true
|
|
|
|
player:hud_change(hud.breathid, "number", 20)
|
|
|
|
player:hud_change(hud.wieldid, "text", "")
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if hud.val == true then
|
|
|
|
player:hud_change(hud.breathid, "number", 0)
|
|
|
|
hud.val = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local t
|
|
|
|
local s = player:get_wielded_item()
|
|
|
|
if s and (not s:is_empty()) then
|
|
|
|
t = s:get_meta():get_string("description")
|
|
|
|
if t == "" then
|
|
|
|
local d = minetest.registered_items[s:get_name()]
|
|
|
|
t = d and d.description
|
|
|
|
end
|
|
|
|
end
|
|
|
|
t = t or ""
|
|
|
|
if t ~= hud.val then
|
|
|
|
hud.val = t
|
|
|
|
player:hud_change(hud.wieldid, "text", t)
|
2018-10-29 22:37:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-04 00:52:21 -05:00
|
|
|
minetest.register_globalstep(function()
|
|
|
|
for _, p in pairs(minetest.get_connected_players()) do
|
|
|
|
dohuds(p)
|
|
|
|
end
|
|
|
|
end)
|
2018-10-29 22:37:57 -04:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2019-03-04 00:52:21 -05:00
|
|
|
huds[player:get_player_name()] = nil
|
2019-03-03 16:53:12 -05:00
|
|
|
player:hud_set_hotbar_itemcount(8)
|
|
|
|
player:hud_set_hotbar_image("nc_player_hud_bar.png")
|
|
|
|
player:hud_set_hotbar_selected_image("nc_player_hud_sel.png")
|
2018-11-02 21:20:51 -04:00
|
|
|
end)
|