mirror of
https://repo.or.cz/minetest_hudbars.git
synced 2025-06-28 22:46:06 +02:00
Compare commits
2 Commits
1.0.0
...
playertest
Author | SHA1 | Date | |
---|---|---|---|
ef30c34609 | |||
4ebc24f2ed |
16
init.lua
16
init.lua
@ -19,6 +19,9 @@ hb.settings.start_offset_right = { x = 15, y = -70 }
|
|||||||
hb.settings.vmargin = 24
|
hb.settings.vmargin = 24
|
||||||
hb.settings.tick = 0.1
|
hb.settings.tick = 0.1
|
||||||
|
|
||||||
|
-- Table which contains all players with active default HUD bars (only for internal use)
|
||||||
|
hb.players = {}
|
||||||
|
|
||||||
function hb.value_to_barlength(value, max)
|
function hb.value_to_barlength(value, max)
|
||||||
if max == 0 then
|
if max == 0 then
|
||||||
return 0
|
return 0
|
||||||
@ -293,13 +296,13 @@ end
|
|||||||
local function update_hud(player)
|
local function update_hud(player)
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
--air
|
--air
|
||||||
local air = player:get_breath()
|
local breath = player:get_breath()
|
||||||
|
|
||||||
if air == 11 then
|
if breath == 11 then
|
||||||
hb.hide_hudbar(player, "breath")
|
hb.hide_hudbar(player, "breath")
|
||||||
else
|
else
|
||||||
hb.unhide_hudbar(player, "breath")
|
hb.unhide_hudbar(player, "breath")
|
||||||
hb.change_hudbar(player, "breath", air)
|
hb.change_hudbar(player, "breath", math.min(breath, 10))
|
||||||
end
|
end
|
||||||
|
|
||||||
--health
|
--health
|
||||||
@ -311,9 +314,14 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
minetest.after(0.5, function()
|
minetest.after(0.5, function()
|
||||||
hide_builtin(player)
|
hide_builtin(player)
|
||||||
custom_hud(player)
|
custom_hud(player)
|
||||||
|
hb.players[player:get_player_name()] = player
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
hb.players[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
local main_timer = 0
|
local main_timer = 0
|
||||||
local timer = 0
|
local timer = 0
|
||||||
local timer2 = 0
|
local timer2 = 0
|
||||||
@ -324,7 +332,7 @@ minetest.after(2.5, function()
|
|||||||
timer2 = timer2 + dtime
|
timer2 = timer2 + dtime
|
||||||
if main_timer > hb.settings.tick or timer > 4 then
|
if main_timer > hb.settings.tick or timer > 4 then
|
||||||
if main_timer > hb.settings.tick then main_timer = 0 end
|
if main_timer > hb.settings.tick then main_timer = 0 end
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for playername, player in pairs(hb.players) do
|
||||||
-- only proceed if damage is enabled
|
-- only proceed if damage is enabled
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
-- update all hud elements
|
-- update all hud elements
|
||||||
|
Reference in New Issue
Block a user