Combat Replica
Based on game build 722832 | Last updated: 2026-04-18
Overview
Combat Replica is the client-side counterpart to the server-side combat component. It synchronizes combat-related state (target, attack range, panic state, cooldowns) across the network using net variables and classified player data. This component allows clients to perform combat validation locally while deferring authoritative decisions to the server. It mirrors most functions from combat but uses replica components and network-synchronized values instead of direct server state.
Usage example
-- Access the combat replica on a player entity
local combat_replica = player.replica.combat
-- Set and get combat target
combat_replica:SetTarget(target_entity)
local current_target = combat_replica:GetTarget()
-- Check if entity can attack
local can_attack = combat_replica:CanAttack(target_entity)
-- Get attack range with equipped weapon
local range = combat_replica:GetAttackRangeWithWeapon()
-- Check cooldown state
local in_cooldown = combat_replica:InCooldown()
Dependencies & tags
External dependencies:
TheWorld-- checksismastersimfor server/client differentiationTheNet-- checksGetPVPEnabled()for player-versus-player rulesGetTime()-- used for cooldown timing calculationsdistsq()-- 3D distance squared calculations for range checks
Components used:
combat-- server-side component referenced when available on master siminventoryreplica -- accesses equipped weapon viareplica.inventory:GetEquippedItem()riderreplica -- checks if entity is riding a mountfollowerreplica -- determines leader/follower relationships for ally checkssanityreplica -- checks sanity state for shadow creature targeting rulesclassified-- player classified data for network-optimized state storage
Tags:
busy-- checked to prevent attacks during busy stateshit-- allows attacks even when busy if hit state is activeextinguisher-- checked for fire extinguishing capabilityrangedlighter-- checked for ranged lighting capabilitycanlight-- target must have this tag to be lightablefire,burnt,smolder-- fire state tags for target validationweapon,projectile,rangedweapon-- weapon type identificationINLIMBO,notarget,debugnoattack-- exclusion tags for targetinginvisible,spawnprotection-- protection state tagsshadow,playerghost,crazy-- sanity and ghost state tagsalwayshostile,companion,domesticated-- ally relationship tagspeacefulmount,propweapon,noplayertarget-- special combat rule tagsflight,noattack,nightmarecreature,shadowcreature,locomotor-- creature state tags
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | entity | --- | The entity instance that owns this component. |
_target | net_entity | --- | Network-synchronized target entity reference. |
_ispanic | net_bool | --- | Network-synchronized panic state flag. |
_attackrange | net_float | --- | Network-synchronized base attack range value. |
_laststartattacktime | number | nil | Timestamp of last attack start for cooldown calculation. |
classified | table | nil | Player classified data container for network optimization. |
ondetachclassified | function | nil | Callback function triggered when classified data detaches. |
Main functions
AttachClassified(classified)
- Description: Attaches player classified data container and sets up cleanup listener for when classified data is removed. Resets attack cooldown timer.
- Parameters:
classified-- player classified data table frominst.player_classified - Returns: None
- Error states: None
DetachClassified()
- Description: Detaches player classified data container and clears related references. Resets attack cooldown timer.
- Parameters: None
- Returns: None
- Error states: None
SetTarget(target)
- Description: Sets the combat target entity via network-synchronized net_entity variable.
- Parameters:
target-- entity instance to set as target - Returns: None
- Error states: None
GetTarget()
- Description: Returns the current combat target entity from network-synchronized variable.
- Parameters: None
- Returns: Entity instance or
nilif no target set
SetLastTarget(target)
- Description: Sets the last combat target in classified data for recent target tracking.
- Parameters:
target-- entity instance to record as last target - Returns: None
- Error states: None
IsRecentTarget(target)
- Description: Checks if target is the current or recently attacked target. Falls back to server combat component if available, otherwise checks classified data or current target.
- Parameters:
target-- entity instance to check - Returns:
trueif target is recent,falseotherwise - Error states: None
SetIsPanic(ispanic)
- Description: Sets the panic state via network-synchronized net_bool variable.
- Parameters:
ispanic-- boolean panic state - Returns: None
- Error states: None
SetAttackRange(attackrange)
- Description: Sets the base attack range via network-synchronized net_float variable.
- Parameters:
attackrange-- number representing attack range in units - Returns: None
- Error states: None
GetAttackRangeWithWeapon()
- Description: Returns total attack range including weapon bonus. Falls back to server combat component if available, otherwise calculates from replica data.
- Parameters: None
- Returns: Number representing total attack range, or
0if no weapon - Error states: None
GetWeaponAttackRange()
- Description: Returns only the weapon's attack range bonus from replica inventory data.
- Parameters: None
- Returns: Number representing weapon attack range bonus, or
0if no weapon - Error states: None
GetWeapon()
- Description: Returns the currently equipped weapon entity from replica inventory. Handles projectile and ranged weapon special cases, excludes weapons when riding unless ranged.
- Parameters: None
- Returns: Weapon entity instance or
nilif no valid weapon equipped - Error states: None
SetMinAttackPeriod(minattackperiod)
- Description: Sets the minimum attack period (cooldown) in classified data.
- Parameters:
minattackperiod-- number representing cooldown duration in seconds - Returns: None
- Error states: None
MinAttackPeriod()
- Description: Returns the minimum attack period (cooldown duration). Falls back to server combat component if available, otherwise reads from classified data.
- Parameters: None
- Returns: Number representing cooldown duration in seconds, or
0if unavailable - Error states: None
SetCanAttack(canattack)
- Description: Sets the can-attack state flag in classified data.
- Parameters:
canattack-- boolean indicating if entity can attack - Returns: None
- Error states: None
StartAttack()
- Description: Initiates an attack and records the start time for cooldown tracking. Falls back to server combat component if available.
- Parameters: None
- Returns: None
- Error states: None
CancelAttack()
- Description: Cancels the current attack and clears the attack start time. Falls back to server combat component if available.
- Parameters: None
- Returns: None
- Error states: None
InCooldown()
- Description: Checks if the entity is currently in attack cooldown period. Falls back to server combat component if available, otherwise calculates from local timestamp.
- Parameters: None
- Returns:
trueif in cooldown,falseotherwise - Error states: None
CanAttack(target)
- Description: Validates if entity can attack the specified target. Checks target validity, attack permission, cooldown state, busy state, and range. Falls back to server combat component if available. Includes position error compensation (
-.5) for client prediction. - Parameters:
target-- entity instance to validate as attack target - Returns:
trueif attack is valid,falseotherwise. (Note: Second return value for invalid target only applies to server combat component, not client replica.) - Error states: None
LocomotorCanAttack(reached_dest, target)
- Description: Validates attack capability during locomotion. Checks target validity, attack permission, busy state, and range. Performs void ground testing for non-ranged weapons when player is within range
> 2. Returns three values for reached destination, validity, and cooldown state. - Parameters:
reached_dest-- boolean indicating if destination was reached (optional, calculated if nil)target-- entity instance to validate as attack target
- Returns: Three values:
reached_dest(boolean),not valid(boolean),in cooldown(boolean) - Error states: None
CanExtinguishTarget(target, weapon)
- Description: Checks if entity can extinguish the target's fire. Falls back to server combat component if available, otherwise checks extinguisher tags and fire state tags.
- Parameters:
target-- entity instance to checkweapon-- weapon entity instance (optional)
- Returns:
trueif target can be extinguished,falseotherwise - Error states: None
CanLightTarget(target, weapon)
- Description: Checks if entity can light the target on fire. Falls back to server combat component if available, otherwise checks rangedlighter tag, canlight tag, and fire/burnt state exclusion.
- Parameters:
target-- entity instance to checkweapon-- weapon entity instance (optional)
- Returns:
trueif target can be lit,falseotherwise - Error states: None
CanHitTarget(target)
- Description: Validates if entity can hit the specified target. Checks target validity, limbo state, extinguish/light/attack capability, and range with position error compensation (
0.5). Falls back to server combat component if available. - Parameters:
target-- entity instance to validate as hit target - Returns:
trueif target can be hit,falseotherwise - Error states: None
IsValidTarget(target)
- Description: Comprehensive target validation checking entity validity, visibility, self-targeting, and multiple exclusion rules including shadow creatures, player ghosts, sanity state, PVP settings, and height restrictions.
- Parameters:
target-- entity instance to validate - Returns:
trueif target is valid,falseotherwise - Error states: None
CanTarget(target)
- Description: Full targeting validation combining
IsValidTarget()with panic state, exclusion tags, invisible state, combat reciprocity, and mount riding rules. - Parameters:
target-- entity instance to validate for targeting - Returns:
trueif target can be targeted,falseotherwise - Error states: None
CanBeAlly(guy)
- Description: Determines if another entity should be considered an ally based on leader/follower relationships, player alignment, domestication state, bedazzled state, and PVP settings.
- Parameters:
guy-- entity instance to check for ally status - Returns:
trueif entity can be ally,falseotherwise - Error states: None
IsAlly(guy)
- Description: Checks if entity is actually an ally by verifying
CanBeAlly()and ensuring the entity is not currently targeting this entity. - Parameters:
guy-- entity instance to check for ally status - Returns:
trueif entity is ally,falseotherwise - Error states: None
TargetHasFriendlyLeader(target)
- Description: Deprecated - Use
IsAlly()orCanBeAlly()instead. Checks if target shares a friendly leader relationship. Will assert on dev branch. - Parameters:
target-- entity instance to check - Returns:
trueif target has friendly leader,falseotherwise - Error states: Asserts on dev branch with message "Deprecated! Use IsAlly/CanBeAlly."
CanBeAttacked(attacker)
- Description: Validates if this entity can be attacked by the specified attacker. Checks ghost state, flight state, invisibility, player targeting restrictions, PVP rules, follower relationships, sanity state, and shadow creature rules.
- Parameters:
attacker-- entity instance attempting to attack (optional) - Returns:
trueif entity can be attacked,falseotherwise - Error states: None
Events & listeners
- Listens to:
onremove- triggersDetachClassified()when classified data is removed from entity