PlayPickupSound

From ZDoom Wiki
Jump to navigation Jump to search

Inventory

virtual void PlayPickupSound (Actor toucher)

Usage

A virtual function called by Inventory items when they're picked up, to play their PickupSound. Normally called in Touch, but can also be called on an item directly to play the sound. Can be overridden to modify its behavior.

Parameters

  • Actor toucher
The actor who is attempting to pick up this item.

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.

This function can be overridden, but the base Inventory class defines it as follows:

	virtual void PlayPickupSound (Actor toucher)
	{
		double atten;
		int chan;
		int flags = 0;

		if (bNoAttenPickupSound)
		{
			atten = ATTN_NONE;
		}
		/*
		else if ((ItemFlags & IF_FANCYPICKUPSOUND) &&
			(toucher == NULL || toucher->CheckLocalView()))
		{
			atten = ATTN_NONE;
		}
		*/
		else
		{
			atten = ATTN_NORM;
		}

		if (toucher != NULL && toucher.CheckLocalView())
		{
			chan = CHAN_ITEM;
			flags = CHANF_NOPAUSE | CHANF_MAYBE_LOCAL;
		}
		else
		{
			chan = CHAN_ITEM;
			flags = CHANF_MAYBE_LOCAL;
		}
		toucher.A_StartSound(PickupSound, chan, flags, 1, atten);
	}

Examples

By default pickupsounds get cut off when multiple items are picked up in quick succession. This version of the Clip item demonstrates how this behavior can be changed, so sounds are played over each other thanks to the CHANF_OVERLAP flag of A_StartSound:

class Clip_NoSoundCutoff : Clip
{
	override void PlayPickupSound (Actor toucher)
	{
		if (toucher && toucher.CheckLocalView())
		{
			toucher.A_StartSound(PickupSound, CHAN_ITEM, CHANF_NOPAUSE|CHANF_MAYBE_LOCAL|CHANF_OVERLAP, 1, ATTN_NORM);
		}
		else
		{
			super.PlayPickupSound(toucher);
		}
	}
}

See also