Pocketwatch Common
Based on game build 714014 | Last updated: 2026-03-06
Overview
pocketwatch_common.lua is a shared helper module that defines two core functions for constructing and extending pocket watch prefabs. The common_fn function initializes the base structure for all pocket watch entities—setting up required components (inventoryitem, rechargeable, pocketwatch, inspectable), animations, physics, and tags. The MakeRecallMarkable function enhances an existing entity with recall-marking capabilities by adding the recallmark component and synchronizing marker visuals based on ownership and position state. This module centralizes common logic used across different pocket watch variants in the game.
Usage example
local prefabs = require "prefabs/pocketwatch_common"
local function MyPocketWatch()
local inst = prefabs.common_fn("bank_name", "build_name", DoCastSpell, true, {"mycustomtag"}, nil, nil)
prefabs.MakeRecallMarkable(inst)
return inst
end
Dependencies & tags
Components used:
inventoryitem(viainst.components.inventoryitem)rechargeable(viainst.components.rechargeable)pocketwatch(viainst.components.pocketwatch)inspectable(viainst.components.inspectable)recallmark(viainst.components.recallmark, added byMakeRecallMarkable)
Tags added by common_fn:
pocketwatchcattoypocketwatch_castfrominventory(only ifcast_from_inventoryistrue)- Any custom tags passed via the
tagsarray
Tags checked:
playerghostpocketwatchcaster
Properties
No public properties are exposed directly in the module's returned functions. Properties are set on the created inst entity within common_fn and MakeRecallMarkable, and are handled via component APIs.
Main functions
common_fn(bank, build, DoCastSpell, cast_from_inventory, tags, common_postinit, master_postinit)
- Description: Constructs and configures a new pocket watch entity. Handles setup of basic entity structure (transform, anim state, sound, network), inventory physics, component registration, animation, and post-initialization callbacks for both client and master simulation.
- Parameters:
bank(string) – AnimState bank name for the item.build(string) – AnimState build name for the item.DoCastSpell(function) – Function assigned toinst.components.pocketwatch.DoCastSpell.cast_from_inventory(boolean) – Iftrue, adds thepocketwatch_castfrominventorytag.tags(array of strings, optional) – Additional tags to apply.common_postinit(function, optional) – Callback run after common (non-master-only) setup, before returning for clients.master_postinit(function, optional) – Callback run after master-only setup (server-side).
- Returns:
inst– The fully initialized entity. - Error states: Returns early (without master setup) for non-master simulations (
TheWorld.ismastersim == false).
MakeRecallMarkable(inst)
- Description: Adds recall-marking functionality to an existing entity. Attaches the
recallmarkcomponent, sets up event listeners for ownership/dropping events, and manages the spawning and removal of a visual marker prefab (pocketwatch_recall_marker) when the item is held by a valid, non-ghost owner. - Parameters:
inst(entity) – The entity to enhance with recall-marking capabilities.
- Returns: Nothing.
- Error states: Marker creation only proceeds if
recallmark:IsMarked()istrue, the marked position is on the same shard, and the grand owner exists and is not a ghost. Fails silently otherwise.
Events & listeners
- Listens to (in
MakeRecallMarkable):onputininventory– Triggers marker creation.onownerputininventory– Triggers marker creation.ondropped– Triggers marker removal.onownerdropped– Triggers marker removal.onremove– Triggers marker removal.ms_respawnedfromghost– Triggers marker recreation after player respawns (listens on grand owner).
- Pushes: None directly. Relies on
recallmarkcomponent’sonMarkPositioncallback and event-driven marker lifecycle.