NWH Saber Blocking Explained

This document explains the new mechanics introduced in the WP_SaberCanBlock function, which adds more granular control over the saber blocking system in Jedi Knight II.

In the base game, Blue and Yellow saber styles were almost useless against a Level 3 Defense, but these changes aim to make things more balanced and configurable.


1. New Console Variables (Cvars)

The updated code introduces three new console variables that allow for dynamic adjustment of block chances (that were hardcoded in BaseJK) for a Level 3 Saber Defend skill.


2. The Block Chance Mechanic

The core logic for blocking with a Level 3 defense now relies on a random dice roll. A random number from 1 to 10 is generated. If the number is less than or equal to the Cvar's value, the block fails. The mod now ensures that the Cvar value is always between 0 and 10, preventing unexpected behavior.

Chance of Blocking = 10 - (Cvar value) 10

The g_disablerandomparries Cvar acts as a global toggle. If set to 1, all random chance checks are bypassed, and the only-angle-based blocking logic is used, where only the g_blockfactor Cvar determines if a block is successful for a Level 3 defender.

Chance of Blocking vs. Cvar Value

Cvar Value (g_blockchanceX) Chance of Failure Chance of Blocking BaseJK Style(s)
0 0% 100% Yellow, Blue
1 10% 90%
2 20% 80% Red
3 30% 70%
4 40% 60%
5 50% 50%
6 60% 40%
7 70% 30%
8 80% 20%
9 90% 10%
10 100% 0%

3. The Block Angle Mechanic (g_blockfactor)

The new code introduces a configurable g_blockfactor Cvar. This variable determines the angle within which a player can successfully block an attack. The value is a cosine, and a lower value corresponds to a wider, more forgiving angle. The specific angle can be calculated using the inverse cosine (arc-cosine) of the blockFactor.

Angle in degrees = arccos(blockFactor)

Arccos Calculator

Enter a blockFactor value (0 to 1) to calculate the angle.

Result will be displayed here.

Block Angle Examples

The angle is measured from the center of the player's view direction. For example, a blockFactor of 0.0 allows blocking in a full ±90° cone, while a blockFactor of 1.0 only allows blocking if the attack is perfectly centered.


4. Other Conditions for Failure

The function also contains several checks that will cause a block to fail immediately, regardless of skill level or Cvar settings:


5. Base Game vs. Mod Block Logic Comparison

The following table and analysis highlight the key differences between the original Jedi Knight II blocking code and the changes introduced in this mod.

Base Game Block Logic Analysis

The base game code for WP_SaberCanBlock uses a series of conditional checks with hardcoded values:

Mod Block Logic Analysis

Key Differences and Improvements

Feature Base Game Logic Mod Logic
Block Chance Hardcoded random checks. Controlled by g_blockchancer, g_blockchancey, and g_blockchanceb for Level 3 defenders.
Block Angle Hardcoded blockFactor values. g_blockfactor Cvar controls the angle for Level 3 defenders.
Flexibility Very low flexibility. High flexibility. Admins can fine-tune chance and angle.
Randomness Toggle No global toggle. g_disablerandomparries Cvar allows for a purely angle-based block system.