lia.char

Character creation and management.

NOTE: For the most part you shouldn't use this library unless you know what you're doing. You can very easily corrupt character data using these functions!

Functions

GetTeamColor(client)

Gets the color associated with a player's team or class.

Parameters

  • client Player

    The player whose color to retrieve

Returns

  • any

    color The color associated with the player's team or class

cleanUpForPlayer(client)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

Cleans up a player's characters, removing them from memory and database.

Parameters

  • client Player

    The player whose characters to clean up.

create(data, callback)

Creates a character object with its assigned properties and saves it to the database.

Parameters

  • data Table

    Properties to assign to this character. If fields are missing from the table, then it will use the default value for that property

  • callback Function

    Function to call after the character saves

delete(id, client)

Deletes a character from memory and database.

Parameters

  • id Integer

    The ID of the character to delete.

  • client Player

    The player associated with the character.

getAll()

Retrieves the SteamIDs of all connected players.

Returns

  • table

    Table containing SteamIDs of all connected players

getCharData(charID, key)

Loads data for a character from the database.

Parameters

  • charID Integer

    The ID of the character to load data for.

  • key String optional

    key to retrieve a specific value from the character's data.

Returns

  • any

    If key is provided, returns the value associated with that key in the character's data. Otherwise, returns the entire data table.

getCharDataRaw(charID, key)

Loads raw data for a character from the database.

Parameters

  • charID Integer

    The ID of the character to load data for.

  • key String optional

    The specific key to retrieve from the character's data.

Returns

  • any

    table|string|boolean If key is provided, returns the value associated with that key in the character's data. If key is not provided, returns the entire data table for the character. Returns false if the character data could not be found.

hookVar(varName, hookName, func)

Adds a hook function to be called when a character variable is modified.

Parameters

  • varName String

    The name of the character variable.

  • hookName String

    The name of the hook.

  • func Function

    The function to be called when the character variable is modified.

new(data, id, client, steamID)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

Creates a new empty Character object. If you are looking to create a usable character, see lia.char.create.

Parameters

  • data Table

    Character vars to assign

  • id Integer

    Unique ID of the character

  • client Player

    Player that will own the character

  • steamID String default: client:SteamID64()

    SteamID64 of the player that will own the character

registerVar(key, data)

Registers a new character variable with specified data and associated hooks. This function is used to define a new character variable in the system, setting up how it interacts with the database, how it is networked, and how it can be accessed or modified within the game.

Parameters

  • key String

    The key identifier for the character variable. This is used as the variable's name.

  • data Table

    A table containing the data and configuration for the character variable.

restore(client, callback, id)

Loads all of a player's characters into memory.

Parameters

  • client Player

    Player to load the characters for

  • callback Function default: nil

    Function to call when the characters have been loaded their characters loaded which will skip the database query and load quicker

  • id Integer default: nil

    The ID of a specific character to load instead of all of the player's characters

setCharData(charID, key, val)

Sets data for a character in the database and in memory.

Parameters

  • charID Integer

    The ID of the character to set data for.

  • key String

    The key of the data to set.

  • val

    The value to set for the specified key.

Returns

  • any

    True if the data was successfully set, false otherwise.

setCharModel(charID, model, bg)

Sets the model and bodygroups for a character in the database and in memory.

Parameters

  • charID Integer

    The ID of the character to set the model for.

  • model String

    The model path to set for the character.

  • bg Table

    A table containing bodygroup IDs and values.

Returns

  • any

    boolean True if the model and bodygroups were successfully set, false otherwise.

setCharName(charID, name)

Sets the name for a character in the database and in memory.

Parameters

  • charID Integer

    The ID of the character to set the name for.

  • name String

    The new name to set for the character.

Returns

  • any

    boolean True if the name was successfully set, false otherwise.