Wardrobe
Based on game build 714014 | Last updated: 2026-03-03
Overview
The wardrobe component enables an entity to function as a dressing station where players or other entities can change skins and clothing. It coordinates animation state transitions (e.g., openwardrobe, dressupwardrobe, changeinwardrobe), handles concurrent usage via changers tracking, and integrates with the skinner, burnable, and talker components to enforce constraints and provide feedback. When canbedressed is true, the wardrobe dresses the wardrobe entity itself; otherwise, it dresses the doer.
Usage example
local inst = CreateEntity()
inst:AddComponent("wardrobe")
inst.components.wardrobe:Enable(true)
inst.components.wardrobe:SetCanBeShared(false)
inst.components.wardrobe:SetRange(4)
inst.components.wardrobe:SetChangeInDelay(1.0)
inst.components.wardrobe:SetCanBeDressed(true)
Dependencies & tags
Components used: burnable, skinner, talker
Tags: Adds "wardrobe" and "dressable" conditionally based on canuseaction and canbedressed.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
changers | table | {} | Map of doer entities currently using the wardrobe; keys are entity instances. |
enabled | boolean | true | Whether the wardrobe is usable at all. |
canuseaction | boolean | true | Whether the wardrobe appears in action collections (affects "wardrobe" tag). |
canbedressed | boolean | nil | Whether the wardrobe dresses the wardrobe entity (true) or the doer (false/nil). |
canbeshared | boolean | false | Whether multiple entities may use the wardrobe simultaneously. |
range | number | 3 | Max distance from the wardrobe at which a user is still considered inside. |
changeindelay | number | 0 | Delay (in seconds) before triggering post-change logic in non-shared mode. |
onchangeinfn | function | nil | Callback fired after changeinwardrobe animation starts in non-shared mode. |
ondressupfn | function | nil | Callback for the dressing phase; takes a completion callback as argument. |
onopenfn | function | nil | Callback fired when the first user opens the wardrobe (i.e., changers transitions from empty). |
onclosefn | function | nil | Callback fired when the last user closes the wardrobe. |
Main functions
SetCanUseAction(canuseaction)
- Description: Controls whether the wardrobe can be targeted by actions. Sets the
"wardrobe"tag based on the value. - Parameters:
canuseaction(boolean) — whether the wardrobe is accessible via actions. - Returns: Nothing.
SetCanBeDressed(canbedressed)
- Description: Sets the dressing mode. When
true, the wardrobe entity is dressed; otherwise, the doer is dressed. - Parameters:
canbedressed(boolean ornil) — target of the dressing operation. - Returns: Nothing.
Enable(enable)
- Description: Enables or disables the wardrobe. When disabled, callers cannot begin changing.
- Parameters:
enable(boolean) —trueenables usage (default);falsedisables. - Returns: Nothing.
SetCanBeShared(canbeshared)
- Description: Enables or disables multi-user usage. When disabled, the wardrobe listens to
"onignite"to end all users if it catches fire. - Parameters:
canbeshared(boolean) —trueallows concurrent usage. - Returns: Nothing.
SetRange(range)
- Description: Sets the radius around the wardrobe within which users remain considered "inside".
- Parameters:
range(number) — max distance in world units. - Returns: Nothing.
SetChangeInDelay(delay)
- Description: Sets the delay before the
"changeinwardrobe"animation completes and post-change logic runs (non-shared mode only). - Parameters:
delay(number) — delay in seconds. - Returns: Nothing.
CanBeginChanging(doer)
- Description: Validates whether a given entity (
doer) may begin using the wardrobe. - Parameters:
doer(entity instance) — the player or entity attempting to use the wardrobe. - Returns:
trueif usage may proceed.false, "INUSE"if the wardrobe is disabled or already in use (non-shared).false, "BURNING"if the wardrobe is on fire.falseifdoeris busy or already in the process.
- Error states: Returns early with
falseifdoer.sg == nilordoer.sghas the"busy"state tag (exceptopengift).
BeginChanging(doer)
- Description: Starts the dressing process for
doer. Enters the"openwardrobe"animation state. - Parameters:
doer(entity instance). - Returns:
trueif successfully started;falseifdoeris already inchangers. - Error states: Does nothing and returns
falseifdoeris already in the process.
EndChanging(doer)
- Description: Ends the dressing process for
doer, cleans up event listeners, and potentially fires the close callback. - Parameters:
doer(entity instance). - Returns: Nothing.
- Notes: Fires
onskinschangedondoerand transitionsdoerback to"idle"if still in the wardrobe.
EndAllChanging()
- Description: Ends dressing for all current users.
- Parameters: None.
- Returns: Nothing.
ActivateChanging(doer, skins)
- Description: Initiates the actual skin/clothing application phase based on current
canbedressedandcanbesharedsettings. - Parameters:
doer(entity instance) — the dressing user.skins(table) — a table of keys{ base, body, hand, legs, feet }with skin/clothing names as values.
- Returns:
trueif the changing process started;falseif validation failed (e.g.,skins == nil,doernot in"openwardrobe"state, or noskinnercomponent). - Notes: Calls
DoDoerChangingorDoTargetChanginginternally.
ApplySkins(doer, diff)
- Description: Applies selected clothing/skins to
doer, usingskinnermethods (SetSkinName,ClearClothing,SetClothing). - Parameters:
doer(entity instance).diff(table) — map with keysbase,body,hand,legs,feet; only non-niland changed values are applied.
- Returns: Nothing.
ApplyTargetSkins(target, doer, skins)
- Description: Applies selected clothing/skins to the wardrobe entity itself when
canbedressed == true. - Parameters:
target(entity instance) — the wardrobe entity.doer(entity instance) — the user (for ownership tracking).skins(table) — mapping{ body, hand, legs, feet }forAnimState:AssignItemSkins.
- Returns: Nothing.
- Notes: Clears all existing clothing on the target and pushes
dressedupevent.
OnUpdate(dt)
- Description: Called when the wardrobe is updating (i.e., has users). Automatically ends usage for users who move out of range or cannot see the wardrobe.
- Parameters:
dt(number) — delta time. - Returns: Nothing.
Events & listeners
- Listens to:
"onignite"— stops all current dressing sessions and notifies users ifcanbeshared == false."onremove"— triggersonclosewardrobecallback for a doer when removed."ms_closepopup"— captures wardrobe popup closure and invokesonclosewardrobe.
- Pushes:
dressedup— fired on the target entity afterApplyTargetSkinscompletes.onskinschanged— fired on the doer when ending a dressing session.
onclosewardrobe
- Type: Internal callback (not an event).
- Description: Invoked on popup close; re-evaluates the result of the dressing operation. If
ActivateChangingfails, callsEndChanging.
onclosepopup
- Type: Internal listener function.
- Description: Parses
ms_closepopupevent data forPOPUPS.WARDROBE, extracts skins, and delegates toonclosewardrobe.
OnIgnite
- Type: Event handler.
- Description: When the wardrobe catches fire, ends all ongoing dressing sessions and tells users why via
talker:Say.