Skip to content

Character

Character metadata helpers for lookup, recognition, persistence, and state management.


Overview

The character meta table wraps a loaded character instance and exposes helpers for identity lookup, attribute and flag access, recognition state, character data storage, networking, and server-side lifecycle actions such as syncing, saving, banning, and deletion.

getID()View Source

Purpose

Returns the numeric ID assigned to this character.

Realm

Shared

Returns

number The character ID.

Example Usage

  local charID = character:getID()
  print("Character ID:", charID)

getPlayer()View Source

Purpose

Resolves and caches the player currently using this character, if any.

Realm

Shared

Returns

Player|nil The owning player when found.

Example Usage

  local owner = character:getPlayer()
  if IsValid(owner) then print(owner:Nick()) end

getDisplayedName(client)View Source

Purpose

Returns the name this character should display to a specific viewer.

Realm

Shared

Parameters

Player client The player viewing this character.

Returns

string The true name, a fake recognized name, or the localized unknown label.

Example Usage

  local shownName = targetCharacter:getDisplayedName(viewer)
  viewer:ChatPrint(shownName)

hasMoney(amount)View Source

Purpose

Checks whether the character has at least the requested amount of money.

Realm

Shared

Parameters

number amount The required amount.

Returns

boolean `true` if the character has enough money.

Example Usage

  if character:hasMoney(500) then
      print("Character can afford this purchase.")
  end

hasFlags(flagStr)View Source

Purpose

Checks whether the character owns any of the supplied flags.

Realm

Shared

Parameters

string flagStr One or more flag characters to test.

Returns

boolean `true` if any requested flag is present.

Example Usage

  if character:hasFlags("pet") then
      print("Character has at least one of those flags.")
  end

getAttrib(key, default)View Source

Purpose

Returns an attribute value after applying any active boosts for that attribute.

Realm

Shared

Parameters

string key The attribute ID.

number default Fallback value when the attribute is unset.

Returns

number The current effective attribute value.

Example Usage

  local strength = character:getAttrib("str", 0)
  print("Strength:", strength)

doesRecognize(id)View Source

Purpose

Checks whether this character normally recognizes another character ID.

Realm

Shared

Parameters

number|table id A character ID or character object.

Returns

boolean `true` unless a hook explicitly rejects recognition.

Example Usage

  if viewerCharacter:doesRecognize(targetCharacter) then
      print("This character is recognized.")
  end

doesFakeRecognize(id)View Source

Purpose

Checks whether this character uses a fake recognized name for another character.

Realm

Shared

Parameters

number|table id A character ID or character object.

Returns

boolean `true` unless a hook explicitly rejects fake recognition.

Example Usage

  if viewerCharacter:doesFakeRecognize(targetCharacter) then
      print("A fake recognized name is being used.")
  end

setData(k, v, noReplication, receiver)View Source

Purpose

Stores arbitrary character data, optionally replicating it and persisting it on the server.

Realm

Shared

Parameters

string|table k A single key or a table of key-value pairs.

any v The value for a single key update.

boolean noReplication Whether to skip sending the updated data over the network.

Player receiver An optional player to receive replicated data.

Example Usage

  character:setData("title", "Quartermaster")
  character:setData({
      rank = "Captain",
      callsign = "Echo-3"
  })

getData(key, default)View Source

Purpose

Retrieves stored character data, checking the cache first and the database on the server when needed.

Realm

Shared

Parameters

string key optional The key to fetch, or `nil` to return the full data table.

any default The fallback value if the key is missing.

Returns

any The stored value, the full data table, or the fallback.

Example Usage

  local title = character:getData("title", "Citizen")
  local allData = character:getData()

isBanned()View Source

Purpose

Checks whether the character is currently banned.

Realm

Shared

Returns

boolean `true` if the ban is permanent or still active.

Example Usage

  if character:isBanned() then
      print("This character cannot be selected right now.")
  end

recognize(character, name)View Source

Purpose

Marks another character as recognized, optionally storing a fake display name.

Realm

Server

Parameters

number|table character A character ID or character object to recognize.

string name optional A fake name to store instead of normal recognition.

Returns

boolean `true` after the recognition data is updated.

Example Usage

  observerCharacter:recognize(targetCharacter)
  observerCharacter:recognize(targetCharacter, "John Doe")

joinClass(class, isForced)View Source

Purpose

Moves the character into a class if the class exists and passes eligibility checks.

Realm

Server

Parameters

