Parryweapon
Based on game build 714014 | Last updated: 2026-03-03
Overview
The Parryweapon component enables a weapon entity to participate in the parry mechanic during combat. It determines whether an incoming attack can be parried by checking the relative angles between the defender (doer) and the attacker, as well as excluding invalid stimuli (e.g., ground spikes or stun damage). It supports optional callback hooks for pre-parry and parry events, primarily intended for stategraph animation synchronization but not required for core logic.
Usage example
local weapon = CreateEntity()
weapon:AddComponent("parryweapon")
weapon.components.parryweapon:SetParryArc(90)
weapon.components.parryweapon:SetOnParryFn(function(inst, doer, attacker, damage)
print("Weapon parried an attack from", attacker:GetName())
end)
Dependencies & tags
Components used: locomotor (via attacker.components.locomotor in TryParry)
Tags: Adds and removes the "parryweapon" tag on attach/detach.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
arc | number | 178 | Total angular width (in degrees) within which a parry is possible. |
onpreparryfn | function? | nil | Optional callback invoked before parry resolution. Signature: fn(inst, doer). |
onparryfn | function? | nil | Optional callback invoked upon successful parry. Signature: fn(inst, doer, attacker, damage). |
Main functions
SetParryArc(arc)
- Description: Sets the angular width of the parry arc. The effective parry zone extends ±
arc/2degrees from the defender's facing direction. - Parameters:
arc(number) — total angular threshold in degrees. - Returns: Nothing.
SetOnPreParryFn(fn)
- Description: Registers a callback to be invoked when parry preparation begins (e.g., before animation triggers). This hook is marked as optional and can be bypassed by game logic.
- Parameters:
fn(function?) — function to call, with signaturefn(inst, doer). - Returns: Nothing.
SetOnParryFn(fn)
- Description: Registers a callback to be invoked when a parry succeeds. Used to trigger side effects such as visual/sound feedback.
- Parameters:
fn(function?) — function to call, with signaturefn(inst, doer, attacker, damage). - Returns: Nothing.
OnPreParry(doer)
- Description: Triggers the
onpreparryfncallback if set. - Parameters:
doer(Entity) — the entity attempting to parry (the defender). - Returns: Nothing.
EnterParryState(doer, rot, duration)
- Description: Notifies the defender that a parry has occurred by pushing a
"combat_parry"event with weapon and direction data. - Parameters:
doer(Entity) — the entity attempting to parry.rot(number) — rotation (degrees) indicating parry direction.duration(number) — how long the parry state lasts, in seconds.
- Returns: Nothing.
TryParry(doer, attacker, damage, weapon, stimuli)
- Description: Evaluates whether the
doercan successfully parry theattacker’s strike based on angular alignment and stimuli. Returnstrueif the parry succeeds and the parry callback (if any) has been invoked. - Parameters:
doer(Entity) — the entity performing the parry.attacker(Entity) — the entity launching the attack.damage(any) — unused in logic, passed toonparryfn.weapon(any) — unused in logic, passed toonparryfn.stimuli(string?) — type of damage stimuli;"stun"blocks parry;nilallows parry.
- Returns:
trueif parry succeeds,falseotherwise. - Error states:
- Returns
falseifstimuliis"stun"or notnilbut not"stun"(i.e., most non-stun cases are allowed unless explicitly excluded). - Returns
falseifattacker:HasTag("groundspike"). - Returns
falseifdoeris not facingattackerwithin the parry arc, and the attacker either lacks alocomotorcomponent or is not facingdoerwithin the parry arc.
- Returns
Events & listeners
- Pushes:
"combat_parry"— fired viadoer:PushEvent(...)inEnterParryState, with payload{ weapon = self.inst, direction = rot, duration = duration }.
Constructor
- Signature:
Parryweapon = Class(function(self, inst) ... end) - Behavior: Attaches
self.instas the owning entity and immediately adds the"parryweapon"tag.
OnRemoveFromEntity
- Behavior: Removes the
"parryweapon"tag when the component is detached from its entity.