Hunger Replica
Based on game build 714014 | Last updated: 2026-03-03
Overview
HungerReplica is a network-aware component that exposes hunger data from the authoritative hunger component (running on the master simulation) to clients and non-master instances. It acts as a client-side or slave-side proxy, reading hunger values from a remote classified object (typically provided by the server via player_classified or pet_hunger_classified). It does not manage hunger logic itself — it only reflects the state managed by the master-side hunger component.
Usage example
-- Typically added automatically to player entities on non-master instances
-- e.g., via the player's network setup; manual usage is rare.
local inst = ThePlayer
if inst.replica.hunger then
local percent = inst.replica.hunger:GetPercent()
if inst.replica.hunger:IsStarving() then
print("Player is starving!")
end
end
Dependencies & tags
Components used: hunger (for authoritative values on master sim), classified objects (player_classified or pet_hunger_classified)
Tags: None identified.
Properties
No public properties are initialized in the constructor.
Main functions
SetCurrent(current)
- Description: Sets the current hunger value on the authoritative
classifiedobject (only valid if running on master simulation). - Parameters:
current(number) — the new current hunger value. - Returns: Nothing.
- Error states: No-op if
self.classifiedisnil.
SetMax(max)
- Description: Sets the maximum hunger value on the authoritative
classifiedobject (only valid if running on master simulation). - Parameters:
max(number) — the new maximum hunger value. - Returns: Nothing.
- Error states: No-op if
self.classifiedisnil.
Max()
- Description: Returns the maximum hunger value. Prioritizes local authoritative source (
inst.components.hunger.max) if present (master sim), otherwise reads fromclassified. Falls back to100if neither is available. - Parameters: None.
- Returns: number — current maximum hunger.
- Error states: Returns
100as a safe default if no source is available (e.g., before network sync completes).
GetPercent()
- Description: Returns the current hunger as a decimal percentage (
current / max). Prioritizes authoritativehungercomponent on master sim, otherwise reads fromclassified, and defaults to1if neither is available. - Parameters: None.
- Returns: number — hunger percentage in range
[0.0, 1.0]. - Error states: Returns
1if bothhungercomponent andclassifiedare unavailable.
GetCurrent()
- Description: Returns the current hunger value. Prioritizes authoritative
hunger.currenton master sim, otherwise reads fromclassified.currenthunger, and defaults to100if neither is available. - Parameters: None.
- Returns: number — current hunger amount.
- Error states: Returns
100if both sources are unavailable.
IsStarving()
- Description: Returns
trueif the entity is currently starving (current <= 0). Uses authoritativehunger:IsStarving()on master sim; otherwise checksclassified.currenthunger <= 0. - Parameters: None.
- Returns: boolean —
trueif starving,falseotherwise. - Error states: Returns
falseifclassifiedisnil(no data available).
Events & listeners
- Listens to:
onremove— firesself.ondetachclassifiedcallback to cleanly detach fromclassifiedobject when the entity is removed.