Caighan

Vitals Display

Feb 1st, 2025
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. -- Create a draggable window for vitals if it doesn't already exist.
  2. if not vitalsWindow then
  3.   vitalsWindow = Geyser.Window:new({
  4.     name = "vitalsWindow",
  5.     x = 50,
  6.     y = 50,
  7.     width = "700",
  8.     height = "120",
  9.     draggable = true  -- Pass the property to try to enable dragging
  10.   })
  11.   vitalsWindow:echo("<center><b>Vitals</b></center>")
  12.  
  13.   if vitalsWindow.setDraggable then
  14.     vitalsWindow:setDraggable(true)
  15.     cecho("<yellow>[Debug] vitalsWindow:setDraggable(true) executed.\n")
  16.   else
  17.     cecho("<red>[Debug] setDraggable method is not available in your version of Mudlet.\n")
  18.   end
  19. end
  20.  
  21. function createProgressBar(parent, name, x, y, width, height, color, labelText)
  22.   local container = Geyser.Container:new({
  23.     name = name .. "_container",
  24.     x = x, y = y,
  25.     width = width, height = height
  26.   }, parent)
  27.   if container.setStyleSheet then
  28.     container:setStyleSheet("background-color: #CCCCCC; border: 1px solid black;")
  29.   end
  30.  
  31.   local bar = Geyser.Label:new({
  32.     name = name,
  33.     x = "0", y = "0",
  34.     width = "0",  -- Starts at 0 width; will be updated.
  35.     height = "100%"
  36.   }, container)
  37.   if bar.setStyleSheet then
  38.     bar:setStyleSheet("background-color: " .. color .. ";")
  39.   end
  40.  
  41.   -- Create an overlay text label for the vital name and percentage.
  42.   local textLabel = Geyser.Label:new({
  43.     name = name .. "_text",
  44.     x = "0", y = "0",
  45.     width = "100%", height = "100%"
  46.   }, container)
  47.   textLabel:echo("<center>" .. labelText .. "</center>")
  48.  
  49.   return { bar = bar, container = container, textLabel = textLabel,
  50.            maxWidth = tonumber(width), maxHeight = tonumber(height) }
  51. end
  52.  
  53.  
  54. if not healthProgress then
  55.   healthProgress = createProgressBar(vitalsWindow, "healthProgress", "10", "40", "150", "14", "#FF0000", "Health")
  56. end
  57. if not manaProgress then
  58.   manaProgress = createProgressBar(vitalsWindow, "manaProgress", "170", "40", "150", "14", "#0000FF", "Mana")
  59. end
  60. if not enduranceProgress then
  61.   enduranceProgress = createProgressBar(vitalsWindow, "enduranceProgress", "330", "40", "150", "14", "#00FF00", "Endurance")
  62. end
  63. if not willpowerProgress then
  64.   willpowerProgress = createProgressBar(vitalsWindow, "willpowerProgress", "490", "40", "150", "14", "#800080", "Willpower")
  65. end
  66.  
  67. function updateProgressBar(progress, percent, labelText)
  68.   local newWidth = math.floor(progress.maxWidth * (percent / 100))
  69.   progress.bar:resize(newWidth, progress.maxHeight)
  70.   progress.textLabel:echo("<center>" .. labelText .. " " .. percent .. "%</center>")
  71. end
  72.  
  73. function updateVitals()
  74.   if gmcp.Char and gmcp.Char.Vitals then
  75.     local vitals = gmcp.Char.Vitals
  76.     local hp    = tonumber(vitals.hp) or 0
  77.     local maxhp = tonumber(vitals.maxhp) or 1
  78.     local mp    = tonumber(vitals.mp) or 0
  79.     local maxmp = tonumber(vitals.maxmp) or 1
  80.     local ep    = tonumber(vitals.ep) or 0
  81.     local maxep = tonumber(vitals.maxep) or 1
  82.     local wp    = tonumber(vitals.wp) or 0
  83.     local maxwp = tonumber(vitals.maxwp) or 1
  84.  
  85.     local hpPercent = math.floor((hp / maxhp) * 100)
  86.     local mpPercent = math.floor((mp / maxmp) * 100)
  87.     local epPercent = math.floor((ep / maxep) * 100)
  88.     local wpPercent = math.floor((wp / maxwp) * 100)
  89.  
  90.     updateProgressBar(healthProgress, hpPercent, "Health")
  91.     updateProgressBar(manaProgress, mpPercent, "Mana")
  92.     updateProgressBar(enduranceProgress, epPercent, "Endurance")
  93.     updateProgressBar(willpowerProgress, wpPercent, "Willpower")
  94.   end
  95. end
  96.  
  97. registerAnonymousEventHandler("gmcp.Char.Vitals", "updateVitals")
  98.  
  99. updateVitals()
  100.  
Advertisement
Add Comment
Please, Sign In to add comment