Classes Library
Character class management and validation system for the Lilia framework.
Overview
The classes library provides comprehensive functionality for managing character classes in the Lilia framework. It handles registration, validation, and management of player classes within factions. The library operates on both server and client sides, allowing for dynamic class creation, whitelist management, and player class assignment validation. It includes functionality for loading classes from directories, checking class availability, retrieving class information, and managing class limits. The library ensures proper faction validation and provides hooks for custom class behavior and restrictions.
lia.class.register(uniqueID, data)
Registers or updates a class definition within the global class list.
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)
Loads and registers all class definitions from a directory.
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)
Determines whether a client can join a specific class.
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)
Retrieves a class table by index or unique identifier.
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)
Collects all players currently assigned to the given class.
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)
Counts how many players are in the specified class.
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)
Finds the class index by matching uniqueID or display name.
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)
Checks whether a class uses whitelist access.
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)
Returns a list of classes the provided client is allowed to join.
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)