-- HP / Mana / Move / XP bars, gold, and time - via char.prompt,
-- which is pushed automatically on every prompt.
-- ============================================================
vitalsHUD = vitalsHUD or {}
-- ---- Reload-safe cleanup ----
if vitalsHUD.container then
vitalsHUD.container:hide()
vitalsHUD.container = nil
end
if vitalsHUD.promptHandlerID then killAnonymousEventHandler(vitalsHUD.promptHandlerID) end
-- ---- CONFIG ----
vitalsHUD.config = {
x = "76%", y = "4%", width = "22%", height = "140px",
}
-- ---- Build window ----
vitalsHUD.container = Geyser.Container:new({
name = "vitalsHUD_container",
x = vitalsHUD.config.x, y = vitalsHUD.config.y,
width = vitalsHUD.config.width, height = vitalsHUD.config.height,
})
vitalsHUD.title = Geyser.Label:new({
name = "vitalsHUD_title", x = 0, y = 0, width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.title:setStyleSheet("background-color: rgba(20,20,20,200); color:white; font-weight:bold;")
vitalsHUD.title:echo("Character Status")
-- HP
vitalsHUD.hpGauge = Geyser.Gauge:new({
name = "vitalsHUD_hpGauge", x = 0, y = "24px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.hpGauge:setColor(200, 40, 40)
vitalsHUD.hpLabel = Geyser.Label:new({
name = "vitalsHUD_hpLabel", x = 0, y = "24px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.hpLabel:setStyleSheet("color:white; background:transparent;")
-- Mana
vitalsHUD.manaGauge = Geyser.Gauge:new({
name = "vitalsHUD_manaGauge", x = 0, y = "48px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.manaGauge:setColor(60, 100, 220)
vitalsHUD.manaLabel = Geyser.Label:new({
name = "vitalsHUD_manaLabel", x = 0, y = "48px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.manaLabel:setStyleSheet("color:white; background:transparent;")
-- Move
vitalsHUD.moveGauge = Geyser.Gauge:new({
name = "vitalsHUD_moveGauge", x = 0, y = "72px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.moveGauge:setColor(60, 180, 80)
vitalsHUD.moveLabel = Geyser.Label:new({
name = "vitalsHUD_moveLabel", x = 0, y = "72px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.moveLabel:setStyleSheet("color:white; background:transparent;")
-- XP
vitalsHUD.xpGauge = Geyser.Gauge:new({
name = "vitalsHUD_xpGauge", x = 0, y = "96px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.xpGauge:setColor(200, 160, 40)
vitalsHUD.xpLabel = Geyser.Label:new({
name = "vitalsHUD_xpLabel", x = 0, y = "96px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.xpLabel:setStyleSheet("color:white; background:transparent;")
-- Gold / Time
vitalsHUD.infoLabel = Geyser.Label:new({
name = "vitalsHUD_infoLabel", x = 0, y = "120px", width = "100%", height = "20px",
}, vitalsHUD.container)
vitalsHUD.infoLabel:setStyleSheet("color:silver; background: rgba(20,20,20,150);")
-- ---- Update on every prompt ----
function vitalsHUD.onPrompt()
local p = gmcp.char and gmcp.char.prompt
if not p then return end
if p.h and p.H then
vitalsHUD.hpGauge:setValue(p.h, p.H)
vitalsHUD.hpLabel:echo(string.format("HP: %s / %s", p.h, p.H))
end
if p.m and p.M then
vitalsHUD.manaGauge:setValue(p.m, p.M)
vitalsHUD.manaLabel:echo(string.format("Mana: %s / %s", p.m, p.M))
end
if p.v and p.V then
vitalsHUD.moveGauge:setValue(p.v, p.V)
vitalsHUD.moveLabel:echo(string.format("Move: %s / %s", p.v, p.V))
end
if p["4"] then
vitalsHUD.xpGauge:setValue(tonumber(p["4"]), 100)
vitalsHUD.xpLabel:echo(string.format("XP to next level: %s%% (%s xp needed)",
tostring(p["4"]), tostring(p.X)))
end
vitalsHUD.infoLabel:echo(string.format("Gold: %s | Time: %s", tostring(p.g), tostring(p.t)))
end
vitalsHUD.promptHandlerID = registerAnonymousEventHandler("gmcp.char.prompt", "vitalsHUD.onPrompt")
-- ---- Manual refresh (useful if GMCP wasn't ready at script load) ----
if vitalsHUD.aliasIDs then
for _, id in pairs(vitalsHUD.aliasIDs) do killAlias(id) end
end
vitalsHUD.aliasIDs = {}
vitalsHUD.aliasIDs.refresh = tempAlias("^hud refresh$", [[sendGMCP("char.prompt"); vitalsHUD.onPrompt(); cecho("<cyan>[VitalsHUD] <white>Refreshed.\n")]])
-- ---- Initial data pull ----
sendGMCP("char.prompt")
-- Retry shortly after load in case GMCP wasn't negotiated yet at startup
tempTimer(3, function() sendGMCP("char.prompt") end)
tempTimer(8, function() sendGMCP("char.prompt") end)
cecho("<cyan>[VitalsHUD] <white>Loaded. 'hud refresh' if it ever comes up empty.\n")