Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create a draggable window for vitals if it doesn't already exist.
- if not vitalsWindow then
- vitalsWindow = Geyser.Window:new({
- name = "vitalsWindow",
- x = 50,
- y = 50,
- width = "700",
- height = "120",
- draggable = true -- Pass the property to try to enable dragging
- })
- vitalsWindow:echo("<center><b>Vitals</b></center>")
- if vitalsWindow.setDraggable then
- vitalsWindow:setDraggable(true)
- cecho("<yellow>[Debug] vitalsWindow:setDraggable(true) executed.\n")
- else
- cecho("<red>[Debug] setDraggable method is not available in your version of Mudlet.\n")
- end
- end
- function createProgressBar(parent, name, x, y, width, height, color, labelText)
- local container = Geyser.Container:new({
- name = name .. "_container",
- x = x, y = y,
- width = width, height = height
- }, parent)
- if container.setStyleSheet then
- container:setStyleSheet("background-color: #CCCCCC; border: 1px solid black;")
- end
- local bar = Geyser.Label:new({
- name = name,
- x = "0", y = "0",
- width = "0", -- Starts at 0 width; will be updated.
- height = "100%"
- }, container)
- if bar.setStyleSheet then
- bar:setStyleSheet("background-color: " .. color .. ";")
- end
- -- Create an overlay text label for the vital name and percentage.
- local textLabel = Geyser.Label:new({
- name = name .. "_text",
- x = "0", y = "0",
- width = "100%", height = "100%"
- }, container)
- textLabel:echo("<center>" .. labelText .. "</center>")
- return { bar = bar, container = container, textLabel = textLabel,
- maxWidth = tonumber(width), maxHeight = tonumber(height) }
- end
- if not healthProgress then
- healthProgress = createProgressBar(vitalsWindow, "healthProgress", "10", "40", "150", "14", "#FF0000", "Health")
- end
- if not manaProgress then
- manaProgress = createProgressBar(vitalsWindow, "manaProgress", "170", "40", "150", "14", "#0000FF", "Mana")
- end
- if not enduranceProgress then
- enduranceProgress = createProgressBar(vitalsWindow, "enduranceProgress", "330", "40", "150", "14", "#00FF00", "Endurance")
- end
- if not willpowerProgress then
- willpowerProgress = createProgressBar(vitalsWindow, "willpowerProgress", "490", "40", "150", "14", "#800080", "Willpower")
- end
- function updateProgressBar(progress, percent, labelText)
- local newWidth = math.floor(progress.maxWidth * (percent / 100))
- progress.bar:resize(newWidth, progress.maxHeight)
- progress.textLabel:echo("<center>" .. labelText .. " " .. percent .. "%</center>")
- end
- function updateVitals()
- if gmcp.Char and gmcp.Char.Vitals then
- local vitals = gmcp.Char.Vitals
- local hp = tonumber(vitals.hp) or 0
- local maxhp = tonumber(vitals.maxhp) or 1
- local mp = tonumber(vitals.mp) or 0
- local maxmp = tonumber(vitals.maxmp) or 1
- local ep = tonumber(vitals.ep) or 0
- local maxep = tonumber(vitals.maxep) or 1
- local wp = tonumber(vitals.wp) or 0
- local maxwp = tonumber(vitals.maxwp) or 1
- local hpPercent = math.floor((hp / maxhp) * 100)
- local mpPercent = math.floor((mp / maxmp) * 100)
- local epPercent = math.floor((ep / maxep) * 100)
- local wpPercent = math.floor((wp / maxwp) * 100)
- updateProgressBar(healthProgress, hpPercent, "Health")
- updateProgressBar(manaProgress, mpPercent, "Mana")
- updateProgressBar(enduranceProgress, epPercent, "Endurance")
- updateProgressBar(willpowerProgress, wpPercent, "Willpower")
- end
- end
- registerAnonymousEventHandler("gmcp.Char.Vitals", "updateVitals")
- updateVitals()
Advertisement
Add Comment
Please, Sign In to add comment