string|number class optional The class identifier to join.

boolean isForced Whether to bypass `lia.class.canBe`.

Returns

boolean `true` if the class was joined.

Example Usage

  local joined = character:joinClass(CLASS_MEDIC)
  print("Joined class:", joined)

kickClass()View Source

Purpose

Removes the character from its current class and falls back to the faction default when possible.

Realm

Server

Example Usage

  character:kickClass()

updateAttrib(key, value)View Source

Purpose

Adds to an attribute without exceeding the configured maximum, then syncs it to the owner.

Realm

Server

Parameters

string key The attribute ID.

number value The amount to add.

Example Usage

  character:updateAttrib("stm", 5)

setAttrib(key, value)View Source

Purpose

Sets an attribute to an exact value and syncs it to the owner.

Realm

Server

Parameters

string key The attribute ID.

number value The new raw value.

Example Usage

  character:setAttrib("str", 15)

addBoost(boostID, attribID, boostAmount)View Source

Purpose

Adds or replaces a temporary boost on an attribute.

Realm

Server

Parameters

string boostID A unique identifier for the boost source.

string attribID The attribute being boosted.

number boostAmount The amount to apply.

Returns

any The result of `setVar`.

Example Usage

  character:addBoost("adrenaline", "stm", 10)

removeBoost(boostID, attribID)View Source

Purpose

Removes one temporary boost from an attribute.

Realm

Server

Parameters

string boostID The boost identifier to remove.

string attribID The attribute the boost belongs to.

Returns

any The result of `setVar`.

Example Usage

  character:removeBoost("adrenaline", "stm")

clearAllBoosts()View Source

Purpose

Clears every active attribute boost on the character.

Realm

Server

Returns

any The result of `setVar`.

Example Usage

  character:clearAllBoosts()

setFlags(flags)View Source

Purpose

Replaces the character's entire flag string and triggers flag callbacks.

Realm

Server

Parameters

string flags The complete set of flags to store.

Example Usage

  character:setFlags("pet")

giveFlags(flags)View Source

Purpose

Adds any missing flags from the supplied string.

Realm

Server

Parameters

string flags The flags to grant.

Example Usage

  character:giveFlags("ab")

takeFlags(flags)View Source

Purpose

Removes any matching flags from the supplied string.

Realm

Server

Parameters

string flags The flags to revoke.

Example Usage

  character:takeFlags("b")

save(callback)View Source

Purpose

Persists the character's field-backed variables to the database.

Realm

Server

Parameters

function callback optional Runs after a successful save.

Example Usage

  character:save(function()
      print("Character saved.")
  end)

sync(receiver)View Source

Purpose

Sends this character's networked state to one player or every player.

Realm

Server

Parameters

Player receiver optional The player to sync to, or `nil` to sync to everyone.

Example Usage

  character:sync()
  character:sync(adminPlayer)

setup(noNetworking)View Source

Purpose

Applies the character to its owning player and optionally syncs inventories and character vars.

Realm

Server

Parameters

boolean noNetworking Whether to skip syncing inventories and character data.

Example Usage

  character:setup()

kick()View Source

Purpose

Removes the owning player from this character and returns them to the selection state.

Realm

Server

Example Usage

  character:kick()

ban(time)View Source

Purpose

Bans the character until a timestamp or permanently, then saves and kicks it.

Realm

Server

Parameters

number time optional Ban duration in seconds. `nil` creates a permanent ban.

Example Usage

  character:ban(3600)
  character:ban()

delete()View Source

Purpose

Deletes the character through the character library.

Realm

Server

Example Usage

  character:delete()

destroy()View Source

Purpose

Removes the character from the loaded character cache.

Realm

Server

Example Usage

  character:destroy()

giveMoney(amount)View Source

Purpose

Gives money to the owning player through the player money helper.

Realm

Server

Parameters

number amount The amount to add.

Returns

boolean `false` if the player is not valid, otherwise the result of `addMoney`.

Example Usage

  character:giveMoney(250)

takeMoney(amount)View Source

Purpose

Removes money from the owning player by applying a negative money change.

Realm

Server

Parameters

number amount The amount to remove.

Returns

boolean Always returns `true`.

Example Usage

  character:takeMoney(100)

isMainCharacter()View Source

Purpose

Checks whether this character is set as the player's main character.

Realm

Server

Returns

boolean `true` when the owner's main character ID matches this character.

Example Usage

  if character:isMainCharacter() then
      print("This is the player's main character.")
  end