GetSoundPlaying

Post » Fri Feb 05, 2010 8:31 pm

Hey,

I've been having some trouble with the "GetSoundPlaying" function. I remember having trouble with it in the past, but I thought I'd give it another shot now.

The first thing I tried was the "Underwater" sound. It's a reasonably long sound, so I figured it should be easily detectable. I tried both:

GetSoundPlaying "Underwater"Player->GetSoundPlaying "Underwater"


With no luck. I then tried the same thing with the "Disarm Trap" sound, still with no luck (even though it's specifically given as an example in MWSFD). However, it occurs to me that perhaps for it to work, the fix must be the container that's being disarmed, rather than the player... does anyone know about this?

I also tried the "miss" sound, which was the only one that worked (but only with the Player fix).

So basically, does anyone know why some work and some don't, or how to get them all working, or which ones don't work (other than the potion drinking sound, which I read is bugged)?

Thanks,

- Danjb
User avatar
Joe Alvarado
 
Posts: 3467
Joined: Sat Nov 24, 2007 11:13 pm

Post » Sat Feb 06, 2010 12:36 pm

Here is a quote from john.moonsugar's website.

GetSoundPlaying is unreliable on some systems
I first noticed this problem while playing as a vampire because two of the mods that I was using, "Vampire Embrace" (VE) and "Vampire Realism" (VR) weren't working correctly for me.

VE allows you do do a "combat bite", where, if you punch someone until their fatigue goes below 10, then you will automatically move close to them and do the neck biting animation and svck their blood. However, this feature was very unreliable for me. I would often punch someone until they fall down, they'd get back up, I'd punch them until the fall down again, and this could go on dozens of times before a combat bite initiated. Even the Readme suggests that this may happen occasionally, and if so, to just try again. But for me, the problem happened the vast majority of times with some NPCs.

VR has a "staking" feature, where you can't kill a vampire unless you hit them with a special stake. You're supposed to fight them until they are knocked down, then use the stake on them, and that will kill them. However for me, I'd fight them, they'd go down, I'd use the stake on them, nothing would happen, they'd get back up, I'd do it all over again. Sometimes I would get a kill, other times the vampire would just keep getting back up, they were virtually immortal.

So I went to PES and looked through all the comments there, and it turns out that some small but significant population of the users of these mods have the same problems.

Looking at the scripting code in these mods, the common factor was that they both used GetSoundPlaying to recognize the event when the NPC was hit.

I still have not found an elegant solution, but I've been able to change the scripts in VE and VR so that they work pretty well now without using GetSoundPlaying. For VE, I use OnKnockout and combine that with checking if ( Player->GetWeaponType == -1 ) [I have a patch for VE's combat bite on my mods page]. For VR, I just commented out the use of GetSoundPlaying as it was essentially superfluous, since HitOnMe was previously checked. I still have more testing to be done.

Looking at code in Bethesda's original scripts, we see that GetSoundPlaying is never used to detect events, it is only used for managing when sounds are played. Sometimes it checks to see if a sound is not playing, so the sound can be started, like this:

if ( GetSoundPlaying "ghostgate sound" == 0 )
playloopsound3dvp "ghostgate sound" 1.0 1.0
endif

and sometimes it checks to see if a sound is playing, so it can be stopped, like this:

if ( GetSoundPlaying "heart" == 1 )
StopSound "heart"
endif

So my conclusion is that GetSoundPlaying is best used only for sound management, and should not generally be used to detect events unless you also offer some alternative method of detection. Also, it is probably pretty safe to check if a sound is not playing. The biggest trouble seems to be when it is used to check if a sound is playing, i.e. event detection. But many user mods already do use GetSoundPlaying for event detection, and I suspect that my opinion on the matter will be highly unpopular with scripters!



Read a bit of it.. don't know if this will help but it may.
User avatar
Lloyd Muldowney
 
Posts: 3497
Joined: Wed May 23, 2007 2:08 pm

Post » Fri Feb 05, 2010 10:09 pm

Hmm... seems like it is indeed a rather unreliable function... which is a shame, really, since it has so much potential! A lot of events cannot be detected any other way.

Still, it seems strange that some sounds work fine for me while others do not work at all; the "miss" sound was detected every single time, without fail, while the others weren't detected even once.
User avatar
Hayley Bristow
 
Posts: 3467
Joined: Tue Oct 31, 2006 12:24 am

Post » Sat Feb 06, 2010 6:52 am

