Skip to content

Option

User-configurable settings management system for the Lilia framework.


Overview

The option library provides comprehensive functionality for managing user-configurable settings in the Lilia framework. It handles the creation, storage, retrieval, and persistence of various types of options including boolean toggles, numeric sliders, color pickers, text inputs, and dropdown selections. The library operates on both client and server sides, with automatic persistence to JSON files and optional networking capabilities for server-side options. It includes a complete user interface system for displaying and modifying options through the configuration menu, with support for categories, visibility conditions, and real-time updates. The library ensures that all user preferences are maintained across sessions and provides hooks for modules to react to option changes.

lia.option.add(key, name, desc, default, callback, data)

Purpose

Register a configurable option with defaults, callbacks, and metadata.

When Called

During initialization to expose settings to the config UI/system.

Parameters

string key Option identifier to resolve choices for.

string name Display name or localization key.

string desc Description or localization key.

any default Default value; determines inferred type.

function callback optional function(old, new) invoked on change.

table data Extra fields: category, min/max, options, visible, shouldNetwork, isQuick, type, etc.

Example Usage

  lia.option.add("hudScale", "HUD Scale", "Scale HUD elements", 1.0, function(old, new)
      hook.Run("HUDScaleChanged", old, new)
  end, {
      category = "@Core",
      min = 0.5,
      max = 1.5,
      decimals = 2,
      isQuick = true
  })

lia.option.getDisplayName(key)

Purpose

Retrieve the localized display name of an option entry.

When Called

When rendering option entries in the config UI or sorting them by name.

Parameters

string key The option key to look up.

Returns

string Localized display name, or the raw key if the entry does not exist.

Example Usage

  local name = lia.option.getDisplayName("BarsAlwaysVisible")
  print("Option name:", name)

lia.option.getDisplayDesc(key)

Purpose

Retrieve the localized description of an option entry.

When Called

When populating tooltips or description labels in the options UI.

Parameters

string key The option key to look up.

Returns

string Localized description string, or an empty string if none exists.

Example Usage

  local desc = lia.option.getDisplayDesc("BarsAlwaysVisible")
  print("Option description:", desc)

lia.option.getDisplayCategory(key)

Purpose

Retrieve the localized category of an option entry for grouping in the UI.

When Called

When building the options UI to sort entries into category sections.

Parameters

string key The option key to look up.

Returns

string Localized category name, or "misc" as the default fallback.

Example Usage

  local cat = lia.option.getDisplayCategory("BarsAlwaysVisible")
  print("Option category:", cat)

lia.option.getOptions(key)

Purpose

Resolve option choices (static or generated) for dropdowns.

When Called

By the config UI before rendering a Table option.

Parameters

string key

Returns

table Array/map of options.

Example Usage

  local list = lia.option.getOptions("weaponSelectorPosition")
  for _, opt in pairs(list) do print("Choice:", opt) end

lia.option.set(key, value)

Purpose

Set an option value, run callbacks/hooks, persist and optionally network it.

When Called

From UI interactions or programmatic changes.

Parameters

string key

any value

Example Usage

  lia.option.set("BarsAlwaysVisible", true)

lia.option.get(key, default)

Purpose

Retrieve an option value with fallback to default or provided default.

When Called

Anywhere an option influences behavior or UI.

Parameters

string key

any default

Returns

any

Example Usage

  local showTime = lia.option.get("ChatShowTime", false)

lia.option.save()

Purpose

Persist option values to disk (data/lilia/options.json).

When Called

After option changes; auto-called by lia.option.set.

Example Usage

  lia.option.save()

lia.option.load()

Purpose

Load option values from disk or initialize defaults when missing.

When Called

On client init or config menu load.

Example Usage

  hook.Add("Initialize", "LoadLiliaOptions", lia.option.load)