Skip to main content

Wx78

Based on game build 714014 | Last updated: 2026-03-07

Overview

wx78.lua defines the WX-78 player character prefab, implementing robot-specific mechanics beyond standard player functionality. It leverages the Entity Component System to integrate tightly with components like upgrademoduleowner, batteryuser, heater, moisture, freezable, and playerlightningtarget. Core responsibilities include energy (charge) regeneration and consumption (e.g., from hunger or moisture), temperature leaning via installed modules, moisture tracking and spark/damage effects, forced night vision handling, and Lightning immunity and charge gain on strike. It also handles custom saving and loading of health, sanity, and hunger to accommodate dynamic max values from modules.

Usage example

-- Installing a WX-78 module that increases ambient heat
local module = SpawnPrefab("wx78module_heat")
if inst.CanUpgradeWithModule(module) then
inst.components.upgrademoduleowner:AddModule(module)
end

-- Increasing WX-78's temperature leaning for heating
inst:AddTemperatureModuleLeaning(1) -- +1 module lean towards heat

-- Enabling forced night vision
inst:SetForcedNightVision(true)

Dependencies & tags

Components used: batteryuser, dataanalyzer, eater, edible, finiteuses, foodaffinity, freezable, frostybreather, grue, health, heater, hunger, inventory, inventoryitem, moisture, playerlightningtarget, playervision, preserver, propagator, sanity, sleepingbaguser, talker, timer, upgrademodule, upgrademoduleowner.

Tags: electricdamageimmune, batteryuser, chessfriend, HASHEATER, soulless, upgrademoduleowner, quagmire_shopper (Quagmire mode only).

Properties

PropertyTypeDefault ValueDescription
_gears_eatennumber0Count of gears consumed; affects gear drop amount on death.
_chip_inusenumber0Total number of module slots currently in use by installed modules.
_moisture_stepsnumber0Accumulated steps for moisture tracking; triggers sparks and damage.
_temperature_moduleleannumber0Temperature leaning direction: >0 for hot, <0 for cold, 0 for neutral.
_num_frostybreath_modulesnumber0Count of frosty breath modules; used to override environmental breath requirements.
_forced_nightvisionnet_boolfalseNetworked flag indicating whether forced night vision is active.

Main functions

AddTemperatureModuleLeaning(inst, leaning_change)

  • Description: Adjusts WX-78's temperature leaning by a specified amount. Adjusts heater thermics, starts/stops steam FX timer, and toggles frosty breath force state.
  • Parameters: leaning_change (number) - Positive to lean hot, negative to lean cold.
  • Returns: Nothing.
  • Error states: No explicit error states; modifies global state variables _temperature_modulelean, _num_frostybreath_modules, and interacts with components.

SetForcedNightVision(inst, nightvision_on)

  • Description: Enables or disables WX-78's forced night vision by pushing/popping a priority stack, and manages grue immunity via a dedicated source.
  • Parameters: nightvision_on (boolean) - Whether to enable forced night vision.
  • Returns: Nothing.

OnChargeFromBattery(inst, battery)

  • Description: Called when a battery is used on WX-78. Heals slight health, reduces sanity slightly, adds 1 charge, triggers electrocute stategraph event, and returns success/failure.
  • Parameters: battery (entity) - The battery entity being used.
  • Returns: true on success; false, "CHARGE_FULL" if charge is already full.

OnLightningStrike(inst)

  • Description: Handles lightning strike events. If insulated, nothing happens. Otherwise, large health and sanity damage occur, but 1 charge is gained.
  • Parameters: None.
  • Returns: Nothing.

OnWetnessChanged(inst, data)

  • Description: Responds to moisture level changes. Triggers moisture tracking if above minimum acceptable threshold, triggers ice creation and stops tracking if icy and a cold module is present.
  • Parameters: data (table) - Contains old and new moisture levels.
  • Returns: Nothing.

OnEat(inst, food)

  • Description: Handles food consumption. Increases _gears_eaten count for gears, and adds charge based on predefined WX78_CHARGING_FOODS.
  • Parameters: food (entity) - The food entity being eaten.
  • Returns: Nothing.

OnFrozen(inst)

  • Description: Handles freezing events. Generates a spark, and deducts charge if not empty.
  • Parameters: None.
  • Returns: Nothing.

OnUpgradeModuleAdded(inst, moduleent)

  • Description: Callback invoked when a module is added. Updates slot usage, pushes dirty event for UI, and replicates module index to client.
  • Parameters: moduleent (entity) - The added module entity.
  • Returns: Nothing.

OnUpgradeModuleRemoved(inst, moduleent)

  • Description: Callback invoked when a module is removed. Updates slot usage, and returns the module to inventory if not about to be destroyed.
  • Parameters: moduleent (entity) - The removed module entity.
  • Returns: Nothing.

CanUseUpgradeModule(inst, moduleent)

  • Description: Validates whether WX-78 can accept the given module based on available slot count.
  • Parameters: moduleent (entity) - The module to install.
  • Returns: true if installable; false, "NOTENOUGHSLOTS" otherwise.

OnSave(inst, data)

  • Description: Saves WX-78-specific persistent data (gears eaten, health, sanity, hunger) to the save table, to preserve dynamically modified max values.
  • Parameters: data (table) - The save data table to populate.
  • Returns: Nothing.

OnLoad(inst, data)

  • Description: Loads WX-78-specific persistent data (gears eaten, health, sanity, hunger) post-component initialization.
  • Parameters: data (table) - The loaded save data table.
  • Returns: Nothing.

Events & listeners

  • Listens to:
    • playeractivated / playerdeactivated - Manages night vision and force dry callbacks.
    • energylevelupdate - Handles charge change announcements and regen timer reset.
    • ms_respawnedfromghost, ms_becameghost, death, ms_playerreroll - Handles state transitions (e.g., stop moisture/hunger timers).
    • moisturedelta - Handles moisture-driven ice generation and tracking.
    • startstarving, stopstarving - Controls hunger-related charge drain timer.
    • timerdone - Routes timer completions to handler functions.
    • forced_nightvision_dirty - Updates forced night vision on change.
  • Pushes:
    • upgrademodulesdirty, upgrademoduleowner_popallmodules, wx78_spark, do_robot_spark, lightningdamageavoided.
    • electrocute (immediate) on battery charge.
    • moisturedelta for UI sync (client-side only via PushEventImmediate).