Hideandseekhider
Based on game build 714014 | Last updated: 2026-03-03
Overview
hideandseekhider tracks and controls an entity's participation in hide-and-seek gameplay as a hider. It manages interactions with hideandseekhidingspot components, coordinates movement and hide timers, and handles save/load state for multiplayer persistence. It is typically attached to player characters during hide-and-seek events.
Usage example
local inst = ThePlayer
inst:AddComponent("hideandseekhider")
-- Attempt to hide in a spot with default timeout
local spot = SpawnPrefab("kitchen_cabinet")
local success = inst.components.hideandseekhider:GoHide(spot, 0)
-- Check if currently playing (i.e., assigned a hiding spot)
if inst.components.hideandseekhider:IsPlaying() then
print("Player is currently hiding!")
end
Dependencies & tags
Components used: hideandseekhidingspot (via hiding_spot.components.hideandseekhidingspot)
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
last_day_played | number | -1 | The world cycle count when the hider last played hide-and-seek. |
gohide_timeout | number | 3 | Default delay (in seconds) before physically hiding after initiating GoHide. |
hiding_spot | Entity or nil | nil | Reference to the entity currently acting as the hiding spot. |
runtohidingspot_task | Task or nil | nil | Pending timer task used to delay hiding; cancels if aborted. |
Main functions
IsPlaying()
- Description: Returns whether the entity is currently assigned a hiding spot (i.e., in the process of or successfully hiding).
- Parameters: None.
- Returns:
boolean—trueifhiding_spotis non-nil, otherwisefalse.
IsHidden()
- Description: Returns whether the entity is fully hidden (i.e., assigned a spot and no pending movement timer).
- Parameters: None.
- Returns:
boolean—trueifhiding_spotis non-nilandruntohidingspot_taskisnil.
GoHide(hiding_spot, timeout_time, isloading)
- Description: Initiates hiding in the provided spot. Assigns the spot, starts a delay task (unless
timeout_time == 0), and updates internal state. Handles loading from save data viaisloading. - Parameters:
hiding_spot(Entity) — The entity that will serve as the hiding location (must support thehideandseekhidingspotcomponent).timeout_time(number ornil) — Delay in seconds before fully hiding; defaults togohide_timeout. Pass0to hide instantly.isloading(boolean) — Iftrue, bypasses component validation to allow reloading from saved state.
- Returns:
boolean—trueif the hide operation was initiated,falseif already playing or spot invalid. - Error states: Returns
falseifhiding_spotalready has an active hider (unlessisloadingistrue) or if the component is already active.
CanPlayHideAndSeek()
- Description: Checks if the entity is allowed to play hide-and-seek in the current world cycle (i.e., they did not already play today).
- Parameters: None.
- Returns:
boolean—trueiflast_day_played < TheWorld.state.cycles.
Found(doer)
- Description: Ends hiding early (e.g., when discovered). Cleans up the hiding spot reference, cancels pending timers, and fires
OnFoundcallback. - Parameters:
doer(Entity ornil) — The entity that discovered the hider (can benil). - Returns: Nothing.
- Error states: No-op if
hiding_spotisnil.
Abort()
- Description: Aborts the current hide attempt. Delegates to
hideandseekhidingspot:Abort()if valid, then callsFound(nil). - Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Prepares state data for serialization (used for save/load in multiplayer).
- Parameters: None.
- Returns:
data(table),refs(table ornil) — Save data containinglast_day_played, optionalhiding_spotGUID, and optionalhiding_timeout. References table contains the hiding spot’s GUID for dependency resolution.
LoadPostPass(newents, data)
- Description: Restores state after world load. Recreates pending timers or spot assignments based on saved data.
- Parameters:
newents(table) — Map of GUID →{entity, ...}for resolved saved references.data(table ornil) — Saved state fromOnSave().
- Returns: Nothing.
GetDebugString()
- Description: Returns a debug-friendly string for logging or overlays.
- Parameters: None.
- Returns:
string—"Hiding Spot: <guid>"or"Hiding Spot: nil".
Events & listeners
- Listens to:
picked,worked,onignite,onopen,onactivated,onpickup,haunted(onhiding_prop) — triggersevict_fncallback viahideandseekhidingspotto remove hider upon spot interaction. - Pushes: None directly (callbacks like
OnHideandOnFoundare user-defined function references, not events).
Additional Notes
- Callback properties (
OnHide,StartGoingToHidingSpot,OnFound) are optional function references that callers can assign to hook into lifecycle events (e.g., UI feedback or sound triggers). They are not managed by this component itself. - The component assumes
TheWorld.state.cyclesis defined and tracks daily progression.