2015-04-18 21:23:22 +02:00
|
|
|
-- Based on 4itemnames mod by 4aiman
|
2014-05-26 11:43:25 +02:00
|
|
|
|
2014-05-26 05:41:40 +02:00
|
|
|
local wield = {}
|
|
|
|
local huds = {}
|
|
|
|
local dtimes = {}
|
2015-04-18 21:23:22 +02:00
|
|
|
local dlimit = 3 -- HUD element will be hidden after this many seconds
|
|
|
|
local air_hud_mod = minetest.get_modpath("4air")
|
|
|
|
local hud_mod = minetest.get_modpath("hud")
|
2015-10-02 20:01:07 +02:00
|
|
|
local hudbars_mod = minetest.get_modpath("hudbars")
|
2014-05-26 05:41:40 +02:00
|
|
|
|
2015-04-18 21:23:22 +02:00
|
|
|
local function set_hud(player)
|
2014-05-26 05:41:40 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local off = {x=0, y=-70}
|
2015-04-18 21:23:22 +02:00
|
|
|
if air_hud_mod or hud_mod then
|
|
|
|
off.y = off.y - 20
|
2015-10-02 20:01:07 +02:00
|
|
|
elseif hudbars_mod then
|
|
|
|
off.y = off.y + 13
|
2014-05-26 05:41:40 +02:00
|
|
|
end
|
|
|
|
huds[player_name] = player:hud_add({
|
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x=0.5, y=1},
|
|
|
|
offset = off,
|
|
|
|
alignment = {x=0, y=0},
|
|
|
|
number = 0xFFFFFF ,
|
|
|
|
text = "",
|
|
|
|
})
|
2015-04-18 21:23:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
minetest.after(0, set_hud, player)
|
2014-05-26 05:41:40 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2015-04-18 21:23:22 +02:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2014-05-26 05:41:40 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local wstack = player:get_wielded_item():get_name()
|
|
|
|
|
|
|
|
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
|
|
|
dtimes[player_name] = dtimes[player_name] + dtime
|
|
|
|
if dtimes[player_name] > dlimit and huds[player_name] then
|
|
|
|
player:hud_change(huds[player_name], 'text', "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if wstack ~= wield[player_name] then
|
|
|
|
wield[player_name] = wstack
|
|
|
|
dtimes[player_name] = 0
|
|
|
|
if huds[player_name] then
|
2015-04-18 21:23:22 +02:00
|
|
|
local def = minetest.registered_items[wstack]
|
|
|
|
local desc = def and def.description or ""
|
2014-05-26 05:41:40 +02:00
|
|
|
player:hud_change(huds[player_name], 'text', desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2015-04-18 21:23:22 +02:00
|
|
|
|