Character

Contains information about a player's current game state.

Characters are a fundamental object type in Lilia. They are distinct from players, where players are the representation of a person's existence in the server that owns a character, and their character is their currently selected persona. All the characters that a player owns will be loaded into memory once they connect to the server. Characters are saved during a regular interval (lia.config.CharacterDataSaveInterval), and during specific events (e.g when the owning player switches away from one character to another).

They contain all information that is not persistent with the player; names, descriptions, model, currency, etc. For the most part, you'll want to keep all information stored on the character since it will probably be different or change if the player switches to another character. An easy way to do this is to use lia.char.registerVar to easily create accessor functions for variables that automatically save to the character object.

Functions

meta:WhitelistAllClasses()

Whitelists all classes for the character.

meta:WhitelistAllFactions()

Whitelists all factions for the character.

meta:WhitelistEverything()

Whitelists everything (all classes and factions) for the character.

meta:__eq(other)

Returns true if this character is equal to another character. Internally, this checks character IDs.

Parameters

  • other Character

    Character to compare to

Returns

  • any

    bool Whether or not this character is equal to the given character

Example Usage

print(lia.char.loaded[1] == lia.char.loaded[2])
 > false

meta:__tostring()

Returns a string representation of this character

Returns

  • any

    string String representation

Example Usage

print(lia.char.loaded[1])
 > "character[1]"

meta:addBoost(boostID, attribID, boostAmount)

Adds a boost to the character's attributes.

Parameters

  • boostID String

    The ID of the boost to add.

  • attribID String

    The ID of the attribute to which the boost should be added.

  • boostAmount Integer

    The amount of boost to add to the attribute.

Example Usage

character:removeBoost("some_boost_id", "some_attribute_id", 10)

meta:ban(time)

Forces a player off their current character, and prevents them from using the character for the specified amount of time.

Parameters

  • time Float optional

    Amount of seconds to ban the character for. If left as nil, the character will be banned permanently

meta:classUnWhitelist(class)

Removes the whitelist for a specific class from the character.

Parameters

  • class Integer

    The class to remove the whitelist status for.

meta:classWhitelist(class)

Whitelists the character for a specific class.

Parameters

  • class Integer

    The class to whitelist the character for.

meta:delete()

Deletes the character from the character database and removes it from memory.

meta:destroy()

Destroys the character, removing it from memory and notifying clients to remove it.

meta:getAttrib(key, default)

Retrieves the value of a character attribute, including applied boosts.

Parameters

  • key String

    The key of the attribute to retrieve.

  • default Integer default: 0

    The default value to return if the attribute is not found.

Returns

  • any

    number The value of the specified attribute, including applied boosts.

Example Usage

local attributeValue = character:getAttrib("some_attribute_key")

meta:getBoost(attribID)

Retrieves the boost value for a specific attribute.

Parameters

  • attribID Integer

    The ID of the attribute for which to retrieve the boost.

Returns

  • any

    number|nil The boost value for the specified attribute, or nil if no boost is found.

Example Usage

local boostValue = character:getBoost("some_attribute_id")

meta:getBoosts()

Retrieves all boosts applied to the character's attributes.

Returns

  • any

    table A table containing all boosts applied to the character's attributes.

Example Usage

local boostsTable = character:getBoosts()

meta:getFlags()

Returns all of the flags this character has.

Returns

  • string

    Flags this character has represented as one string. You can access individual flags by iterating through the string letter by letter

meta:getID()

Returns this character's database ID. This is guaranteed to be unique.

Returns

  • any

    number Unique ID of character

meta:getItemWeapon()

Retrieves the character's equipped weapon and its corresponding item from the inventory.

Returns

  • any

    Entity|false The equipped weapon entity, or false if no weapon is equipped.

  • any

    Item|false The corresponding item from the character's inventory, or false if no corresponding item is found.

Example Usage

local weapon, item = character:getItemWeapon()

meta:getPlayer()

Returns the player that owns this character.

Returns

  • any

    player Player that owns this character

meta:giveFlags(flags)

Adds a flag to the list of this character's accessible flags. This does not overwrite existing flags.

