summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2015-02-04 04:01:56 +0100
committerWuzzy <almikes@aol.com>2015-02-04 04:01:56 +0100
commit4776027d184955458024fd4d27600448e34fac7c (patch)
treefb016a046f7fa619dc33482fc58074e1fb11b1e0
parent2e40e311a033f315ef57e0b56bb93a7f6df8e1ab (diff)
Add text to bars
-rw-r--r--init.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 65b28cb..1b674a0 100644
--- a/init.lua
+++ b/init.lua
@@ -6,7 +6,9 @@ hud.air = {}
-- HUD item ids
local health_hud = {}
+local health_hud_text = {}
local air_hud = {}
+local air_hud_text = {}
-- default settings
@@ -67,6 +69,15 @@ local function custom_hud(player)
alignment = {x=-1,y=-1},
offset = HUD_HEALTH_OFFSET,
})
+ health_hud_text[name] = player:hud_add({
+ hud_elem_type = "text",
+ position = HUD_HEALTH_POS,
+ text = tostring(string.format("Health: %d/%d", player:get_hp(), 20)),
+ alignment = {x=1,y=1},
+ number = 0xFFFFFF,
+ direction = 0,
+ offset = { x = HUD_HEALTH_OFFSET.x + 2, y = HUD_HEALTH_OFFSET.y },
+ })
--air
player:hud_add({
@@ -85,6 +96,15 @@ local function custom_hud(player)
alignment = {x=-1,y=-1},
offset = HUD_AIR_OFFSET,
})
+ air_hud_text[name] = player:hud_add({
+ hud_elem_type = "text",
+ position = HUD_AIR_POS,
+ text = tostring(string.format("Breath: %d/%d", math.min(player:get_breath(), 10), 10)),
+ alignment = {x=1,y=1},
+ number = 0x000000,
+ direction = 0,
+ offset = { x = HUD_AIR_OFFSET.x + 2, y = HUD_AIR_OFFSET.y },
+ })
end
end
@@ -99,6 +119,9 @@ local function update_hud(player)
air = player:get_breath()
hud.air[name] = air
player:hud_change(air_hud[name], "number", hud.value_to_barlength(math.min(air, 10), 10))
+ player:hud_change(air_hud_text[name], "text",
+ tostring(string.format("Breath: %d/%d", math.min(player:get_breath(), 10), 10))
+ )
end
--health
local hp = tonumber(hud.health[name])
@@ -106,6 +129,9 @@ local function update_hud(player)
hp = player:get_hp()
hud.health[name] = hp
player:hud_change(health_hud[name], "number", hud.value_to_barlength(hp, 20))
+ player:hud_change(health_hud_text[name], "text",
+ tostring(string.format("Health: %d/%d", hp, 20))
+ )
end
end