Attunable
Based on game build 714014 | Last updated: 2026-03-20
Overview
The Attunable component manages the relationship between an entity (such as a Resurrection Effigy) and players who have "attuned" to it. It tracks both online and offline players, ensuring persistence across sessions. It enforces grouping logic via tags, preventing players from attuning to multiple entities of the same group simultaneously. This component works in tandem with the attuner component found on player entities.
Usage example
local inst = CreateEntity()
inst:AddComponent("attunable")
-- Set a group tag to limit attunement scope
inst.components.attunable:SetAttunableTag("resurrector")
-- Define custom logic for linking
inst.components.attunable:SetOnLinkFn(function(entity, player, isloading)
print(player.name.." attuned to "..entity.prefab)
end)
-- Link a specific player
inst.components.attunable:LinkToPlayer(ThePlayer, false)
Dependencies & tags
Components used: attuner (required on player entity for validation).
Tags:
- Adds
ATTUNABLE_ID_<GUID>(unique identifier per entity instance). - Adds dynamic tag defined by
SetAttunableTag(e.g.,resurrector) to classified entities spawned during linking.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
attuned_players | table | {} | Stores currently online player instances that are attuned. |
attuned_userids | table | {} | Stores user IDs of offline players who remain attuned. |
attunable_tag | string/nil | nil | Group identifier used to enforce mutual exclusivity (e.g., only one resurrector). |
onattunecostfn | function/nil | nil | Callback to validate cost or conditions before linking. |
onlinkfn | function/nil | nil | Callback fired immediately after a successful link. |
onunlinkfn | function/nil | nil | Callback fired immediately after a link is removed. |
Main functions
SetAttunableTag(tag)
- Description: Assigns a group tag to this attunable entity. Used to prevent players from attuning to multiple entities of the same type.
- Parameters:
tag(string) - The group identifier. - Returns: Nothing.
LinkToPlayer(player, isloading)
- Description: Establishes a link between the entity and a specific player. Spawns a classified entity and registers events.
- Parameters:
player(entity) - The player instance to attune.isloading(boolean) - True if restoring from save data (skips cost checks).
- Returns:
trueon success,falseon failure. - Error states: Returns
falseifCanAttunefails oronattunecostfnreturns failure.
UnlinkFromPlayer(player, isloading)
- Description: Removes the attunement link for a specific player. Cleans up events and classified entities.
- Parameters:
player(entity) - The player instance to unattune.isloading(boolean) - Passed to the unlink callback.
- Returns: Nothing.
IsAttuned(player)
- Description: Checks if a specific player is currently attuned to this entity.
- Parameters:
player(entity) - The player instance to check. - Returns:
trueif attuned,falseotherwise.
CanAttune(player)
- Description: Validates if a player is eligible to attune (has valid userid, has
attunercomponent, not already attuned). - Parameters:
player(entity) - The player instance to validate. - Returns:
trueif eligible,falseotherwise.
OnSave()
- Description: Serializes attuned user IDs for persistence.
- Parameters: None.
- Returns: Table containing
linksarray of user IDs, ornilif empty.
OnLoad(data)
- Description: Restores attunement links from save data. Re-links online players and caches offline IDs.
- Parameters:
data(table) - Save data containinglinks. - Returns: Nothing.
Events & listeners
- Listens to:
ms_playerjoined(onTheWorld) - Re-links players who join the server.onremove(onplayer) - Cleans up link when a player entity is removed.attuned(onplayer) - Detects if a player attunes to a conflicting entity.
- Pushes:
attuned(onplayer) - Fired when a successful link is established.