Skip to content

Playing a Sound when a Creature is Damaged

DJ_WoWDJ_WoW Member Posts: 50
Gooday all,

Like the title says.


I need the proper syntax to play a sound that the damager will here.

OnDamaged Script

PlaySound("resref");
AssignCommand(oDamager, PlaySound("resref"));
AssignCommand(OBJECT_SELF, PlaySound("resref"));

Is not working?

I have also tried PlaySoundObject

Any guidance would be appreciated.

DJ-WoW







Comments

  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited July 2023
    You need the actual wave file name (without the ".wav") not the resref for PlaySound(). From the lexicon -
    PlaySound(string)

    Plays a sound on the client machine.
    void PlaySound(string sSoundName);
    

    Parameters

    sSoundName

    The name of the sound to play.

    Description

    Play the wave resource named sSoundName.

    Remarks

    PlaySound returns immediately, it does not wait for the sound to finish playing. If you want to play a sound using a trigger, then look at the SoundObjectPlay function, as PlaySound requires an object to work.

    Known Bugs

    This might not be an actual bug, but though PlaySound isn't an action (you don't get the little yellow square on the screen), if you assign a PlaySound to someone, it will wait for their current action queue to finish before playing.

    and
    SoundObjectPlay(object)

    Play a sound object.
    void SoundObjectPlay(object oSound);
    

    Parameters

    oSound

    Sound object to be played.

    Description

    Play sound object created and placed in module using the Sound Wizard.

    Remarks

    PlaySound() and SoundObjectPlay() perform different functions. SoundObjectPlay() plays a sound object, which may comprise many sound resources. PlaySound(), in contrast, plays a single sound resource. Sound objects have additional properties as well, such as location and looping characteristics. SoundObjectPlay() may thus be an appropriate choice for controlling area noises, such those associated with OnEnter events.

    Note that the sound list of the object is set by default to play at random. So if you have a list of several sounds you want all to play, then go to the Advanced tab of the sound object's properties and change the Play Order to Sequential. If you want it to play at the exact same time, you will need to create multiple sound objects.

    Notice that while PlaySound() requires a string as its parameter, SoundObjectPlay() requires an object.

    TR
  • ForSeriousForSerious Member Posts: 455
    You should be able to add something like this:
    PlaySound("gui_trapsetoff");
    
    I have that in a delay command that gets called in the OnClose slot on a placeable. It plays the sound with the placeable as the sound source.
  • DJ_WoWDJ_WoW Member Posts: 50
    Gooday all,

    Wanted to thank you all for your insights. I had the PlaySoundObject working, but I had not unchecked the Active Box. Does exactly what I wanted it to do now.

    Thanks again for your time,
    DJ-WoW
Sign In or Register to comment.