Classes
Character class management and validation system for the Lilia framework.
Overview
lia.class.register(uniqueID, data)
Purpose
Registers or updates a class definition within the global class list.
When Called
Invoked during schema initialization or dynamic class creation to ensure a class entry exists before use.
Parameters
string uniqueID Unique identifier for the class; must be consistent across loads.
table data Class metadata such as name, desc, faction, limit, OnCanBe, etc.
Returns
table The registered class table with applied defaults.
Example Usage
lia.class.register("soldier", {
name = "Soldier",
faction = FACTION_MILITARY,
limit = 4
})
lia.class.loadFromDir(directory)
Purpose
Loads and registers all class definitions from a directory.
When Called
Used during schema loading to automatically include class files in a folder following the naming convention.
Parameters
string directory Path to the directory containing class Lua files.
Example Usage
lia.class.loadFromDir("lilia/gamemode/classes")
lia.class.canBe(client, class)
Purpose
Determines whether a client can join a specific class.
When Called
Checked before class selection to enforce faction, limits, whitelist, and custom restrictions.
Parameters
Player client Player attempting to join the class.
number|string class Class index or unique identifier.
Returns
boolean|string False and a reason string on failure; otherwise returns the class's isDefault value.
Example Usage
local ok, reason = lia.class.canBe(ply, CLASS_CITIZEN)
if ok then
-- proceed with class change
end
lia.class.get(identifier)
Purpose
Retrieves a class table by index or unique identifier.
When Called
Used whenever class metadata is needed given a known identifier.
Parameters
number|string identifier Class list index or unique identifier.
Returns
table|nil The class table if found; otherwise nil.
Example Usage
local classData = lia.class.get("soldier")
lia.class.getPlayers(class)
Purpose
Collects all players currently assigned to the given class.
When Called
Used when enforcing limits or displaying membership lists.
Parameters
number|string class Class list index or unique identifier.
Returns
table Array of player entities in the class.
Example Usage
for _, ply in ipairs(lia.class.getPlayers("soldier")) do
-- notify class members
end
lia.class.getPlayerCount(class)
Purpose
Counts how many players are in the specified class.
When Called
Used to check class limits or display class population.
Parameters
number|string class Class list index or unique identifier.
Returns
number Current number of players in the class.
Example Usage
local count = lia.class.getPlayerCount(CLASS_ENGINEER)
lia.class.retrieveClass(class)
Purpose
Finds the class index by matching uniqueID or display name.
When Called
Used to resolve user input to a class entry before further lookups.
Parameters
string class Text to match against class uniqueID or name.
Returns
number|nil The class index if a match is found; otherwise nil.
Example Usage
local idx = lia.class.retrieveClass("Engineer")
lia.class.hasWhitelist(class)
Purpose
Checks whether a class uses whitelist access.
When Called
Queried before allowing class selection or displaying class info.
Parameters
number|string class Class list index or unique identifier.
Returns
boolean True if the class is whitelisted and not default; otherwise false.
Example Usage
if lia.class.hasWhitelist(CLASS_PILOT) then
-- restrict to whitelisted players
end
lia.class.retrieveJoinable(client)
Purpose
Returns a list of classes the provided client is allowed to join.
When Called
Used to build class selection menus and enforce availability.
Parameters
Player client optional Target player; defaults to LocalPlayer on the client.
Returns
table Array of class tables the client can currently join.
Example Usage
local options = lia.class.retrieveJoinable(ply)