Aller au contenu

Photo

PlaySound ... or does it?


  • Veuillez vous connecter pour répondre
13 réponses à ce sujet

#1
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
Is there a way to just easily one-off play a sound?

I never could figure out what the PlaySounds wanted me to pass as a parameter and they never work.

Sure I created a sound object and set it to play or not for my previous works but that seems bulky and ridiculous
when I just want a single line of code to play a reasonably loud 1 shot sound.

#2
rjshae

rjshae
  • Members
  • 4 505 messages
Does this help? http://nwn2.wikia.com/wiki/PlaySound

#3
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
not really... playing a sound from a placeable thats about to die. Not sure what the string value should be etc, and no actions would be queued anyway

#4
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
This is my code btw

if (iSonicDmg >= 1) // die if sonic damage dealt

	{
	DBT("...1 or more sonic damage dealt, destroying...");
	
	
	AssignCommand(OBJECT_SELF, PlaySound("as_na_rockfalg1", TRUE) );
	DelayCommand(1.0f, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDie, OBJECT_SELF) );
	
	}


It seems to work fine in conversation and I basically copied their script except for my death part

#5
rjshae

rjshae
  • Members
  • 4 505 messages
To produce a placed sound, you can create an IPoint speaker at the location of the object, then run a script on it to play the sound and have it clean up itself. (Kind of a long example here: the PlaySound call is in the DoRockslide function.)

#6
Dann-J

Dann-J
  • Members
  • 3 161 messages
I thought PlaySound only worked on creatures. Hence the occasional need for a 'sound ninja'.

If the sound is occuring while the player isn't doing something else (like moving or being in combat), you can ClearAllActions() on the PC and assign the PlaySound to them. That way you're guaranteed to hear it (in a single player game, at least)

PlaySound is added to a creature's action queue, which means it can be overridden by more aggressive actions, or potentially delayed until you've finished your current action. If you assign PlaySound to a player on the move, for instance, it won't play until the player reaches their destination and stops.

#7
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
So would you say my method of throwing down a sound object that plays once only and sending a line of code to play it is no less bulky than these other methods?

#8
Dann-J

Dann-J
  • Members
  • 3 161 messages
If it was for a sound you expected to hear multiple times at various places, then something more complex might be warranted. A sound that plays only once, and only at a specific location, might as well be a sound object.

Another option would be to create a custom VFX that incorporates dust, flying stone debris, and an appropriate sound, then just play the effect when destroying the placeable.

#9
Tchos

Tchos
  • Members
  • 5 072 messages
I have taken to creating SEFs containing nothing but the sound I want to play, and spawning them as temporary effects in the location, because of inconsistent results with PlaySound.

#10
Morbane

Morbane
  • Members
  • 1 883 messages
make the PC play the sound? strange i know - but a much shorter trip - and even in 3d sound it wouldnt be obvious.

Tchos' idea is work intensive but not bulky to code for.


Edit: sorry Dann you already said this :innocent:

Modifié par Morbane, 03 août 2013 - 11:36 .


#11
kamal_

kamal_
  • Members
  • 5 258 messages
Would this help?

credit to kevL:
kamalpoe.blogspot.com/2013/02/summoning-sound-ninja-playsound-fix.html

#12
kevL

kevL
  • Members
  • 4 070 messages
i guess (it's been a while) you'd need a creature-resref "sh_sound_ninja.Utc" ready to go, w/ ScriptHidden checked and Disable AI unchecked

?

#13
Dann-J

Dann-J
  • Members
  • 3 161 messages
It shouldn't need to be running it's AI. In fact, you'd be better off stripping the ninja blueprint of all it's usual scripts so that it's unlikely to ever have anything in it's action queue. Much like a faction pig.

#14
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi E.E.

I have also had issues playing sounds using PlaySound, however, I found there is one quite important thing to note:-

The object playing the sound must remain "alive" for a small amount of time to allow the sound to start properly without it being terminated.

So, it is possible to have placeables play a sound and I have this occur using code like PlaySound(sSound, TRUE);  in many scripts. However, if this same script tries to fire as the object is being destroyed, then the sound does not play, and it is better to have another object that remains alive to play the sound instead.

When is this script of yours trying to play the sound?

Lance.

EDIT: I just noticed that you say that your script is for a placeable about to "die", so this is your problem then. I have written some "Hardness" checking scripts for placeables that intercept the damage taken to determine how much damage and if the placeable should be destroyed or not. By taking control of the moment of destruction, I can play the sound prior to the placable being destroyed. You could do a similar thing if you like, or I can send you my scripts for you to look at and take what you need.

Modifié par Lance Botelle, 10 août 2013 - 10:38 .