Wx78 Abilitycooldown
Based on game build 722832 | Last updated: 2026-04-28
Overview
wx78_abilitycooldown.lua registers an invisible, non-persisting prefab entity used to track individual ability cooldowns for the WX-78 character. The prefab uses network variables (net_hash, net_byte, net_ushortint) to synchronize cooldown state between server and clients. On the server, it runs wall update ticks via the updatelooper component to decrement cooldown progress; on clients, it listens for dirty events to update local preview state. The prefab is classified and hidden from normal entity queries.
Usage example
-- Spawn a cooldown tracker (typically done internally by WX-78 components):
local cooldown = SpawnPrefab("wx78_abilitycooldown")
-- Server: Initialize with ability name and duration in seconds
if TheWorld.ismastersim then
cooldown:InitAbilityCooldown("overcharge", 10)
end
-- Read cooldown state (both client and server):
local name = cooldown:GetAbilityName()
local duration = cooldown:GetLength()
local percent = cooldown:GetPercent()
-- Client receives updates via namedirty/pctdirty events automatically
Dependencies & tags
Components used:
updatelooper-- registersOnWallUpdatecallback for periodic cooldown decrement
Tags:
CLASSIFIED-- added infn(); hides entity from normal queries and targeting
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
pct | number | 1 | Local preview state for cooldown percentage (0-1). Reverted on server sync. |
syncdelay | number | 1 | (master only) Delay counter before next network sync; decrements each wall update. |
_name | net_hash | --- | Networked ability name string. Dirty event: namedirty. |
_pct | net_byte | 180 | Networked cooldown percentage scaled to 0-180 range. Dirty event: pctdirty. |
_len | net_ushortint | --- | Networked cooldown duration in deciseconds (duration * 10). No dirty event. |
SYNC_INTERVAL | constant (local) | 1 | Default sync delay interval in seconds between network updates. |
Main functions
fn()
- Description: Prefab constructor. Creates invisible classified entity, initializes network variables, attaches updatelooper component, and sets up master/client split logic. Server sets up sync delay and server interface methods; client registers dirty event listeners. Returns
instfor prefab framework. - Parameters: None
- Returns: entity instance
- Error states: None — runs on every host with appropriate branching.
GetAbilityName()
- Description: Returns the ability name stored in the
_namenetvar. Safe to call on both client and server. - Parameters: None
- Returns: string ability name from
inst._name:value() - Error states: None.
GetLength()
- Description: Returns the cooldown duration in seconds. Reads
_lennetvar (stored as deciseconds) and divides by 10. - Parameters: None
- Returns: number duration in seconds
- Error states: None.
GetPercent()
- Description: Returns the current cooldown progress as a percentage (0-1 range). Reads local
inst.pctvalue. - Parameters: None
- Returns: number between 0 and 1
- Error states: None.
SetPercent(percent, overtime)
- Description: Updates cooldown percentage with network sync. Behavior depends on percent value:
percent <= 0— removes entity on master; sets local state to 0 on clientpercent >= 1— caps at 1, sets_pctto 180, resetssyncdelayif present0 < percent < 1— setsinst.pct, scales to 0-180 range for_pct, resetssyncdelayunlessovertimeis true
- Parameters:
percent-- number cooldown percentage (0-1 range)overtime-- boolean if true, usesset_localto avoid network sync
- Returns: nil
- Error states: None — handles all percent ranges with guards.
InitAbilityCooldown(abilityname, duration)
- Description: (master only) Initializes a new cooldown with the given ability name and duration. Sets
_nameand_lennetvars, clamping duration to 0-65535 deciseconds range. - Parameters:
abilityname-- string ability identifierduration-- number duration in seconds (converted to deciseconds internally)
- Returns: nil
- Error states: Errors if called on client without master guard (source does not guard this function).
RestartAbilityCooldown(duration)
- Description: (master only) Resets an existing cooldown with a new duration. Updates
_lennetvar and sets percent to 1 (full cooldown). - Parameters:
duration-- number new duration in seconds - Returns: nil
- Error states: Errors if called on client without master guard (source does not guard this function).
OnNameDirty(inst) (local)
- Description: Client-only event handler for
namedirtyevent. When the ability name changes on the server, registers this cooldown entity with the player'swx78_abilitycooldownscomponent. - Parameters:
inst-- this cooldown entity - Returns: nil
- Error states: None — guards against missing
ThePlayeror missing component.
OnPctDirty(inst) (local)
- Description: Client-only event handler for
pctdirtyevent. Updates localinst.pctfrom the networked_pctvalue (scaled from 0-180 range back to 0-1). - Parameters:
inst-- this cooldown entity - Returns: nil
- Error states: None.
OnWallUpdate(inst, dt) (local)
- Description: Wall update callback registered with updatelooper. Decrements cooldown percentage over time based on elapsed time and cooldown length. Fires every wall tick. Logic:
- Scales
dtby time scale - If
pct > 0and_len <= 0, sets percent to 0 (removes entity on master) - Otherwise decrements
pctbydt / (length in seconds), passingovertime=truewhensyncdelayreaches 0 - Decrements
syncdelaycounter each tick
- Scales
- Parameters:
inst-- this cooldown entitydt-- number delta time since last update
- Returns: nil
- Error states: None.
Events & listeners
Listens to (client only):
namedirty— triggersOnNameDirty; registers cooldown with player'swx78_abilitycooldownscomponent. Data: nonepctdirty— triggersOnPctDirty; updates localpctfrom networked_pctvalue. Data: none
Pushes (via netvar setters):
namedirty— fired when_name:set()is called on masterpctdirty— fired when_pct:set()is called on master