Classes Library
This page details the class system functions.
Overview
The classes library loads Lua definitions that describe player classes. Classes act like temporary jobs within a faction. The library stores available classes, applies default values, and provides lookup functions by index or text search.
See Class Fields for configurable CLASS
properties and Class Hooks for customization callbacks.
lia.class.register
Purpose
Registers a new class or updates an existing one with matching uniqueID
.
Applies default values and validates that the provided faction exists.
Parameters
uniqueID
(string): Unique identifier for the class.data
(table): Properties such asname
,desc
,faction
,limit
, etc.
Realm
Shared
Returns
- table | nil: The registered class table, or
nil
if the faction is invalid.
Edge Cases
- Sets defaults of
name
toL("unknown")
,desc
toL("noDesc")
,limit
to0
, andOnCanBe
to a function returningtrue
when those fields are missing. - Logs an error and returns
nil
whenfaction
is missing or not a valid team.
Example Usage
-- Register a class for the Combine faction
local class = lia.class.register("overwatch", {
name = "Overwatch Soldier",
desc = "Transhuman soldier of the Combine.",
faction = FACTION_COMBINE,
limit = 4,
isWhitelisted = true
})
lia.class.loadFromDir
Purpose
Loads every .lua
file within the supplied directory. Each file should define a CLASS
table inserted into lia.class.list
with an automatic index.
Skips files whose uniqueID
already exists and requires each class to have a valid faction
.
Defaults name
to L("unknown")
, desc
to L("noDesc")
, limit
to 0
, and OnCanBe
to a function returning true
.
Files prefixed with sh_
have the prefix stripped when determining uniqueID
.
Parameters
directory
(string): Folder path containing class Lua files, typically"schema/classes"
in a schema.
Edge Cases
- After inclusion, the temporary global
CLASS
is cleared to avoid leaking state.
Realm
Shared
Returns
- nil: This function does not return a value.
Example Usage
lia.class.canBe
Purpose
Validates faction membership, current class, and population limits before calling the CanPlayerJoinClass
gamemode hook and the class’s OnCanBe
method. This function does not automatically enforce class whitelists.
Parameters
-
client
(Player): Player attempting to join. -
class
(number): Class index to join.
Realm
Shared
Returns
- boolean | nil, string?:
false
and a localized reason when basic checks fail. If either the hook orOnCanBe
returnsfalse
, this function simply returnsfalse
. On success, returns the class’sisDefault
flag (true
for default classes, otherwisenil
).
Example Usage
lia.class.get
Purpose
Retrieves the class table associated with the given index.
Parameters
index
(number): Class index to look up.
Realm
Shared
Returns
- table | nil: Class table if found, or
nil
for an invalid index.
Example Usage
lia.class.getPlayers
Purpose
Returns an array of players whose characters belong to the given class.
Parameters
class
(number): Class index to check.
Realm
Shared
Returns
- table: List of player objects. Returns an empty table when no players are in the class.
Example Usage
lia.class.getPlayerCount
Purpose
Counts the number of players currently in the specified class.
Parameters
class
(number): Class index to check.
Realm
Shared
Returns
- number: Player count (returns
0
if none).
Example Usage
lia.class.retrieveClass
Purpose
Finds a class whose uniqueID
or name
matches the given text (case-insensitive, partial matches allowed).
Parameters
class
(string): Name oruniqueID
to look up.
Realm
Shared
Returns
- number | nil: Matching class index or
nil
if not found.
Example Usage
lia.class.hasWhitelist
Purpose
Checks if the class requires a whitelist. Default classes and invalid class indices always return false
.
Parameters
class
(number): Class index to check.
Realm
Shared
Returns
- boolean:
true
if the class is whitelisted; otherwisefalse
.
Example Usage
-- Check whether the class is whitelisted
if lia.class.hasWhitelist(classID) then
print("Whitelist required")
end
lia.class.retrieveJoinable
Purpose
Returns all classes the specified client is eligible to join by calling lia.class.canBe
on each registered class.
Parameters
client
(Player?): Player to check. Defaults toLocalPlayer()
when called on the client. If invalid or omitted on the server, an empty table is returned.
Realm
Shared
Returns
- table: List of class tables the client can join. Returns an empty table if the client is invalid.
Example Usage