Skip to content

Instantly share code, notes, and snippets.

@octacian octacian/statbar.lua Secret
Created Mar 28, 2017

Embed
What would you like to do?
Statbar "self" table generation.
local function gen(name, hud_name)
local hud = {
remove = function()
hudlib.remove(name, hud_name)
end,
hide = function()
hudlib.hide(name, hud_name)
end,
show = function()
hudlib.show(name, hud_name)
end,
set_pos = function(x, y)
hudlib.change(name, hud_name, "position", {x = x, y = y})
end,
set_texture = function(texture)
hudlib.change(name, hud_name, "text", texture)
end,
set_dir = function(dir)
hudlib.change(name, hud_name, "direction", dir)
end,
set_offset = function(x, y)
hudlib.change(name, hud_name, "offset", {x = x, y = y})
end,
set_size = function(x, y)
hudlib.change(name, hud_name, "size", {x = x, y = y})
end,
set_min = function(min)
hudlib.set(name, hud_name, "min", min)
if hudlib.get(name, hud_name, "def").number < min then
hudlib.change(name, hud_name, "number", min)
end
end,
set_max = function(max)
hudlib.set(name, hud_name, "max", max)
if hudlib.get(name, hud_name, "def").number > max then
hudlib.change(name, hud_name, "number", max)
end
end,
set_status = function(num)
local def = hudlib.get(name, hud_name, "def")
if num < def.min then
hudlib.change(name, hud_name, "number", min)
elseif num > def.max then
hudlib.change(name, hud_name, "number", max)
else
hudlib.change(name, hud_name, "number", num)
end
end,
}
hud.color = hud.colour
return hud
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.