Skip to content

Bars

Dynamic progress bar creation and management system for the Lilia framework.


Overview

The bars library provides a comprehensive system for creating and managing dynamic progress bars in the Lilia framework. It handles the creation, rendering, and lifecycle management of various types of bars including health, armor, and custom progress indicators. The library operates primarily on the client side, providing smooth animated transitions between bar values and intelligent visibility management based on value changes and user preferences. It includes built-in health and armor bars, custom action progress displays, and a flexible system for adding custom bars with priority-based ordering. The library ensures consistent visual presentation across all bar types while providing hooks for customization and integration with other framework components.

lia.bar.get(identifier)

Purpose

Retrieve a registered bar definition by its identifier.

When Called

Before updating/removing an existing bar or inspecting its state.

Parameters

string identifier optional Unique bar id supplied when added.

Returns

table|nil Stored bar data or nil if not found.

Example Usage

  local staminaBar = lia.bar.get("stamina")
  if staminaBar then
      print("Current priority:", staminaBar.priority)
  end

lia.bar.add(getValue, color, priority, identifier)

Purpose

Register a new dynamic bar with optional priority and identifier.

When Called

Client HUD setup or when creating temporary action/status bars.

Parameters

function getValue Returns current fraction (0-1) when called.

Color color optional Bar color; random bright color if nil.

number priority optional Lower draws earlier; defaults to append order.

string identifier optional Unique id; replaces existing bar with same id.

Returns

number Priority used for the bar.

Example Usage

  -- Add a stamina bar that fades after inactivity.
  lia.bar.add(function()
      local client = LocalPlayer()
      local stamina = client:getLocalVar("stm", 100)
      return math.Clamp(stamina / 100, 0, 1)
  end, Color(120, 200, 80), 2, "stamina")

lia.bar.remove(identifier)

Purpose

Remove a bar by its identifier.

When Called

After a timed action completes or when disabling a HUD element.

Parameters

string identifier Unique id passed during add.

Example Usage

  timer.Simple(5, function() lia.bar.remove("stamina") end)

lia.bar.drawBar(pos, max, color)

Purpose

Draw a single bar at a position with given fill and color.

When Called

Internally from drawAll or for custom bars in panels.

Parameters

number pos Current value.

number max Maximum value.

Color color Fill color.

Example Usage

  -- Custom panel painting a download progress bar.
  function PANEL:Paint(w, h)
      lia.bar.drawBar(10, h - 24, w - 20, 16, self.progress, 1, Color(120, 180, 255))
  end

lia.bar.drawAction(text, duration)

Purpose

Show a centered action bar with text and timed progress.

When Called

For timed actions like searching, hacking, or channeling abilities.

Parameters

string text Label to display.

number duration Seconds to run before auto-removal.

Example Usage

  hook.Add("OnStartSearch", "ShowSearchBar", function(duration)
      lia.bar.drawAction(L("searchingChar"), duration)
  end)

lia.bar.drawAll()

Purpose

Render all registered bars with smoothing, lifetimes, and ordering.

When Called

Each HUDPaintBackground (hooked at bottom of file).

Example Usage

  -- Bars are drawn automatically via the HUDPaintBackground hook.
  -- For custom derma panels, you could manually call lia.bar.drawAll().