Configuration
Comprehensive user-configurable settings management system for the Lilia framework.
Overview
lia.config.add(key, name, value, callback, data)
Purpose
Register a config entry with defaults, UI metadata, and optional callback.
When Called
During schema/module initialization to expose server-stored configuration.
Parameters
string key Unique identifier for the config entry.
string name Display text or localization key for UI.
any value Default value; type inferred when data.type is omitted.
function callback optional Invoked server-side as callback(oldValue, newValue) after set().
table data Fields such as type, desc, category, options/optionsFunc, noNetworking, etc.
Example Usage
lia.config.add("MaxThirdPersonDistance", "maxThirdPersonDistance", 100, function(old, new)
lia.option.set("thirdPersonDistance", math.min(lia.option.get("thirdPersonDistance", new), new))
end, {category = "Lilia", type = "Int", min = 10, max = 200})
lia.config.getOptions(key)
Purpose
Resolve a config entry's selectable options, static list or generated.
When Called
Before rendering dropdown-type configs or validating submitted values.
Parameters
string key Config key to resolve options for.
Returns
table Options array or key/value table; empty when unavailable.
Example Usage
local opts = lia.config.getOptions("Theme")
lia.config.forceSet(key, value, noSave)
Purpose
Force-set a config value and fire update hooks without networking.
When Called
Runtime adjustments (admin tools/commands) or hot reload scenarios.
Parameters
string key Config key to change.
any value Value to assign.
boolean noSave optional When true, skip persisting to disk.
Example Usage
lia.config.forceSet("MaxCharacters", 10, false)
lia.config.set(key, value)
lia.config.get(key, default)
Purpose
Retrieve a config value with fallback to its stored default or a provided default.
When Called
Anywhere configuration influences gameplay or UI logic.
Parameters
string key Config key to read.
any default Optional fallback when no stored value or default exists.
Returns
any Stored value, default value, or supplied fallback.
Example Usage
local walkSpeed = lia.config.get("WalkSpeed", 200)
lia.config.getChangedValues(includeDefaults)
Purpose
Collect config entries whose values differ from last synced values or their defaults.
When Called
Prior to sending incremental config updates to clients.
Parameters
boolean includeDefaults optional When true, compare against defaults instead of last synced values.
Returns
table key → value for configs that changed.
Example Usage
local changed = lia.config.getChangedValues()
if next(changed) then lia.config.send() end
lia.config.hasChanges()
Purpose
Check whether any config values differ from the last synced snapshot.
When Called
To determine if a resync to clients is required.
Returns
boolean True when at least one config value has changed.
Example Usage
if lia.config.hasChanges() then lia.config.send() end
lia.config.send(client)
Purpose
Send config values to one player (full payload) or broadcast only changed values.
When Called
After config changes or when a player joins the server.
Parameters
Player client optional Target player for full sync; nil broadcasts only changed values.
Example Usage
hook.Add("PlayerInitialSpawn", "SyncConfig", function(ply) lia.config.send(ply) end)
lia.config.send() -- broadcast diffs