Playeravatardata
Overview
The PlayerAvatarData component stores and synchronizes player avatar configuration—such as name, base and clothing skins, player age, and equipment—across the network and to disk. It is attached to player entities and facilitates bidirectional data flow between client-side UI, network replication (via net_* types), and persistent saves, without requiring additional server-side components.
Dependencies & Tags
- Relies on
EquipSlotmodule (equipslotutil.lua) to map equipment slot IDs to names and vice versa. - Does not add or remove entity tags itself.
- Does not directly add other components via
inst:AddComponent.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | Reference to the associated player entity. |
hasdata | boolean? | nil | Flag indicating whether any avatar data has been initialized. |
allowemptyname | boolean | true | Whether empty names are permitted when retrieving data. |
allowburnt | boolean | true | Whether burnt players (tag "burnt") are allowed in data retrieval. |
strings | table? | nil | Networked string fields (name, prefab). Initialized on first call to AddNameData. |
skins | table? | nil | Networked skin fields (base_skin, body_skin, hand_skin, legs_skin, feet_skin). Initialized on AddBaseSkinData or AddClothingData. |
numbers | table? | nil | Networked numeric fields (playerage). Initialized on AddAgeData. |
equip | table? | nil | Array of networked equipment slot strings (indexed by EquipSlot ID). Initialized on AddEquipData. |
unsupported_equips | table? | nil | Map of equipment slot names (not IDs) not recognized in currentEquipSlot definition, used during save/load for backwards/forwards compatibility. |
savestrings, saveskins, savenumbers, saveequip | boolean | nil | Flags indicating whether corresponding data fields should be persisted to disk. Set on respective Add*Data calls. |
Main Functions
SetAllowEmptyName(allow)
- Description: Sets whether empty player names are acceptable when calling
GetData. - Parameters:
allow(boolean?) — Iffalseor omitted, empty names will causeGetDatato returnnil.
SetAllowBurnt(allow)
- Description: Sets whether players tagged as
"burnt"are allowed in the returned avatar data. - Parameters:
allow(boolean?) — Iffalseor omitted, burnt players will causeGetDatato returnnil.
AddNameData(save)
- Description: Initializes the
strings.nameandstrings.prefabnetworked fields. Marks data as present if not already. - Parameters:
save(boolean?) — If truthy, setssavestrings = truefor saving.
AddBaseSkinData(save)
- Description: Initializes
skins.base_skin. Initializesskinstable if not present. - Parameters:
save(boolean?) — If truthy, setssaveskins = truefor saving.
AddClothingData(save)
- Description: Initializes clothing skin fields (
body_skin,hand_skin,legs_skin,feet_skin). Initializesskinstable if not present. - Parameters:
save(boolean?) — If truthy, setssaveskins = truefor saving.
AddAgeData(save)
- Description: Initializes
numbers.playerage. Marks data as present if not already. - Parameters:
save(boolean?) — If truthy, setssavenumbers = truefor saving.
AddEquipData(save)
- Description: Initializes
equiparray with onenet_stringper slot ID (usingEquipSlot.Count()). Marks data as present if not already. - Parameters:
save(boolean?) — If truthy, setssaveequip = truefor saving.
AddPlayerData(save)
- Description: Convenience method to initialize all avatar data types in one call.
- Parameters:
save(boolean?) — Applied to all data initialization calls.
GetData()
- Description: Returns a plain Lua table with the current avatar values, suitable for UI or net replication. Returns
nilif no data is available or if constraints (allowemptyname,allowburnt) are violated. - Parameters: None.
SetData(client_obj)
- Description: Populates internal networked fields from a plain Lua table (e.g., from a client UI submission or network packet).
- Parameters:
client_obj(table?) — Dictionary-like object with keys matching avatar data fields.
OnSave()
- Description: Serializes avatar data into a plain Lua table for saving to disk, mapping equip slot IDs to their canonical names.
- Parameters: None.
- Returns:
table?— Non-empty save table ornilif no data.
OnLoad(data)
- Description: Loads persisted avatar data from disk into internal networked fields, converting equip slot names back to IDs.
- Parameters:
data(table?) — Saved avatar data table.
Events & Listeners
None.