Skip to content

ax.character

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

Documented functions: 13  ·  Realm: server, shared

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)

Source: gamemode/framework/libraries/sh_character.lua:276


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)

Source: gamemode/framework/libraries/sh_character.lua:27


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", "")

Source: gamemode/framework/libraries/sh_character.lua:55


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})

Source: gamemode/framework/libraries/sh_character.lua:305


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})

Source: gamemode/framework/libraries/sh_character.lua:96


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)

Source: gamemode/framework/libraries/sh_character.lua:256


ax.character:ValidateVar(varName, value)

Verifies the input based on the character variable's validate function, if it exists.

Realm: shared

Parameters

Name Type Description
varName string The variable name to validate
value any The value to validate

Returns

  • boolean,: string|nil True if valid, false if not. Error message if invalid.

Usage

local isValid, errorMsg = ax.character:ValidateVar("detailedDescription", inputValue)

Source: gamemode/framework/libraries/sh_character.lua:229


ax.character:Create(payload, callback)

Create a new character in the database.

Creates a character with the provided payload data and automatically creates an inventory.

Calls the callback with the character and inventory objects upon completion.

Realm: server

Parameters

Name Type Description
payload table Character creation data containing variable values
callback function Optional callback function called with (character, inventory) or (false) on failure

Usage

ax.character:Create({name = "John Doe", description = "A citizen"}, function(char, inv) end)

Source: gamemode/framework/libraries/sv_character.lua:28


ax.character:Delete(id, callback)

Delete a character from the database.

Permanently removes a character and its associated inventory from the database.

Realm: server

Parameters

Name Type Description
id number The character ID to delete
callback function Optional callback function called with success boolean

Usage

ax.character:Delete(123, function(success) print("Deleted:", success) end)

Source: gamemode/framework/libraries/sv_character.lua:327


ax.character:Kick(client, reason)

Kick a player out of their active character and return them to the menu.

Realm: server

Parameters

Name Type Description
client Player The player to kick out of their character
reason string\|nil Optional reason to notify the player with

Returns

  • boolean: True if a character was unloaded

Usage

ax.character:Kick(client, "You have been kicked to the menu.")

Source: gamemode/framework/libraries/sv_character.lua:214


ax.character:Load(client, character)

Load a character for a player.

Associates a character with a player, syncs character data, and sets up inventory.

Automatically respawns the player after loading the character.

Realm: server

Parameters

Name Type Description
client Player The player entity to load the character for
character table The character object to load

Usage

ax.character:Load(player, characterObject)

Source: gamemode/framework/libraries/sv_character.lua:118


ax.character:Restore(client, callback)

Restore all characters for a player from the database.

Loads all characters associated with the player's SteamID64 and sends them to the client.

Realm: server

Parameters

Name Type Description
client Player The player entity to restore characters for
callback function Optional callback function called with the character array

Usage

ax.character:Restore(player, function(characters) print("Loaded", #characters, "characters") end)

Source: gamemode/framework/libraries/sv_character.lua:263


ax.character:Sync(client, character, recipient)

Synchronize character data to all clients or a specific recipient.

Broadcasts character information to all connected players or a specific player for client-side access.

Realm: server

Parameters

Name Type Description
client Player The player associated with the character
character table The character object to synchronize
recipient Player Optional specific recipient; if nil, broadcasts to all

Usage

ax.character:Sync(player, characterObject)
ax.character:Sync(player, characterObject, newPlayer)

Source: gamemode/framework/libraries/sv_character.lua:471