A_FireShotgun

From ZDoom Wiki
Jump to navigation Jump to search
Ktip.png This page describes a function made for one of the natively supported games. These functions are made with very specific purpose and provide no flexibility, so using them in custom projects is not recommended. Authors are encouraged to use one of the more generalized functions in custom projects. For example: A_FireBullets.
DoomWiki.org
For more information on this article, visit the A_FireShotgun page on the Doom Wiki.


StateProvider

action void A_FireShotgun()

Usage

Performs Doom's shotgun attack, firing seven pellets each dealing 5 * 1d3 damage. This is a shortcut for calling A_FireBullets, A_StartSound and A_GunFlash with predetermined hard-coded parameters.

This code is the equivalent of calling A_FireShotgun for 7 tics on the A frame of the SHTG sprite:

SHTG A 7
{
  A_FireBullets (5.6, 0, 7, 5);
  A_StartSound("weapons/shotgf", CHAN_WEAPON);
  A_GunFlash();
}

If vertical bullet spread for weapons is enabled, the function applies vertical spread in addition to the horizontal one.

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.
action void A_FireShotgun()
{
	if (player == null)
	{
		return;
	}

	A_StartSound ("weapons/shotgf", CHAN_WEAPON);
	Weapon weap = player.ReadyWeapon;
	if (weap != null && invoker == weap && stateinfo != null && stateinfo.mStateType == STATE_Psprite)
	{
		if (!weap.DepleteAmmo (weap.bAltFire, true))
			return;
		
		player.SetPsprite(PSP_FLASH, weap.FindState('Flash'), true);
	}
	player.mo.PlayAttacking2 ();

	double pitch = BulletSlope ();

	for (int i = 0; i < 7; i++)
	{
		GunShot (false, "BulletPuff", pitch);
	}
}