Fireflies
Based on game build 714014 | Last updated: 2026-03-05
Overview
fireflies is a prefab definition that creates a lightweight, dynamic entity used primarily as a collectible item and light source in DST. It manages client-side lighting modulation via fading animations and server-side gameplay logic (e.g., workability, pickup, stacking, and hauntable interactions). The entity reacts to player proximity and world state (isnight) to control its active state—fading in when near a player at night and fading out otherwise.
Usage example
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddPhysics()
inst.entity:AddLight()
inst.entity:AddNetwork()
-- Load the fireflies prefab logic
inst:DoTaskInTime(0, function()
local firefly = Prefab("fireflies", nil, nil):Spawn(inst:GetPosition())
end)
Dependencies & tags
Components used:
playerproxinspectableworkablestackableinventoryitemtradablefuelhauntable
Tags:
- Adds:
firefly,cattoyairborne,flying,NOBLOCK,NOCLICK - Checks:
NOCLICK(removes/adds based on fade state)
Properties
No public properties are exposed directly. Internal reactive values are managed via replicated network variables:
| Property | Type | Default Value | Description |
|---|---|---|---|
inst._fadeval | net_float | 0 | Tracks current light intensity (0 to INTENSITY). |
inst._faderate | net_smallbyte | 0 | Controls fade direction/rate (0 = none, <0 = fade out, >0 = fade in). |
Main functions
fadein(inst)
- Description: Triggers the firefly to fade in: enables light and animation (
swarm_loop), removesNOCLICKtag, and enables workability. Called when player proximity and night state justify activation. - Parameters:
inst(Entity) — the firefly instance. - Returns: Nothing.
- Error states: No-op if already in fade-in state or not mastersim when expecting server-side state changes.
fadeout(inst)
- Description: Triggers the firefly to fade out: plays
swarm_pstanimation, disables light, addsNOCLICKtag, disables workability, and waits before schedulingdisablework. - Parameters:
inst(Entity) — the firefly instance. - Returns: Nothing.
- Error states: No-op if already fading out or not mastersim.
updatefade(inst, rate)
- Description: Applies incremental light intensity changes over time to animate fading in/out smoothly. Uses
inst._fadevaland synchronizes client lighting viainst.Light:SetIntensity. - Parameters:
inst(Entity) — the firefly instance.rate(number) — intensity delta per frame; derived fromresolvefaderate.
- Returns: Nothing.
- Error states: Stops task and resets when intensity reaches bound (
0orINTENSITY); on master, addsNOCLICKtag and disables light when fade completes at0.
resolvefaderate(x)
- Description: Computes the fade rate (intensity change per frame) based on
_faderatevalue. Returns a rate in (0, positive] for fade-in, negative for fade-out, or0for no change. - Parameters:
x(number) — the current_faderatevalue (0,1..31, or32..63). - Returns: number — calculated fade rate.
- Error states: None; uses precomputed constants (
INTENSITY,FRAMES) and clamp logic.
updatelight(inst)
- Description: Re-evaluates whether the firefly should be active based on night status and player proximity. Invokes
fadeinorfadeoutas appropriate. - Parameters:
inst(Entity) — the firefly instance. - Returns: Nothing.
ondropped(inst)
- Description: Callback for inventory item drop event. Resets work left, triggers immediate fade-out, then schedules a delayed
updatelightcall. - Parameters:
inst(Entity) — the firefly instance. - Returns: Nothing.
onputininventory(inst)
- Description: Callback for inventory insert event. Immediately disables fade task, light, and animation; sets intensity to
0. - Parameters:
inst(Entity) — the firefly instance. - Returns: Nothing.
getstatus(inst)
- Description: Returns
"HELD"when the firefly is held by a player; otherwise returnsnil. - Parameters:
inst(Entity) — the firefly instance. - Returns:
"HELD"ornil.
Events & listeners
-
Listens to:
onfaderatedirty— triggers re-computation of fade state viaOnFadeRateDirty(client-side only).isnight— triggersupdatelightafter delay viaOnIsNight.
-
Pushes:
onfaderatedirty— implicitly triggered viainst._faderate:set(...)(see networked variable binding).