Skip to content

ax.character

Source: gamemode/framework/libraries/sh_character.lua

Character management system for creating, storing, and retrieving character data.

Documented functions: 6

Functions


ax.character:CanPopulateVar(varName, payload, client)

Check if a variable can be populated during character creation. Server-side validation to determine if a variable is available for population.

Realm: server

Parameters

Name Type Description
varName string The variable name to check
payload table Character creation payload data
client Player The client creating the character

Returns

  • boolean,: string|nil True if allowed, false if not. Error message if denied.

Usage

local canPop, reason = ax.character:CanPopulateVar("description", data, player)

ax.character:Get(id)

Get a character by their unique ID.

Realm: shared

Parameters

Name Type Description
id number The character's unique ID

Returns

  • table|nil: The character table if found, nil if invalid ID or not found

Usage

local character = ax.character:Get(123)

ax.character:GetVar(char, name, fallback, dataFallback)

Get a character variable's value. Retrieves a character variable with fallback to default or provided fallback value. For ax.type.data variables, passing fallback reads a nested key and dataFallback is used when that nested key is absent.

Realm: shared

Parameters

Name Type Description
char table The character instance
name string The variable name to retrieve

Returns

  • any: The variable value, default value, or fallback

Usage

local description = ax.character:GetVar(character, "description", "No description")
local flags = ax.character:GetVar(character, "data", "flags", "")

ax.character:RegisterVar(name, data)

Register a new character variable. Creates a character variable with getter/setter methods and database integration. Automatically generates Get/Set methods unless disabled with bNoGetter/bNoSetter.

Realm: shared

Parameters

Name Type Description
name string The variable name
data table Variable configuration including default, field, fieldType, etc.

Usage

ax.character:RegisterVar("description", {default = "", fieldType = ax.type.text})

ax.character:SetVar(char, name, value, opts)

Set a character variable's value. Updates a character variable and handles networking and change callbacks. For ax.type.data variables, pass the nested key as value and provide opts.dataValue for the stored value.

Realm: shared

Parameters

Name Type Description
char table The character instance
name string The variable name to set
value any New value, or nested data key for ax.type.data vars

Usage

ax.character:SetVar(character, "name", "John Doe")
ax.character:SetVar(character, "data", "flags", {dataValue = "ab", bNoNetworking = true})

ax.character:SyncBotToClients(char, recipients)

Sync a bot character to all clients for variable updates. Sends bot character data to clients so they can receive variable changes.

Realm: server

Parameters

Name Type Description
char table The bot character instance
recipients table Optional specific recipients, defaults to all players

Usage

ax.character:SyncBotToClients(botCharacter)