SaltLicker
Based on game build 722832 | Last updated: 2026-04-28
Overview
SaltLicker enables an entity to seek out nearby saltlick objects and consume uses from them over a timed duration. It periodically searches for valid saltlicks within range, starts a timer when one is found, and consumes a configured number of uses per lick interval. The component integrates with timer, sleeper, and freezable components to pause behavior during sleep, freeze, or limbo states.
Usage example
local inst = CreateEntity()
inst:AddComponent("timer")
inst:AddComponent("saltlicker")
inst.components.saltlicker:SetUp(3) -- 3 uses consumed per lick interval
inst.components.saltlicker:SetSalted(true)
Dependencies & tags
Components used:
timer-- required; manages the salt consumption timer (asserted in constructor)finiteuses-- accessed on saltlick entity to consume uses per licksleeper-- checked to pause behavior when entity is asleepfreezable-- checked to pause behavior when entity is frozen
Tags:
saltlicker-- added in constructor; marks entity as having this componentsaltlicker_salted-- added/removed via property watcher whensaltedchanges
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
salted | boolean | false | Whether the entity is currently salted. Assignment fires onsalted watcher. |
saltedduration | number | TUNING.SALTLICK_DURATION | Duration in seconds for each salt consumption cycle. |
uses_per_lick | number | nil | nil | Number of finite uses consumed from saltlick per timer interval. |
_task | task | nil | nil | Periodic task reference for seeking behavior. |
saltlick | entity | nil | nil | Reference to the currently targeted saltlick entity. |
Main functions
SetUp(uses_per_lick)
- Description: Initializes the saltlicker behavior with a configured uses-per-lick value. Registers all event listeners and starts the seeking timer if valid.
- Parameters:
uses_per_lick-- number of uses to consume from saltlick per interval, ornilto disable
- Returns: nil
- Error states: Errors if
self.insthas notimercomponent (asserted in constructor).
Stop()
- Description: Halts all saltlicker activity. Removes all event listeners, stops the salt timer, cancels seeking task, and resets state. Called automatically in
OnRemoveFromEntity. - Parameters: None
- Returns: nil
- Error states: None
SetSalted(salted)
- Description: Sets the salted state. Only pushes
saltchangeevent if the value actually changes. - Parameters:
salted-- boolean target state
- Returns: nil
- Error states: None
OnRemoveFromEntity()
- Description: Cleanup handler called when component is removed from entity. Stops all activity and removes both
saltlickerandsaltlicker_saltedtags. - Parameters: None
- Returns: nil
- Error states: None
OnSave()
- Description: Returns save data if the entity is currently salted. Only saves when
self.saltedis true to avoid triggering LoadPostPass unnecessarily. - Parameters: None
- Returns:
{ salted = true }if salted,nilotherwise
LoadPostPass()
- Description: Restores salted state after world load by checking if the timer component still has the salt timer active.
- Parameters: None
- Returns: nil
- Error states: None
GetDebugString()
- Description: Returns debug information including salted state, time remaining on salt timer, seeking task next time, duration, and uses per lick.
- Parameters: None
- Returns: string debug output
onsalted(self, salted) (local)
- Description: Property watcher callback fired when
self.saltedis assigned. Adds or removes thesaltlicker_saltedtag based on the new value. - Parameters:
self-- component instancesalted-- boolean new value
- Returns: nil
- Error states: None
_checkforsaltlick(inst, self) (local)
- Description: Searches for a valid saltlick entity within
TUNING.SALTLICK_CHECK_DIST. If found, stores reference, starts salt timer, stops seeking, and sets salted to true. - Parameters:
inst-- entity instanceself-- component instance
- Returns:
trueif saltlick found,falseotherwise - Error states: None
_onsaltlickplaced(inst, data) (local)
- Description: Event handler for
saltlick_placed. If no salt timer exists and the placed saltlick is within range, starts consuming from it immediately. - Parameters:
inst-- entity instancedata-- event data withdata.instbeing the placed saltlick
- Returns: nil
- Error states: None
_StopSeeking(self) (local)
- Description: Cancels the periodic seeking task and removes the
saltlick_placedevent listener. - Parameters:
self-- component instance
- Returns: nil
- Error states: None
_StartSeeking(self) (local)
- Description: Starts periodic seeking for saltlicks. Cancels any existing task, registers
saltlick_placedlistener, and creates a new periodic task with period =saltedduration * 0.125. - Parameters:
self-- component instance
- Returns: nil
- Error states: None
_ontimerdone(inst, data) (local)
- Description: Timer completion handler. Consumes
uses_per_lickfrom the saltlick'sfiniteusescomponent if valid. Then checks if entity should remain salted or resume seeking based on limbo/sleep/freeze state. - Parameters:
inst-- entity instancedata-- timer event data withdata.name
- Returns: nil
- Error states: None
OnPause(inst) (local)
- Description: Pauses saltlicker behavior when entity enters limbo, sleep, or freeze state. Stops the salt timer and seeking task.
- Parameters:
inst-- entity instance
- Returns: nil
- Error states: None
TryUnpause(inst) (local)
- Description: Attempts to resume saltlicker behavior when entity exits limbo, sleep, or freeze. Only resumes if no salt timer is already running and entity is in valid state.
- Parameters:
inst-- entity instance
- Returns: nil
- Error states: None
OnDeath(inst) (local)
- Description: Death event handler. Calls
Stop()to clean up all saltlicker activity when the entity dies. - Parameters:
inst-- entity instance
- Returns: nil
- Error states: None
Events & listeners
-
Listens to:
timerdone-- triggers_ontimerdone; consumes uses from saltlick when timer expiresenterlimbo-- triggersOnPause; pauses behavior when entity enters limboexitlimbo-- triggersTryUnpause; attempts to resume behavior when exiting limbogotosleep-- triggersOnPause; pauses behavior when entity falls asleeponwakeup-- triggersTryUnpause; attempts to resume behavior when waking upfreeze-- triggersOnPause; pauses behavior when entity freezesunfreeze-- triggersTryUnpause; attempts to resume behavior when thawingdeath-- triggersOnDeath; stops all saltlicker activity on entity deathsaltlick_placed-- triggers_onsaltlickplaced; handles nearby saltlick placement events
-
Pushes:
saltchange-- fired whenSetSalted()changes the salted state. Data:{ salted = boolean }