A character of a player, stored in the characters table.
It belongs to a User and holds the name, gender, physical description, model, skin,
health, armor, reserve ammo and ban state of the character; other plugins add their own
columns and relations, as Factions does with the faction and rank. A record is only valid
with a name and a physical description; how long they may be is set by the
character_min_name_len, character_max_name_len, character_min_desc_len and
character_max_desc_len configs and checked when a character is created or its description
is changed by its player. Characters are created and changed through the Characters
functions and the Player extensions rather than directly.
Two columns hold serialized tables. data is the generic data of the character: any plugin
can keep values in it under string keys without adding a column, with Character:get_data
and Character:set_data. The decoded table lives in the custom_data field of the record
and is written back to the column whenever the record is saved. ammo holds the reserve
ammo as amounts by ammo type name, read and written with Character:get_ammo and
Character:set_ammo.
Summary
Methods
Methods
Called by ActiveRecord before the character is saved. Serializes the custom_data field
into the data column; an empty table is stored as NULL. The column is left as it is when
the table cannot be serialized.
Parameters
- _fetched Boolean true when the record already exists in the database
Returns the reserve ammo saved with the character.
Returns
- Map amounts of ammo by ammo type name, empty when none is saved
Returns a value from the generic data of the character.
Parameters
- key String
- default Any optional, defaults to
nilvalue to return when nothing is stored under the key
Returns
- Any
See also
Checks whether the character is banned.
Returns
- Boolean
Called by ActiveRecord when the character has been loaded from the database. Decodes the
data column into the custom_data field.
Sets the reserve ammo saved with the character. It is written to the database the next time the character is saved.
Parameters
- ammo Map amounts of ammo by ammo type name; nil or an empty table clears it
Sets a value in the generic data of the character. It is written to the database the
next time the character is saved, and sent to the owner right away if the key is
registered with Characters.network_data. Server only.
Parameters
- key String nothing happens when it is not a string
- value Any anything serializable, so no functions; nil removes the key