Possessedaxe
Based on game build 714014 | Last updated: 2026-03-03
Overview
Possessedaxe is a component that manages the lifecycle of Lucy, a special axe that transforms when held by a valid woodcutter player ("woodcutter" tag). It tracks player association, handles delayed reversion upon player disconnect or death, and ensures only one Lucy exists per player. The component integrates closely with inventory, inventoryitem, equippable, and finiteuses components to manage item state during possession, dropping, and reversion.
Usage example
local inst = CreateEntity()
inst:AddTag("axe")
inst:AddComponent("possessedaxe")
inst:AddComponent("equippable")
inst:AddComponent("inventoryitem")
inst:AddComponent("finiteuses")
inst.components.possessedaxe.revert_prefab = "axe"
inst.components.possessedaxe.revert_uses = 10
inst.components.possessedaxe.revert_fx = "lucy_transform"
Dependencies & tags
Components used: inventory, inventoryitem, equippable, finiteuses
Tags: Checks for "woodcutter" (owner), "player" (owner), "usesdepleted" (via finiteuses), "equippable" (via equippable:IsEquipped()).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
revert_prefab | string | "axe" | Prefab name to spawn on reversion. |
revert_uses | number? | nil | Uses value to restore to the reverted item via finiteuses:SetUses. |
revert_fx | string? | nil | FX prefab name to spawn during reversion. |
revert_time | number | TUNING.LUCY_REVERT_TIME | Delay in seconds before auto-reverting after player loss. |
player | Entity? | nil | Current linked player entity (if any). |
userid | string? | nil | User ID of the linked player, preserved across reconnects. |
currentowner | Entity? | nil | Current inventory item owner (e.g., player). |
checkownertask | Task? | nil | Deferred task to validate the owner. |
waittask | Task? | nil | Task for delayed reversion (e.g., timeout). |
waittotime | number? | nil | Absolute game time when reversion triggers. |
oncontainerpickedup | function? | nil | Listener callback for owner container events. |
Main functions
WaitForPlayer(userid, delay)
- Description: Initiates a reversion timer for the axe if ownership is lost. The axe remains associated with
useridand will revert afterdelayseconds unless re-linked. Can be cancelled viaStopWaitingForPlayer. - Parameters:
userid(string?) — User ID to track;nilclears the listener.delay(number?) — Revert delay in seconds; defaults torevert_timeifnil.
- Returns: Nothing.
StopWaitingForPlayer()
- Description: Cancels the pending reversion timer and removes the
"ms_playerjoined"event listener. - Parameters: None.
- Returns: Nothing.
LinkToPlayer(player)
- Description: Associates the axe with a specific player entity. Updates
playeranduseridfields, removes old listeners, sets up newonremoveand"possessedaxe"listeners on the player, and fires"axepossessedbyplayer"with the player entity. Reverts if the player already holds another Lucy. - Parameters:
player(Entity?) — Player entity to link;nildrops current association.
- Returns: Nothing.
Drop()
- Description: Drops the axe from its owner's inventory if present and valid. Calls
Inventory:DropItem(self.inst, true, true). - Parameters: None.
- Returns: Nothing.
Revert()
- Description: Spawns the
revert_prefab(typically"axe"), copies overrevert_uses(if specified), and transfers the item to the same position or inventory slot as the original. Handles equipped, held, and container-dropped cases. Optionally spawnsrevert_fx. - Parameters: None.
- Returns: Entity — The newly spawned reverted item (or
self.instif reversion fails). - Error states: Returns early with
self.instifSpawnPrefab(revert_prefab)fails.
OnSave()
- Description: Serializes component state for persistence. Includes
prefab,uses,userid, and remaining time for pending reversion. - Parameters: None.
- Returns: table? — A table with keys
prefab,uses,userid, andwaittimeremaining, ornilif all values arenil/empty.
OnLoad(data)
- Description: Restores component state after a save load. Restores
revert_prefabandrevert_uses, and resumes waiting for a player if needed. - Parameters:
data(table?) — Save data fromOnSave.
- Returns: Nothing.
GetDebugString()
- Description: Returns a human-readable debug string summarizing current state.
- Parameters: None.
- Returns: string — A formatted string like
"held: player entity player: player entity timeout: 12.34".
Events & listeners
-
Listens to:
"onputininventory"— TriggersOnChangeOwneron item placement."ondropped"— TriggersOnChangeOwneron drop."onremove"— Removesonplayerremovedcallback when linked player is removed."possessedaxe"— Triggersonplayerpossessedaxe(callsRevert) if another Lucy is obtained."ms_playerjoined"— Triggersonplayerjoinedwhen a player rejoins the world.
-
Pushes:
"axerejectedowner"— Fired when the owner is not a woodcutter."axerejectedotheraxe"— Fired when another possessed axe is present in the owner’s inventory."axepossessedbyplayer"— Fired on successful linking or clearing of the player link.