WX78 Common
Based on game build 722832 | Last updated: 2026-04-28
Overview
wx78_common.lua is a utility module that provides shared functions for WX-78 character systems. It is not a component or prefab file — instead, it exports a WX78Common table containing helper functions for upgrade module management, dizzy visual effects, heat/steam effects, socket handling, and visual modifications (mimic eyes, heart veins, trapper). The module is required by WX-78 prefab files and called during initialization to set up character-specific systems. Functions handle both master and client logic with appropriate TheWorld.ismastersim guards.
Usage example
local WX78Common = require("prefabs/wx78_common")
-- In prefab master_postinit:
WX78Common.Initialize_Master(inst)
WX78Common.SetupUpgradeModuleOwnerInstanceFunctions(inst)
-- In prefab common_postinit (client + master):
WX78Common.Initialize_Common(inst)
WX78Common.AddDizzyFx_Common(inst)
WX78Common.AddHeatSteamFx_Common(inst)
-- Query module count:
local spinModules = inst:GetModuleTypeCount("spin")
-- Set visual state:
WX78Common.SetMimicEyes(inst, true, doer)
WX78Common.SetHeartVeins(inst, true)
Dependencies & tags
External dependencies:
TUNING-- global balance constants for WX-78 values (max charge, dizzy thresholds, perish rates)CIRCUIT_BARS-- circuit bar type definitions for module slotsSOCKETQUALITY-- socket quality tier constants (LOW, MEDIUM, HIGH)ACTIONS-- action enum for upgrade module action validationPRNG_Uniform-- seeded random number generator for mimic eye placementMakeItemSocketable_Server-- server-side socketable item setupMakeInstSocketHolder_Client-- client-side socket holder setup
Components used:
upgrademoduleowner-- module slot management and charge level trackingwx78_classified-- backup body classified data fallbacktimer-- heat steam effect tick schedulingheater-- thermic temperature controlpreserver-- perish rate multiplier based on temperaturefrostybreather-- breath control for cold modulessocketholder-- socket position managementsocketable-- socket item name and quality queriessocket_shadow_harvester-- shadow socket low quality effectsocket_shadow_heart-- shadow socket medium quality effectsocket_shadow_mimicry-- shadow socket high quality effectuseabletargeteditem-- socket item targeting configurationlinkeditem-- owner user ID verification for socket permissionsupdatelooper-- dizzy effect update loop registrationSoundEmitter-- dizzy sound playback and parameter controlAnimState-- visual symbol show/hide for mimic eyes, veins, trapper
Tags:
possessable_chassis-- added when gestalt trapper socket is activeDECOR-- added to dizzy and steam effect entitiesNOCLICK-- added to effect entities to prevent interaction
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
DEPENDENCIES | table | --- | Table containing assets and prefabs arrays for WX-78 related entities. |
WX78_UPGRADE_MODULE_ACTIONS | table | --- | Action validation table for TOGGLEWXSCREECH and TOGGLEWXSHIELDING actions. |
DEFAULT_ZEROS_MODULEDATA | table | --- | Pre-initialized module data table with zeros for all circuit bars and slots. |
HEATSTEAM_TIMERNAME | constant (local) | "heatsteam_tick" | Timer name for heat steam effect periodic triggers. |
HEATSTEAM_TICKRATE | constant (local) | 5 | Seconds between heat steam effect ticks. |
Main functions
GetMaxEnergy(inst) (local)
- Description: Returns the maximum energy charge level for the WX-78 instance. Checks
upgrademoduleownerfirst, thenwx78_classifiedfallback, then returnsTUNING.WX78_INITIAL_MAXCHARGELEVELdefault. - Parameters:
inst-- entity instance - Returns: number maximum charge level
- Error states: None — gracefully falls back through all checks.
GetEnergyLevel(inst) (local)
- Description: Returns the current energy charge level. Checks
upgrademoduleowner.charge_level, thenwx78_classified.currentenergylevel, then returns0default. - Parameters:
inst-- entity instance - Returns: number current charge level
- Error states: None — gracefully falls back through all checks.
GetModulesData(inst) (local)
- Description: Returns module data table for all circuit bars. Populates with module
_netidvalues fromupgrademoduleowner, or callswx78_classified:GetModulesData(), or returnsDEFAULT_ZEROS_MODULEDATAfallback. Fills remaining slots with0to matchMAX_CIRCUIT_SLOTS. - Parameters:
inst-- entity instance - Returns: table module data indexed by bar type
- Error states: None — gracefully falls back through all checks.
CanUpgradeWithModule(inst, moduleent) (local)
- Description: Validates whether a module can be installed. Counts existing slots in use for the module's bar type and checks if
max_charge - slots_inuse >= 0. Falls back towx78_classified:CanUpgradeWithModule()if available. - Parameters:
inst-- entity instancemoduleent-- module entity or nil
- Returns: boolean
trueif module can be installed - Error states: Returns
falseifmoduleentis nil.
GetModuleTypeCount(inst, ...) (local)
- Description: Counts installed modules of specified type(s). Accepts variable arguments — if first arg is a table, iterates through it; otherwise treats first arg as module name and remaining args as additional names. Sums counts from
GetModuleTypeCount_Internal. - Parameters:
inst-- entity instance...-- module type name(s) as string args or single table arg
- Returns: number total count of matching modules
- Error states: None — handles nil module names gracefully via internal check.
UnplugModule(inst, moduletype, moduleindex) (local)
- Description: Removes a module from the specified bar type and slot index. Pushes
unplugmoduleevent with the module entity on master. Falls back towx78_classified:UnplugModule()if available. - Parameters:
inst-- entity instancemoduletype-- string bar type namemoduleindex-- integer slot index
- Returns: None
- Error states: None — silently returns if module not found.
CollectUpgradeModuleActions(inst, actions) (local)
- Description: Collects valid WX-78 upgrade module actions into the actions table. Checks
wx78_classified.inherentactionsand validates each action viaWX78_UPGRADE_MODULE_ACTIONSvalidfn. Used by entity action system. - Parameters:
inst-- entity instanceactions-- table to insert valid actions into
- Returns: None (modifies actions table in-place)
- Error states: None — silently returns if
wx78_classifiedorinherentactionsis nil.
SetupUpgradeModuleOwnerInstanceFunctions(inst) (local)
- Description: Attaches upgrade module helper functions directly to the instance. Sets
inst.GetMaxEnergy,inst.GetEnergyLevel,inst.GetModulesData,inst.CanUpgradeWithModule,inst.GetModuleTypeCount,inst.UnplugModule,inst.CollectUpgradeModuleActions. Called during prefab initialization. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
CreateDizzyFx() (local)
- Description: Creates a non-persistent dizzy visual effect entity. Adds
DECORandNOCLICKtags, sets up Transform, AnimState, and Follower components. Playsdizzy_meteranimation fromplayer_wx78_actionsbuild. - Parameters: None
- Returns: entity instance for dizzy effect
- Error states: None.
RemoveDizzyFx(inst) (local)
- Description: Removes the dizzy effect entity and clears the removal task reference. Called after dizzy level returns to 0 with a 60 tick delay.
- Parameters:
inst-- entity with_dizzyfxand_dizzyfxremovaltask - Returns: None
- Error states: Errors if
inst._dizzyfxis nil when called (should be guarded by caller).
OnDizzyLevel(inst) (local)
- Description: Updates dizzy visual effect based on
dizzylevelnetvar. Shows/hides individualdizzy1throughdizzy6symbols based on level. Creates effect entity if nil, or schedules removal task if level drops to 0. Client-only visual sync. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
SetDizzyLevel(inst, level) (local)
- Description: Sets the dizzy level netvar and triggers visual update on non-dedicated clients. Only updates if value differs from current. Master sets function, client listens for dirty event.
- Parameters:
inst-- entity instancelevel-- integer dizzy level (0-6)
- Returns: None
- Error states: None.
CalcMaxDizzy(inst) (local)
- Description: Calculates maximum dizzy threshold based on spin module count. Returns
TUNING.WX78_SPIN_TIME_TO_DIZZY_2if more than 1 spin module, otherwiseTUNING.WX78_SPIN_TIME_TO_DIZZY. - Parameters:
inst-- entity instance - Returns: number max dizzy threshold from TUNING
- Error states: None.
CalcRecoveredDizzy(inst) (local)
- Description: Calculates recovered dizzy amount based on time elapsed since last spin. Uses quadratic decay formula:
dizzy - k * k * maxwherek = (GetTime() - wx_spin_last) / TUNING.WX78_SPIN_DIZZY_RECOVER_TIME. Returns current dizzy and max values. - Parameters:
inst-- entity instance - Returns: number dizzy, number max
- Error states: None — returns nil if
wx_spin_buildupnot set.
SetDizzySound(inst, level, recovering) (local)
- Description: Controls dizzy sound loop playback and FMOD parameter. Remaps level to 0-0.6 range for
dizzinessparameter. PlaysWX_rework/dizzy/loopif not already playing. Kills sound when level is 0. - Parameters:
inst-- entity instancelevel-- number remapped sound levelrecovering-- boolean whether dizzy is recovering
- Returns: None
- Error states: None.
DizzyUpdate(inst) (local)
- Description: Periodic update function for dizzy effects. Registered via updatelooper component. If in dizzy state, sets max level. Otherwise calculates recovered dizzy and updates visuals/sound. Removes itself from updatelooper when dizzy reaches 0.
- Parameters:
inst-- entity instance - Returns: None
- Error states: None.
StartDizzyFx(inst) (local)
- Description: Starts the dizzy effect update loop. Adds
updateloopercomponent if missing, registersDizzyUpdatecallback, and triggers initial update. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
AddDizzyFx_Common(inst) (local)
- Description: Initializes dizzy effect system. Creates
dizzylevelnet_tinybyte netvar. On master, setsSetDizzyLevel,StartDizzyFx,CalcMaxDizzy,CalcRecoveredDizzyfunctions. On client, listens fordizzyleveldirtyevent. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
OnSteamFxTimeOut(inst) (local)
- Description: Removes steam effect entity from scene and pool after timeout. Clears from
_steam_fx_pooland nils pool if empty. - Parameters:
inst-- steam effect entity - Returns: None
- Error states: None.
OnSteamFxAnimOver(inst) (local)
- Description: Handles steam effect animation completion. Stops following, removes from scene, adds to
_steam_fx_poolfor reuse, and schedules 30 second timeout task. - Parameters:
inst-- steam effect entity - Returns: None
- Error states: None.
CreateSteamFx(frame) (local)
- Description: Creates or reuses a steam visual effect entity. Pulls from
_steam_fx_poolif available, otherwise creates new entity withwx_fxanim bank/build. Playssteam_<frame>animation and listens foranimoverevent. - Parameters:
frame-- integer animation frame number (1 or 2) - Returns: entity instance for steam effect
- Error states: None.
OnSteamFx_NoFaced(inst) (local)
- Description: Creates single steam effect for non-facing variant. Follows
headbasesymbol. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
OnSteamFx(inst) (local)
- Description: Creates three steam effects with different offsets for standard variant. All follow
headbasesymbol with varying z-offsets. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
AddHeatSteamFx_Common(inst, nofacings) (local)
- Description: Initializes heat steam effect system. Creates
steamfxnet_event. On non-dedicated clients, listens forwx78_common.steamfxevent and calls appropriate handler based onnofacingsflag. - Parameters:
inst-- entity instancenofacings-- boolean whether to use single or triple effect
- Returns: None
- Error states: None.
do_steam_fx(inst) (local)
- Description: Pushes steamfx net_event and starts/restarts heat steam timer. Uses event listener pattern to support
wx78_backupbodyreferences. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
OnTimerFinished(inst, data) (local)
- Description: Timer completion handler. Calls
do_steam_fxwhenHEATSTEAM_TIMERNAMEtimer completes. - Parameters:
inst-- entity instancedata-- table withnamefield
- Returns: None
- Error states: None.
AddTemperatureModuleLeaning(inst, leaning_change) (local)
- Description: Adjusts temperature module leaning value and updates heater, timer, and frostybreather components. Positive values enable exothermic heating with steam effects. Zero disables all. Negative values enable endothermic cooling with breath effects.
- Parameters:
inst-- entity instanceleaning_change-- number positive for warmer, negative for colder
- Returns: None
- Error states: None — assumes components exist (set during initialization).
ModuleBasedPreserverRateFn(inst, item) (local)
- Description: Perish rate multiplier function for preserver component. Returns
TUNING.WX78_PERISH_HOTRATEif leaning > 0,TUNING.WX78_PERISH_COLDRATEif leaning < 0, or1default. - Parameters:
inst-- entity instanceitem-- item entity (unused)
- Returns: number perish rate multiplier
- Error states: None.
GetThermicTemperatureFn(inst, observer) (local)
- Description: Temperature function for heater component. Returns
inst._temperature_modulelean * TUNING.WX78_HEATERTEMPPERMODULE. - Parameters:
inst-- entity instanceobserver-- observer entity (unused)
- Returns: number temperature offset
- Error states: None.
MakeItemSocketable(inst) (local)
- Description: Sets up socketable item behavior. Calls
MakeItemSocketable_Serverand configuresuseabletargeteditemto allow self-targeting without toggling useability. - Parameters:
inst-- item entity instance - Returns: None
- Error states: Errors if
useabletargeteditemcomponent is missing.
ShouldAllowSocketable_CLIENT(inst, item, doer) (local)
- Description: Client-side socket permission check. Allows if
inst == doeror iflinkeditemowner user ID matches doer's user ID. - Parameters:
inst-- socket holder entityitem-- socketable itemdoer-- player attempting to socket
- Returns: boolean
trueif socketing is allowed - Error states: None.
OnGetSocketable(inst, item, doer) (local)
- Description: Handles socket item insertion. For
socket_shadow, addssocket_shadow_harvesterat LOW quality,socket_shadow_heartat MEDIUM,socket_shadow_mimicryat HIGH. Forsocket_gestalttrapper, addspossessable_chassistag. Calls WX78Common visual setup functions. - Parameters:
inst-- socket holder entityitem-- socketable itemdoer-- player who socketed (can be nil)
- Returns: None
- Error states: None — checks component existence before access.
OnRemoveSocketable(inst, item) (local)
- Description: Handles socket item removal. Removes shadow components in reverse quality order (HIGH to LOW). Removes
possessable_chassistag for gestalt trapper. Calls WX78Common visual teardown functions. - Parameters:
inst-- socket holder entityitem-- socketable item being removed
- Returns: None
- Error states: None — checks component existence before removal.
ActivateSocketsIn(inst, socketposition, socketname) (local)
- Description: Activates a socket at the specified position by setting the socket name.
- Parameters:
inst-- socket holder entitysocketposition-- integer position indexsocketname-- string socket name or 0 to deactivate
- Returns: None
- Error states: None — silently returns if
socketholdermissing.
DeactivateSocketsIn(inst, socketposition) (local)
- Description: Deactivates a socket at the specified position by setting socket name to 0.
- Parameters:
inst-- socket holder entitysocketposition-- integer position index
- Returns: None
- Error states: None — silently returns if
socketholdermissing.
ShowMimicEyes(inst, doer) (local)
- Description: Randomly shows 1-3 mimic eye symbols using seeded PRNG based on world position. Ensures at least one eye is shown if random rolls fail. Uses
wx78_backupbody_inventoryanimstate owner if available. - Parameters:
inst-- entity instancedoer-- doer entity for position seed (optional)
- Returns: None
- Error states: None.
HideMimicEyes(inst) (local)
- Description: Hides all three mimic eye symbols. Uses
wx78_backupbody_inventoryanimstate owner if available. - Parameters:
inst-- entity instance - Returns: None
- Error states: None.
OnMimicEyesUpdated(inst, data) (local)
- Description: Event handler for mimic eyes update. Calls
ShowMimicEyesorHideMimicEyesbased ondata.enabled. - Parameters:
inst-- entity instancedata-- table withenabledanddoerfields
- Returns: None
- Error states: None.
SetMimicEyes(inst, enabled, doer) (local)
- Description: Sets mimic eyes enabled state and pushes
mimiceyes_updateevent. Skips event push for player entities (handled in SGwilson). Stores state ininst._has_mimiceyes. - Parameters:
inst-- entity instanceenabled-- booleandoer-- doer entity (optional)
- Returns: None
- Error states: None.
HasMimicEyes(inst) (local)
- Description: Returns whether mimic eyes are currently enabled. Checks
wx78_backupbody_inventoryif available. - Parameters:
inst-- entity instance - Returns: boolean
- Error states: None.
HideVeins(animstateowner) (local)
- Description: Hides shadow veins and mimic eyes, then removes itself from animover event. Used as event callback.
- Parameters:
animstateowner-- entity with AnimState - Returns: None
- Error states: None.
OnHeartVeinsChanged(inst, enabled) (local)
- Description: Event handler for heart veins state change. Shows/hides
shad_veinssymbol and plays pre/post animations if in idle state. Shows mimic eyes if enabled. - Parameters:
inst-- entity instanceenabled-- boolean
- Returns: None
- Error states: None.
SetHeartVeins(inst, enabled) (local)
- Description: Sets heart veins enabled state and pushes
heartveins_changedevent. Skips event push for player entities. Stores state ininst._has_heartveins. - Parameters:
inst-- entity instanceenabled-- boolean
- Returns: None
- Error states: None.
HasHeartVeins(inst) (local)
- Description: Returns whether heart veins are currently enabled. Checks
wx78_backupbody_inventoryif available. - Parameters:
inst-- entity instance - Returns: boolean
- Error states: None.
HideTrapper(animstateowner) (local)
- Description: Hides trapper symbol and removes itself from animover event. Used as event callback.
- Parameters:
animstateowner-- entity with AnimState - Returns: None
- Error states: None.
OnTrapperChanged(inst, enabled) (local)
- Description: Event handler for trapper state change. Shows/hides
trappersymbol and plays pre/post animations with ratchet sound if in idle state. - Parameters:
inst-- entity instanceenabled-- boolean
- Returns: None
- Error states: None.
SetTrapper(inst, enabled) (local)
- Description: Sets trapper enabled state and pushes
trapper_changedevent. Skips event push for player entities. Stores state ininst._has_trapper. - Returns: None
- Error states: None.
HasTrapper(inst) (local)
- Description: Returns whether trapper is currently enabled. Checks
wx78_backupbody_inventoryif available. - Parameters:
inst-- entity instance - Returns: boolean
- Error states: None.
OnWxSpinActions(inst, actionsdata) (local)
- Description: Event handler for spin actions. Prioritizes ATTACK action from actionsdata array and stores action, target, and time in instance memory for spin tracking.
- Parameters:
inst-- entity instanceactionsdata-- array of action data tables
- Returns: None
- Error states: None.
CanSpinUsingItem(item) (local)
- Description: Validates whether an item can be used for spinning. On master, checks
toolcomponent for CHOP or MINE actions. On client, checks forCHOP_toolorMINE_tooltags. Assigns appropriate function toWX78Common.CanSpinUsingItemon first call. - Parameters:
item-- item entity or nil - Returns: boolean
- Error states: None.
Initialize_Common(inst) (local)
- Description: Client-side initialization (runs on both client and master). Sets up socket holder client functions and hides all WX-78 visual symbols (veins, mimic eyes, trapper, gestalt states).
- Parameters:
inst-- entity instance - Returns: None
- Error states: None.
Initialize_Master(inst) (local)
- Description: Master-only initialization. Sets
_temperature_moduleleanto 0, adds and configuresheaterandpreservercomponents, listens fortimerdoneevent, sets socket holder callbacks, and listens for visual state events (mimiceyes, heartveins, trapper) or spin actions for players. - Parameters:
inst-- entity instance - Returns: None
- Error states: None — assumes components are added by calling prefab.
Events & listeners
Listens to:
dizzyleveldirty(client only) — triggers OnDizzyLevel; updates dizzy visual effect symbolswx78_common.steamfx(client only) — triggers OnSteamFx or OnSteamFx_NoFaced; creates steam visual effectstimerdone(master only) — triggers OnTimerFinished; continues heat steam effect ticksmimiceyes_update(master only, non-player) — triggers OnMimicEyesUpdated; shows/hides mimic eye symbolsheartveins_changed(master only, non-player) — triggers OnHeartVeinsChanged; shows/hides shadow veinstrapper_changed(master only, non-player) — triggers OnTrapperChanged; shows/hides trapper symbolms_wx_spinactions(master only, player) — triggers OnWxSpinActions; tracks spin attack actionsanimover(effect entities) — triggers HideVeins, HideTrapper, OnSteamFxAnimOver; cleanup after animations
Pushes:
unplugmodule— data: module entity; fired when module is unpluggedmimiceyes_update— data:{enabled = boolean, doer = entity}; fired when mimic eyes state changesheartveins_changed— data: boolean enabled; fired when heart veins state changestrapper_changed— data: boolean enabled; fired when trapper state changes