Skip to content

Critical Hits

szapp edited this page Oct 31, 2017 · 12 revisions

The feature Critical Hits (GFA_CRITICALHITS) implements critical hits for ranged weapons. The customization allows to define which body parts are weak spots and what happens when a critical hit occurs (event like screen print, sound jingle, additional XP, ...).

On projectile collision and positive hit registration with an NPC, a "config function" is called (GFA_GetCriticalHitDefinitions). In this function, based on the hit NPC, the weapon used, the damage, etc., you define a weak spot. This weak spot is defined by the name of the bone of the NPC model (e.g. "Bip01 Head") and a new base damage value (the damage of the weapon, not the final, applied damage).
After this function returns the weak spot definition (this can be different every time), the collision with the NPC is checked for the bone ("Was the NPC hit in Bip01 Head?"). If so, the damage will be overwritten with the newly defined damage value and another config function is called (GFA_StartCriticalHitEvent). This second function allows to start an event. By default a sound jingle is played and a hit marker is shown briefly to signal the critical hit. If the projectile did not hit the defined bone, the damage will of course not be adjusted and the event function will not be called.

The first part of this implementation differs, if free aiming for ranged weapons is not activated (e.g. disabled in the game menu, or when playing with keyboard controls only) or if the setting constant GFA_TRUE_HITCHANCE is set to false. If that is the case, the shot cannot be checked for a specific bone of the model and a different config function is called instead (GFA_GetCriticalHitAutoAim). In this function you can return a critical hit probability, which will be used instead. The event function will be called on positive critical hit.

Keep in mind, that you should always adjust both of these alternatives, because there are players that prefer to play the game keyboard-only or others who might not like free aiming (boring!).
 

Contents

1.   Config Functions
    1.1.   GFA_GetCriticalHitDefinitions
    1.2.   GFA_GetCriticalHitAutoAim
    1.3.   GFA_StartCriticalHitEvent


Config Functions

The configuration of this feature is found in the file config/criticalHit.d.

GFA_GetCriticalHitDefinitions

This function is called every time (any kind of) NPC is hit by a projectile (arrows and bolts) to determine, whether a critical hit occurred; but only if free aiming is enabled and if GFA_TRUE_HITCHANCE is set to true. For critical hits without free aiming (or scattering) see GFA_GetCriticalHitAutoAim below.

This function here defines the critical hit zone (weak spot) based on the NPC that it hit or the weapon used. A weak spot is defined by the name of a bone of the model and modified damage. This function is dynamic: It is called on every hit and the weak spot and damage can be calculated individually differently every time.

Note: This function is specific to free aiming. For critical hits without free aiming see GFA_GetCriticalHitAutoAim below.

Note: This function only defines the critical hits. It is called every time an NPC is hit, regardless of whether it is a critical hit. To start an event when a critical hit actually occurs, see GFA_StartCriticalHitEvent below.

Ideas: incorporate weapon-specific stats, head shot talent, dependency on target, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.
By default, weak spots for all Gothic 1 and Gothic 2 monsters are defined as head shots.

func void GFA_GetCriticalHitDefinitions(C_Npc target, C_Item weapon, int talent, int damage, int damageType, int returnPtr)
target The NPC that is hit by the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
talent The talent value of the shooter depending on the ranged weapon.
damage Base damage (damage of the ranged weapon), not the final damage! This value is an integer float.
damageType Damage type of the projectile.
returnPtr Instance pointer to the weak spot definition.

 

GFA_GetCriticalHitAutoAim

This function is called every time (any kind of) NPC is hit by a projectile (arrows and bolts) to determine, whether a critical hit occurred; but only if free aiming is disabled, not active (game settings) or GFA_TRUE_HITCHANCE is set to false. For critical hits with free aiming see GFA_GetCriticalHitDefinitions above.

This function here allows to define a critical hit chance even for the standard auto aiming. Although not existing in the original Gothic 2, this is important here to balance the damage output between free aiming and auto aiming, as the player can switch between them anytime during a running game in the game menu.

Note: This is not necessary for Gothic 1, as it already has critical hits for auto aiming by default. Nevertheless, the original critical hit calculation of Gothic 1 is disabled and replaced by this function. This way, the critical hit chance can be manipulated if desired. The lines of code below for Gothic 1 are the same as default by Gothic.

Note: This function is only called if free aiming is disabled, not active (game settings) or GFA_TRUE_HITCHANCE == false. For critical hits with free aiming see GFA_GetCriticalHitDefinitions above.

Ideas: scale critical hit chance with player skill and distance, ...
Examples are given inside the function (section of Gothic 2), but commented out to serve as inspiration of what is possible.

func int GFA_GetCriticalHitAutoAim(C_Npc target, C_Item weapon, int talent)
target The NPC that is hit by the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
talent The talent value of the shooter depending on the ranged weapon.
returns Percentage (chance level or hit chance), where 0 is no critical hit ever and and 100 always causes a critical hit. Everything in between is dependent on a respective probability. To disable this feature, simply have the function always return 0.

 

GFA_StartCriticalHitEvent

This function is called when a critical hit occurs and can be used to print something to the screen, play a sound jingle or, as done here by default, show a hit marker. Leave this function blank for no event.

This function is also called when free aiming is disabled, depending on the configuration in GFA_GetCriticalHitAutoAim, see above.

Idea: The critical hits could be counted here to give an XP reward after 25 head shots, print to screen, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func void GFA_StartCriticalHitEvent(C_Npc target, C_Item weapon, int freeAimingIsEnabled)
target The NPC that is hit by the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
freeAimingIsEnabled Indicator whether free aiming is currently active.