Check if sound is currently playing in a channel

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Check if sound is currently playing in a channel

Re: Check if sound is currently playing in a channel

by Player701 » Tue Jan 02, 2024 10:12 am

FEZ_GG wrote: Sun Dec 31, 2023 3:57 pmIs that something that can even be used in ZScript?
Yes, it can. On the script side, it's called IsActorPlayingSound, and here is the original declaration. The second argument is needed in case you want to check for a specific sound being played, otherwise it will just tell you whether any sound is currently playing or not.

P.S. These posts should probably be split into a separate thread and moved to the scripting subforum. If possible, please post similar questions there next time.

Re: Check if sound is currently playing in a channel

by FEZ_GG » Sun Dec 31, 2023 3:57 pm

> Hell, one could even make a close captions mod with that.

Apologies for the 4 year bump, but I came across this thread while trying to make a captions mod myself. I had planned to write it in ZScript, but I looked through GZDoom's code and saw the aforementioned S_IsActorPlayingSomething is a C++ function. Is that something that can even be used in ZScript? My initial plan was to have some sort of event listener fire when a sound effect is played, and run code that would display a caption for the sound on the UI, but I wasn't sure if something like that existed.

Re: Check if sound is currently playing in a channel

by Graf Zahl » Tue Dec 17, 2019 2:59 am

Marisa Kirisame wrote:Hm, also, wouldn't it be better if this function was clearscope? it could have its uses on the ui too. Hell, one could even make a close captions mod with that.
Done. I also renamed it.

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Tue Dec 17, 2019 2:08 am

Hm, also, wouldn't it be better if this function was clearscope? it could have its uses on the ui too. Hell, one could even make a close captions mod with that.

Re: Check if sound is currently playing in a channel

by Apeirogon » Tue Dec 17, 2019 2:04 am

IMO it would be better if "is play sound()" method would return sound id instead of bool.

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Tue Dec 17, 2019 1:30 am

Well, ever since the time I made this suggestion I've gotten quite proficient at making non-deterministic gameplay scripting that doesn't cause desyncs. :P

Re: Check if sound is currently playing in a channel

by Graf Zahl » Mon Dec 16, 2019 4:36 pm

So, S_GetMSLength was exported, but S_IsActorPlayingSomething was not. So I just added that export, too.

Regarding desyncs, yes, if you make any gameplay related decisions on sounds it will desync. On the other hand, there's no way to design sound without some tools to query the state.
This is a case where trying to make it foolproof is not the best solution, at some point it is the modder's responsibility to use those functions properly.

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Thu Dec 28, 2017 5:39 am

Oh, I see. Although visibility isn't really important at all since it's just a sound effect. No need to be seen or anything.

I'm a bit confused about the FloatBobPhase part, though. The actor doesn't even have floatbob or anything.

Oh wait, it would screw the RNG seed, I see.

Edit: I was digging through the sources a little bit ago and I came across the S_GetMSLength() function, for getting the duration of a sound. Looking at it, I think this one might be a better choice (would even add some parity with unrealscript).

Edit 2: I opened a pull request on qzdoom for both functions.

Re: Check if sound is currently playing in a channel

by RaveYard » Wed Dec 27, 2017 10:32 am

Instead of +NOSECTOR you can use +NOINTERACTION and thus keep the actor visible (for other purposes if need be).

Don't forget to set "FloatBobPhase" to something else than -1 (See here why: https://github.com/coelckers/gzdoom/blo ... .cpp#L5065 )

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Wed Dec 27, 2017 6:55 am

The flags for this actor are +NOGRAVITY, +NOBLOCKMAP, +NOSECTOR and +DONTSPLASH (because it's used on Heretic). Is that enough?

Re: Check if sound is currently playing in a channel

by RaveYard » Wed Dec 27, 2017 5:46 am

It shouldn't desync as long as you avoid using random number generators.

From my experience, if done well, you can spawn actors just on one peer without causing desync if they don't interact with the game and if they have specific flags and properties set.

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Wed Dec 27, 2017 3:57 am

Oh, then I can see it causing problems, since it would be used for deleting a sound playing actor.

Edit: I talked about this with Rachael and it seems that within my use case it might not desync, actually, since the actors have no other interaction with the game at all beyond warping to the player and playing sound.

Re: Check if sound is currently playing in a channel

by _mental_ » Tue Dec 26, 2017 7:46 am

It depends on what you about to do with information returned from this function.
If you will use it for some game logic decisions, it may cause problems in MP.
If you plan to just stop this sound and play that one, everything will be fine.

Re: Check if sound is currently playing in a channel

by Marisa the Magician » Tue Dec 26, 2017 6:04 am

Actually I was wondering about that too. How would this be implemented in a way that wouldn't desync? Is it even possible to have "clientside" actors or something that wouldn't get synced?

Re: Check if sound is currently playing in a channel

by RaveYard » Mon Dec 25, 2017 12:08 pm

Isn't this feature going to cause an issue with multiplayer and demos?

Or am I missing something?

Top