[SOLVED FR] I want to change how the expire sound is played

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

[SOLVED FR] I want to change how the expire sound is played

Post by yum13241 »

PowerDamage4
Spoiler:


Damage4
Spoiler:
Right now the Powerup.Expire sound plays AFTER the powerup finishes blinking. (it actually expires)

I want it to play WHILE it's blinking. Is this possible?

SOLUTION: See BlueShadows''s post.
Last edited by yum13241 on Tue Dec 13, 2022 3:55 am, edited 5 times in total.
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: I want to change how the expire sound is played

Post by yum13241 »

This just errors out with Unexpected Character: ? (ASCII -62)
Spoiler:

Where's my problem?
Jarewill
 
 
Posts: 1768
Joined: Sun Jul 21, 2019 8:54 am

Re: I want to change how the expire sound is played

Post by Jarewill »

I have honestly no idea what caused this problem, but when I rewrote your code from scratch it worked fine:
Spoiler:
Maybe some invisible character somewhere messed with the compiler?
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: I want to change how the expire sound is played

Post by yum13241 »

Thanks! For future readers: Make sure to comment out the DeathSound.

HOLD UP! Even though I set the DeathSound to "dsempty" the expire sound now plays twice; once while it's blinking, and another time when it's actually gone.

PowerDamage4
Spoiler:
Damage4
Spoiler:
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: I want to change how the expire sound is played

Post by Blue Shadow »

yum13241 wrote: Wed Dec 07, 2022 9:21 am HOLD UP! Even though I set the DeathSound to "dsempty" the expire sound now plays twice; once while it's blinking, and another time when it's actually gone.
The code was written so that the sound plays repeatedly through out the expiration period, not just once. So if your sound is shorter than 4 seconds or so, then it'll play more than once.
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [SOLVED SORTA] I want to change how the expire sound is played

Post by yum13241 »

Is it possible to change that?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: [SOLVED SORTA] I want to change how the expire sound is played

Post by Blue Shadow »

This should do it.

Code: Select all

Class PowerDamage4 : PowerDamage
{
	private bool soundplayed;

	Default
	{
		Powerup.Color "Purple", 0.25;
		DamageFactor "Normal", 4;
		Inventory.Icon "QUADA0";
		SeeSound "powerups/4equip";
		Powerup.Duration -35;
		DeathSound "dsempty";
		+INVENTORY.ADDITIVETIME;
	}

	override bool HandlePickup (Inventory item)
	{
		int savedEffectTics = EffectTics; // Save the powerup's current duration before handling the pickup.
		bool res = Super.HandlePickup(item);

		// Only allow the sound to be replayed if the powerup's duration changed to be greater than before,
		// while at the same time, the new duration is greater than the blinking threshold (we don't want
		// the sound to be replayed if the powerup is still expiring with the new duration).
		if (res && EffectTics > savedEffectTics && EffectTics > BLINKTHRESHOLD)
		{
			soundplayed = false;
		}

		return res;
	}

	Override void DoEffect()
	{
		Super.DoEffect();
		If(!soundplayed && owner && EffectTics > 0 && EffectTics <= BLINKTHRESHOLD)
		{
			owner.A_StartSound("powerups/4expire",CHAN_5,CHANF_NOSTOP,1.0,ATTN_NONE);
			soundplayed = true;
		}
	}
}
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [SOLVED SORTA] I want to change how the expire sound is played

Post by yum13241 »

One blink passes by w/o any sound but this is all I can do. Btw the sound is the Quad Damage expiration sound. Oh well.
Post Reply

Return to “Scripting”