Combat Replica
Based on game build 714014 | Last updated: 2026-03-03
Overview
Combat Replica is a client-side component that mirrors and exposes key combat functionality from the server-side combat component. It synchronizes state like target, panic mode, attack range, and attack cooldown across the network using net variables (net_entity, net_bool, net_float). It is primarily used on the client to evaluate combat decisions (e.g., target validity, attack readiness) in a prediction-safe manner, especially for player entities, while deferring authoritative logic to the server via the corresponding combat component when present.
It integrates closely with the combat, follower, inventory, rider, and sanity components, and relies on replicated data (replica.*) to reason about world state without direct server queries.
Usage example
-- Typically added automatically to player entities; manual usage is rare.
local inst = ThePlayer
if inst.replica.combat ~= nil then
-- Set and retrieve target
inst.replica.combat:SetTarget(target)
local target = inst.replica.combat:GetTarget()
-- Check attack readiness
if inst.replica.combat:CanAttack(target) then
inst.replica.combat:StartAttack()
end
-- Get effective attack range, accounting for weapon
local range = inst.replica.combat:GetAttackRangeWithWeapon()
end
Dependencies & tags
Components used: combat, follower, inventory, rider, sanity, inventoryitem
Tags: Checks INLIMBO, notarget, debugnoattack, invisible, noattack, noplayertarget, playerghost, flight, shadowcreature, nightmarecreature, spawner, domesticated, companion, peacefulmount, crazy, propweapon, extinguisher, rangedlighter, canlight, fire, smolder, burnt, canlight, spawnprotection, player, playerghost. No tags are added or removed by this component.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_target | net_entity | nil | Network-replicated current combat target. |
_ispanic | net_bool | false | Whether the entity is in panic mode. |
_attackrange | net_float | 0 | Base attack range (server-authoritative). |
_laststartattacktime | number or nil | nil | Timestamp of last attack start (client-side, for cooldown estimation). |
classified | PlayerClassified or nil | nil | Server-side combat classification data, attached via AttachClassified. |
Main functions
SetTarget(target)
- Description: Sets the network-replicated current combat target.
- Parameters:
target(Entity ornil) — the entity to target. - Returns: Nothing.
- Error states: None. Unsafe if used without server consensus (should only be called via server-authoritative
combatcomponent on the server, but this replica ensures sync).
GetTarget()
- Description: Returns the network-replicated current combat target.
- Parameters: None.
- Returns: Entity or
nil.
SetLastTarget(target)
- Description: Sets the last combat target on the
PlayerClassified(for recent-target tracking). - Parameters:
target(Entity ornil) — the last entity targeted. - Returns: Nothing.
IsRecentTarget(target)
- Description: Determines if
targetis the current target or the last target (within memory window). Used for AI behavior consistency. - Parameters:
target(Entity ornil) — entity to check. - Returns:
boolean—trueiftargetis recent. - Error states: If no
combatcomponent exists, falls back toclassified.lastcombattargetor_target.
SetIsPanic(ispanic)
- Description: Updates the network-replicated panic state.
- Parameters:
ispanic(boolean) — whether the entity is panicked. - Returns: Nothing.
SetAttackRange(attackrange)
- Description: Updates the network-replicated base attack range.
- Parameters:
attackrange(number) — new attack range value. - Returns: Nothing.
GetAttackRangeWithWeapon()
- Description: Returns the current effective attack range, including the weapon's range (if any), client-side.
- Parameters: None.
- Returns: number — effective range, clamped to
>= 0. - Error states: Falls back to client-side weapon lookup if
combatcomponent is absent.
GetWeaponAttackRange()
- Description: Returns the range of the currently equipped weapon only (0 if none or invalid).
- Parameters: None.
- Returns: number — weapon range, or
0.
GetWeapon()
- Description: Returns the current equipped weapon on the client (replica-based).
- Parameters: None.
- Returns:
ReplicaInventoryItemornil— the weapon replica, ornilif none qualifies. - Error states: Skips weapons if mounted (unless ranged). Checks
weapon,projectile,rangedweapon, andcomplexprojectiletags.
SetMinAttackPeriod(minattackperiod)
- Description: Sets the minimum attack period on the
PlayerClassified. - Parameters:
minattackperiod(number) — attack cooldown in seconds. - Returns: Nothing.
MinAttackPeriod()
- Description: Returns the minimum attack period (server if available, otherwise client-side estimate).
- Parameters: None.
- Returns: number — attack period, or
0if unavailable.
SetCanAttack(canattack)
- Description: Updates the
canattackflag onPlayerClassified. - Parameters:
canattack(boolean) — whether the entity can currently attack. - Returns: Nothing.
StartAttack()
- Description: Initiates an attack, updating server or client-side cooldown timestamp.
- Parameters: None.
- Returns: Nothing.
- Error states: If
combatcomponent is present, defers to server-side logic; otherwise, sets_laststartattacktimeto current time.
CancelAttack()
- Description: Cancels an ongoing attack attempt, clearing the client cooldown timestamp.
- Parameters: None.
- Returns: Nothing.
- Error states: Delegates to
combatif present; otherwise, sets_laststartattacktimetonil.
InCooldown()
- Description: Checks if the entity is in the attack cooldown window.
- Parameters: None.
- Returns:
boolean—trueif cooldown is active. - Error states: Falls back to
combator client-side timestamp andminattackperiod.
CanAttack(target)
- Description: Evaluates if the entity can attack
target, considering range, target validity, panic, busy state, and cooldown. Used client-side for prediction. - Parameters:
target(Entity ornil) — target to evaluate. - Returns:
boolean, boolean— first return istrueif attack is possible, second istrueif target is invalid (for AI rethinking). - Error states: Range check uses prediction-aware tolerance (
-.5units). Does not check"hit"state tag on client.
LocomotorCanAttack(reached_dest, target)
- Description: Determines if the entity can initiate an attack after moving, factoring in path completion, target validity, and weapon type (e.g., melee vs. ranged). Used by AI movement logic.
- Parameters:
reached_dest(boolean ornil) — whether movement goal has been reached.target(Entity ornil) — target to evaluate.
- Returns:
boolean, boolean, boolean—(reached_dest, can_not_attack, in_cooldown). - Error states: Adjusts
reached_destfor ground validity in melee attacks for players. Only checks"hit"state tag;"busy"alone may not block.
CanExtinguishTarget(target, weapon)
- Description: Checks if
targetcan be extinguished with the given or equipped weapon. - Parameters:
target(Entity) — target entity.weapon(ReplicaInventoryItemornil) — weapon to use.
- Returns:
boolean—trueif target issmolder/fireand weapon hasextinguishertag or entity hasextinguisher. - Error states: Does not delegate to server
combatcomponent in this branch; implements simplified client-side logic.
CanLightTarget(target, weapon)
- Description: Checks if
targetcan be lit on fire with the given or equipped weapon. - Parameters:
target(Entity) — target entity.weapon(ReplicaInventoryItemornil) — weapon to use.
- Returns:
boolean—trueif target iscanlight, notfire/burnt, and weapon hasrangedlighter. - Error states: Does not delegate to server
combatcomponent in this branch; implements simplified client-side logic.
CanHitTarget(target)
- Description: Determines if
targetis within range to be hit, considering valid action type (attack/ light/exinguish). - Parameters:
target(Entity ornil) — target to check. - Returns:
boolean—trueif within range and type-allowed. - Error states: Uses prediction-aware tolerance (
0.5units). ExcludesINLIMBOtargets.
IsValidTarget(target)
- Description: Performs a comprehensive validity check for a combat target, including entity visibility, distance, tags, and PVP rules.
- Parameters:
target(Entity ornil) — target to validate. - Returns:
boolean—trueif target is valid. - Error states: Enforces
shadowcreature/nightmarecreaturerestrictions andnoplayertargetrules. Validates PVP and follower targeting logic.
CanTarget(target)
- Description: Combines
IsValidTargetwith additional situational checks (panic, flags likenotarget, riding constraints). - Parameters:
target(Entity) — target to validate. - Returns:
boolean—trueif target is usable. - Error states: Enforces rider mount restrictions (e.g., peaceful mounts block melee). Ignores
invisibletargets unless flagged for tracking.
CanBeAlly(guy)
- Description: Determines if
guycan be considered an ally (friend or neutral), based on leadership and group membership. - Parameters:
guy(Entity) — entity to evaluate. - Returns:
boolean—trueif alliance is possible. - Error states: Enforces
alwayshostile, self-check, leader/follower relationships, andcompanionstatus for players.
IsAlly(guy)
- Description: Determines if
guyis currently not an enemy, assuming they could be an ally. - Parameters:
guy(Entity) — entity to evaluate. - Returns:
boolean—trueif not attacking the entity. - Error states: Depends on
guy.replica.combat:GetTarget().
TargetHasFriendlyLeader(target)
- Description: Checks if
targetis protected due to having a leader that the entity respects (e.g., same leader, friendly player leader, or domesticated). - Parameters:
target(Entity) — target to evaluate. - Returns:
boolean—trueif target is protected. - Error states: Accounts for followers and leaders via
followerreplica.
CanBeAttacked(attacker)
- Description: Determines if this entity can be attacked by
attacker, considering state tags, sanity, PVP, and shadow creature logic. - Parameters:
attacker(Entity ornil) — potential attacker. - Returns:
boolean—trueif attack is allowed. - Error states: Returns
falsefornoattack,invisible,playerghost,flight. Enforces PVP rules and follower targeting restrictions. Applies shadow creature visibility rules strictly.
Events & listeners
- Listens to:
onremove— triggered onclassifiedto detach (viaondetachclassified). - Pushes: None directly. Does not fire events.