-
Notifications
You must be signed in to change notification settings - Fork 9
SelfUpdatingGauge: Examples
Damian edited this page Apr 17, 2023
·
3 revisions
-- the following will watch "gmcp.Char.Vitals.hp" and "gmcp.Char.Vitals.maxhp"
-- and update itself every 250 milliseconds
local SUG = require("MDK.sug")
myGauge = SUG:new({
name = "myGauge",
height = 50,
width = 200, -- everything up to here is standard Geyser.Gauge
updateTime = 250, -- this timer will update every 250ms, or 4 times a second
textTemplate = "HP: |c/|m (|p%)", -- gauge will show "HP: 500/1000 (50%)" as the text if you had 500 current and 1000 max hp
currentVariable = "gmcp.Char.Vitals.hp", --if gmcp.Char.Vitals.hp is nil or unreachable, it will use the defaultCurrent of 50
maxVariable = "gmcp.Char.Vitals.maxhp", --if gmcp.Char.Vitals.maxhp is nil or unreachable, it will use the defaultMax of 100
})
-- the following will watch "gmcp.Char.Vitals.hp" and "gmcp.Char.Vitals.maxhp"
-- and update itself every time the gmcp.Char.Vitals event fires
local SUG = require("MDK.sug")
myGauge = SUG:new({
name = "myGauge",
height = 50,
width = 200, -- everything up to here is standard Geyser.Gauge
updateEvent = "gmcp.Char.Vitals", -- this gauge will update every time gmcp.Char.Vitals event fires
textTemplate = "HP: |c/|m (|p%)", -- gauge will show "HP: 500/1000 (50%)" as the text if you had 500 current and 1000 max hp
currentVariable = "gmcp.Char.Vitals.hp", --if gmcp.Char.Vitals.hp is nil or unreachable, it will use the defaultCurrent of 50
maxVariable = "gmcp.Char.Vitals.maxhp", --if gmcp.Char.Vitals.maxhp is nil or unreachable, it will use the defaultMax of 100
})
-- the following will watch "gmcp.Char.Vitals.hp" and "gmcp.Char.Vitals.maxhp"
-- and update itself every time the gmcp.Char.Vitals event fires
-- and also change it's color depending on how damaged you are
local SUG = require("MDK.sug")
-- the gauge itself is passed first, then the current and max values being used for the update
local function recolor(self, cur, max)
-- figure out the percentage of HP remaining
local perc = math.floor((cur / max * 100) + 0.5)
if perc > 75 then -- > 75 is green
self:setColor("green")
elseif perc > 50 then -- 50 < perc < 76 is yellow
self:setColor("yellow")
elseif perc > 25 then -- 25 < perc < 51 is orange
self:setColor("orange")
else -- 25% or less is red
self:setColor("red")
end
end
myGauge = SUG:new({
name = "myGauge",
height = 50,
width = 200, -- everything up to here is standard Geyser.Gauge
updateEvent = "gmcp.Char.Vitals", -- this gauge will update every time gmcp.Char.Vitals event fires
textTemplate = "HP: |c/|m (|p%)", -- gauge will show "HP: 500/1000 (50%)" as the text if you had 500 current and 1000 max hp
currentVariable = "gmcp.Char.Vitals.hp", -- if gmcp.Char.Vitals.hp is nil or unreachable, it will use the defaultCurrent of 50
maxVariable = "gmcp.Char.Vitals.maxhp", -- if gmcp.Char.Vitals.maxhp is nil or unreachable, it will use the defaultMax of 100
updateHook = recolor, -- change the gauge color based on percent full
})