Requesting help with a custom event handler check for a sound being 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
Protozoare
Posts: 17
Joined: Sat Oct 08, 2022 2:51 am
Preferred Pronouns: He/Him

Requesting help with a custom event handler check for a sound being played

Post by Protozoare »

So I've spent my last afternoon making a simple taunt event handler for a custom class for a mod. The sound plays and it works as usual, but the problem is that you can spam the key and the noise overlaps. Naturally, I've looked for a way to fix this and come up with the plan to find a function that can prevent a sound from playing if it is already being played in the same channel, by the player. I've tried for a few hours and never got the S_StartSound function to get to understand the CHANF_NOSTOP flag. Slade3 shows that I need an int type variable....and the only documentation I've found in regards to sound channel flags was about A_StartSound :? I'm wondering if there is a way to prevent the sound from being played if the sound is already being played, as to not overlap it, as the game launches with the code below, and there seem to be no changes despite the me changing the flag in various ways, even if I replace it with a number, nothing changes, and I'm starting to ask myself if the flags are supported by this function, and if yes, how? I get no warnings or crashes, and I'm probably missing something here....after spending my time searching for examples of such a simple program, I've stumbled across various syntaxes for the flag, none of which worked. Even posts from 2021 had a syntax that didn't work. I'm surprised, as there have been way worse things to code for this mod, and it wasn't so bad. Anyways, after all this rambling at a late hour I've decided to ask someone about it, so here is the code in my file.

Code: Select all

version "4.11.1"
class my_eventhandler : EventHandler
{
    override void NetworkProcess(ConsoleEvent e)
    {
      if (players[0].mo is "myclass"&& e.Name == "Taunt")
        {
          S_StartSound("TAUNT0", 2, CHANF_NOSTOP, 1);
        }
    }
} 
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Requesting help with a custom event handler check for a sound being played

Post by Jarewill »

CHANF_NOSTOP works a bit differently, if my memory is right it only prevents playing the sound if the channel is occupied by any other sound, it will still override the sound if it's the same.
What you want to use here is IsActorPlayingSound:
if (players[0].mo is "myclass"&& e.Name == "Taunt" && !players[0].mo.IsActorPlayingSound(CHAN_VOICE))
Protozoare
Posts: 17
Joined: Sat Oct 08, 2022 2:51 am
Preferred Pronouns: He/Him

Re: Requesting help with a custom event handler check for a sound being played

Post by Protozoare »

I copied over the new condition in the if, and it still does not prevent the sound from overriding, even though the code is there and the event takes place when pressing the key.
version "4.11.1" class Sportstan_eventhandler : EventHandler { override void NetworkProcess(ConsoleEvent e) { if (players[0].mo is "Stan"&& e.Name == "Sportstan_Taunt" && !players[0].mo.IsActorPlayingSound(CHAN_VOICE)) { S_StartSound("TAUNT0",2); } } }
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Requesting help with a custom event handler check for a sound being played

Post by Jarewill »

Oh my bad, I thought you were using A_StartSound.
Since S_StartSound doesn't play the sound from the player, IsActorPlayingSound won't work.
I am not familiar with a similar function that would work with this, but you can use A_StartSound with the player pointer: players[0].mo.A_StartSound("TAUNT0",2);

Also instead of using players[0] I recommend using players[e.Player] as this will support multiplayer.
Protozoare
Posts: 17
Joined: Sat Oct 08, 2022 2:51 am
Preferred Pronouns: He/Him

Re: Requesting help with a custom event handler check for a sound being played

Post by Protozoare »

Thank you, works fine now! I was suspecting the S_ function for not having the sound played by the actor.
Post Reply

Return to “Scripting”