Skip to content

Class

Character class helpers for registering, loading, retrieving, counting, validating, and resolving playable classes.


Overview

The class library centralizes shared character class behavior under `lia.class`. It stores class definitions in `lia.class.list`, loads class files, validates whether a player can join a class, resolves class identifiers, manages whitelist checks, reports class membership counts, and applies default or overridden bodygroups for characters.

lia.class.getBodygroups(class)View Source

Purpose

Retrieves the normalized bodygroup table configured for a class.

Realm

Shared

Parameters

table|number|string class Class data table or class identifier used to look up registered class data.

Returns

table Normalized bodygroup values from `bodyGroups` or `bodygroups`, or an empty table when no class data exists.

Example Usage

  local bodygroups = lia.class.getBodygroups(CLASS_CITIZEN)

lia.class.getMergedBodygroups(character)View Source

Purpose

Builds the effective bodygroup table for a character by combining class defaults with character-specific overrides.

Realm

Shared

Parameters

Character character Character whose class bodygroups and stored bodygroup overrides should be merged.

Returns

table Merged normalized bodygroup table where character overrides take priority over class defaults.

Example Usage

  local bodygroups = lia.class.getMergedBodygroups(character)

lia.class.register(uniqueID, data)View Source

Purpose

Registers or updates a character class with a unique identifier and class data.

Realm

Shared

Parameters

string uniqueID Unique string identifier for the class.

table data Class definition data to store, including a valid `faction` value and optional class configuration.

Returns

number|nil Registered class index, or nil if registration fails because the class has no valid faction. table|nil Registered class table, or nil if registration fails because the class has no valid faction.

Example Usage

  local classIndex = lia.class.register("medic", {
      name = "Medic",
      desc = "A trained field medic.",
      faction = FACTION_CITIZEN
  })

lia.class.loadFromDir(directory)View Source

Purpose

Loads class definition files from a directory and adds valid class definitions to the registered class list.

Realm

Shared

Parameters

string directory Lua directory path containing class files to load.

Returns

Example Usage

  lia.class.loadFromDir("schema/classes")

lia.class.canBe(client, class)View Source

Purpose

Checks whether a player is allowed to join a specific class.

Realm

Shared

Parameters

Player client Player being checked.

number class Class index being checked.

Returns

boolean True if the player can join the class, otherwise false. string|nil Localized failure reason when class validation fails.

Example Usage

  local canJoin, reason = lia.class.canBe(client, CLASS_MEDIC)

lia.class.get(identifier)View Source

Purpose

Retrieves registered class data by identifier.

Realm

Shared

Parameters

number|string identifier Class list key used to retrieve the class data.

Returns

table|nil Registered class data when found, otherwise nil.

Example Usage

  local classData = lia.class.get(CLASS_MEDIC)

lia.class.getPlayers(class)View Source

Purpose

Returns all players whose active character is assigned to a class.

Realm

Shared

Parameters

number class Class index to match against active characters.

Returns

table Sequential table of players currently in the class.

Example Usage

  local medics = lia.class.getPlayers(CLASS_MEDIC)

lia.class.getPlayerCount(class)View Source

Purpose

Counts players whose active character is assigned to a class.

Realm

Shared

Parameters

number class Class index to count.

Returns

number Number of players currently in the class.

Example Usage

  local medicCount = lia.class.getPlayerCount(CLASS_MEDIC)

lia.class.retrieveClass(class)View Source

Purpose

Finds a registered class index by matching a class unique ID or display name.

Realm

Shared

Parameters

string class Class unique ID or class name to search for.

Returns

number|nil Matching class index when found, otherwise nil.

Example Usage

  local classIndex = lia.class.retrieveClass("medic")

lia.class.hasWhitelist(class)View Source

Purpose

Checks whether a class requires whitelist access.

Realm

Shared

Parameters

number class Class index to check.

Returns

boolean True if the class requires whitelist access, otherwise false.

Example Usage

  if lia.class.hasWhitelist(CLASS_MEDIC) then
      client:notifyInfo("This class requires whitelist access.")
  end

lia.class.retrieveJoinable(client)View Source

Purpose

Returns classes that a player is currently eligible to join.

Realm

Shared

Parameters

Player client optional Player to check. Defaults to the local player on the client when omitted.

Returns

table Sequential table of class data tables that the player can join.

Example Usage

  local classes = lia.class.retrieveJoinable(client)

Hooks

Library-specific hooks documented for this library.


CanPlayerJoinClass(client, class, classData)View Source

Purpose

Allows plugins or modules to block a player from joining a class during class eligibility checks.

Realm

Shared

Parameters

Player client The player attempting to join the class.

number class The class index being checked.

table classData The registered class data for the class being checked.

Returns

boolean|nil Return false to prevent the player from joining the class. Return nil or any non-false value to continue normal class validation.