Yes I know, this was my original plan for Comments in my companion mod, though since I read up on it and realized it doesn't work on some computers at all or only a few sounds work on others, I am going to have to judge by journal entries... maybe.
User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Post » Sat Feb 06, 2010 12:42 am

Reports on what works and what not are sparse along the many years of Morrowind modding, as a general hint you should look for mods containing the GetSoundPlaying word made by other well-known modders (first that comes to my mind is Cortex, but there are many others). Even so, it is not guaranteed that what worked in first vamilla version or before Bloodmoon engine would still work after current MCP patched version commonly used nowadays.
Put it simply, when it works, it works, you have to try. There are many things to know.
First, often the sound emitted is not the one you would expect (see water detection examples, what are the real emitted sounds?). Also, sometimes the same .wav is used by different sound ids, what is the right one?.
Second, it must be a 3d positional sound.
In my experience, usually sounds emitted by player (usually not in menu mode or deleting the object at the same time like the the drink sound) or activators work.
Frankly, I don't mind much Linux Wine users whining it can't detect sounds like real hardware on Windows for a Windows game, I bet if they play with a virtual machine running a Windows OS with a emulated chipset/soundblaster it works).
Something that maybe could help is using MWEdit script templates to generate a detection test for all interesting sounds making player play them and testing for detection by the same player.
User avatar
Motionsharp
 
Posts: 3437
Joined: Sun Aug 06, 2006 1:33 am

Post » Fri Feb 05, 2010 11:58 pm

Put it simply, when it works, it works, you have to try. There are many things to know.
First, often the sound emitted is not the one you would expect (see water detection examples, what are the real emitted sounds?). Also, sometimes the same .wav is used by different sound ids, what is the right one?.
Second, it must be a 3d positional sound.
In my experience, usually sounds emitted by player (usually not in menu mode or deleting the object at the same time like the the drink sound) or activators work.
Frankly, I don't mind much Linux Wine users whining it can't detect sounds like real hardware on Windows for a Windows game, I bet if they play with a virtual machine running a Windows OS with a emulated chipset/soundblaster it works).
Something that maybe could help is using MWEdit script templates to generate a detection test for all interesting sounds making player play them and testing for detection by the same player.

Thanks for the information.

I've been manually testing some out for use in my upcoming Achievements mod. Here are the results:

================================GETSOUNDPLAYING================================All sounds tested with "Player->" as the fixSUCCESSFUL:alteration castconjuration castdestruction castillusion castmysticism castrestoration castSpell Failure AlterationSpell Failure ConjurationSpell Failure DestructionSpell Failure IllusionSpell Failure MysticismSpell Failure RestorationbowShootcrossbowShootHealth DamageHand to Hand Hit	\Hand to Hand Hit 2	/ Only triggered when the PLAYER is hit with fistsmiss			<-- Only triggered if you're aiming at someoneTorch Out		<-- Only triggered when a light goes underwaterWeapon Swish		<-- Seems to be all weapons / hand-to-handUNSUCCESSFUL:book open		<-- May work with the book as the fixcritical damage 	<-- May work if the PLAYER gets crit'dDisarm Trap		<-- May work with the door / chest as the fixDisarm Trap Fail	<-- May work with the door / chest as the fixdrink			<-- Causes an "EXPRESSION" error (from MWSFD)Open Lock		<-- May work with the door / chest as the fixOpen Lock Fail		<-- May work with the door / chest as the fixpotion successpotion failRepairrepair failscroll			<-- Causes an "EXPRESSION" errorskillraiseSwallow			<-- May work with the ingredient as the fixUnderwaterUNKNOWN (no idea when these sounds actually play):PackSwishSSwishMSwishL


I've found that in all successful cases, the sound WILL be detected EVERY TIME, without fail, for multiple frames, so I'm not really worried about them only working "sometimes". I can understand how people with different hardware might have problems, but that's just an incompatibility issue; inevitable and unavoidable. I'm not going to hold back from using the functions when they work perfectly well for me :)
User avatar
Robert Bindley
 
Posts: 3474
Joined: Fri Aug 03, 2007 5:31 pm

Post » Fri Feb 05, 2010 11:59 pm

GetSoundPlaying only works with 3DSound.

I don't quite know what it means but I know it's true. So basically if you are using GetSoundPlaying not everyone will be able to use your mod.

http://www.fliggerty.com/phpBB3/viewtopic.php?f=30&t=3769
User avatar
Jack Bryan
 
Posts: 3449
Joined: Wed May 16, 2007 2:31 am


Return to III - Morrowind