Parameters

  • flags String

    Flag(s) this character should be given

Example Usage

character:GiveFlags("pet")
 gives p, e, and t flags to the character

See Also

meta:giveMoney(amount, takingMoney)

Gives or takes money from the character's wallet.

Parameters

  • amount Integer

    The amount of money to give or take.

  • takingMoney Boolean default: false

    Whether the operation is to take money from the character.

Returns

  • any

    bool Whether the operation was successful.

meta:hasClassWhitelist(class)

Checks if the player has whitelisted access to a class.

Parameters

  • class Integer

    The class to check for whitelisting.

Returns

  • bool

    Whether the player has whitelisted access to the specified faction.

meta:hasFlags(flags)

Returns true if the character has the given flag(s).

Parameters

  • flags String

    Flag(s) to check access for

Returns

  • bool

    Whether or not this character has access to the given flag(s)

meta:hasMoney(amount)

Checks if the character has at least the specified amount of money.

Parameters

  • amount Integer

    The amount of money to check for.

Returns

  • any

    bool Whether the character has at least the specified amount of money.

Example Usage

local hasEnoughMoney = character:hasMoney(100)

meta:isClass(class)

Checks if the player belongs to the specified class.

Parameters

  • class String

    The class to check against.

Returns

  • bool

    Whether the player belongs to the specified class.

meta:isFaction(faction)

Checks if the player belongs to the specified faction.

Parameters

  • faction String

    The faction to check against.

Returns

  • bool

    Whether the player belongs to the specified faction.

meta:joinClass(class, isForced)

Sets the character's class to the specified class.

Parameters

  • class String

    The class to join.

  • isForced Boolean default: false

    Whether to force the character to join the class even if conditions are not met.

Returns

  • any

    bool Whether the character successfully joined the class.

Example Usage

local success = character:joinClass("some_class")

meta:kick()

Forces a player off their current character, and sends them to the character menu to select a character.

meta:kickClass()

Kicks the character from their current class and joins them to the default class of their faction.

Example Usage

character:kickClass()

meta:removeBoost(boostID, attribID)

Removes a boost from the character's attributes.

Parameters

  • boostID String

    The ID of the boost to remove.

  • attribID String

    The ID of the attribute from which the boost should be removed.

Example Usage

character:removeBoost("some_boost_id", "some_attribute_id")

meta:save(callback)

Saves this character's info to the database.

Parameters

  • callback Function default: nil

    Function to call when the save has completed.

Example Usage

lia.char.loaded[1]:save(function()
	print("Done saving " .. lia.char.loaded[1] .. "!")
end)
> Done saving character[1]! -- after a moment

meta:setAttrib(key, value)

Sets the value of a character attribute.

Parameters

  • key String

    The key of the attribute to set.

  • value Integer

    The value to set for the attribute.

Example Usage

character:setAttrib("some_attribute_key", 10)

meta:setFlags(flags)

Sets this character's accessible flags. Note that this method overwrites all flags instead of adding them.

Parameters

  • flags String

    Flag(s) this charater is allowed to have

See Also

meta:sync(receiver)

Internal

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

Networks this character's information to make the given player aware of this character's existence. If the receiver is not the owner of this character, it will only be sent a limited amount of data (as it does not need anything else). This is done automatically by the framework.

Parameters

  • receiver Player default: nil

    Player to send the information to. This will sync to all connected players if set to nil.

meta:takeFlags(flags)

Removes this character's access to the given flags.

Parameters

  • flags String

    Flag(s) to remove from this character

Example Usage

-- for a character with "pet" flags
character:takeFlags("p")
-- character now has e, and t flags

meta:takeMoney(amount)

Takes money from the character's wallet.

Parameters

  • amount Integer

    The amount of money to take.

Returns

  • any

    bool Whether the operation was successful.

meta:updateAttrib(key, value)

Updates the value of a character attribute by adding a specified value to it.

Parameters

  • key String

    The key of the attribute to update.

  • value Integer

    The value to add to the attribute.

Example Usage

character:updateAttrib("some_attribute_key", 10)