A_WeaponJump

From DoomWiki.org

A_WeaponJump(state, chance) is a random jump function for weapons that is part of the MBF21 specification. It mirrors the behavior of A_RandomJump, introduced with MBF, but is used for player weapons rather than mobjs. It has two parameters, using the values in the "Args1" and "Args2" fields as arguments.

The first argument determines the chance to jump, utilizing a number between 0 and 256—where 0 guarantees a jump, while 256 guarantees no jump. The second argument sets the state to jump to, using its DeHackEd index number. When the function is called, a random number is generated and tested against the value in the first argument. If the generated random number is smaller than the specified chance, the function jumps to the specified state (success); if the number is bigger, the state is executed normally (failure).

Example[edit]

The following is an example of how to set the A_WeaponJump code pointer in a DeHackEd file using BEX syntax:

Frame 1234
Next frame = 16
Args1 = 10
Args2 = 64

[CODEPTR]
FRAME 1234 = WeaponJump

Or using DECOHack syntax:

state 1234
{
 TNT1 A 0 A_WeaponJump(10, 64)
 goto 16
}

The example above uses A_WeaponJump on an invisible, zero-duration state to implement a 25% chance to skip the A_ReFire code pointer in the pistol's firing sequence (state 16). This avoids the aiming offset triggered by the A_ReFire function, instead giving the pistol perfect accuracy for the next shot if the jump succeeds.

External links[edit]