• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Repeated sound not being played?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
            ...
            if (GetLocalPlayer() == Player(i)) then
                call PlaySoundBJ(gg_snd_WAR)
            endif
            ...
            if (...) then 
                if (GetLocalPlayer() == Player(p)) then
                    call PlaySoundBJ(gg_snd_WAR)
                endif
            endif
I play this sound, but if I type the command when this is to be played fast enough it is silent I think its because the last sound isn’t finnished yet. Do I need to create a local sound to metigate this? (I want the new sound to be played over or instead of the old.) How do I do that?
Also, is there anything else related to playing sounds for 1 player or about sounds in general that is missing in my few lines of code?

Trigger 1 (sound is played)
Trigger 2 (I typed so fast that no sound is played)
Trigger 3 (sound is played again, enough time has passed)
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
But to stop a sound I need to Store the LastCreatedSound? As you can see two players here the same sound every time. Im confused.

JASS:
            ...
            if (GetLocalPlayer() == Player(i)) then
                call StopSoundBJ(gg_snd_WAR, false)
                call PlaySoundBJ(gg_snd_WAR)
            endif
            ...
            if (...) then 
                if (GetLocalPlayer() == Player(p)) then
                    call StopSoundBJ(gg_snd_WAR, false)
                    call PlaySoundBJ(gg_snd_WAR)
                endif
            endif

It just doesn't feel right using gg_snd_WAR there is no problem playing it for more then 1 player?
 
But to stop a sound I need to Store the LastCreatedSound? As you can see two players here the same sound every time. Im confused.

JASS:
            ...
            if (GetLocalPlayer() == Player(i)) then
                call StopSoundBJ(gg_snd_WAR, false)
                call PlaySoundBJ(gg_snd_WAR)
            endif
            ...
            if (...) then 
                if (GetLocalPlayer() == Player(p)) then
                    call StopSoundBJ(gg_snd_WAR, false)
                    call PlaySoundBJ(gg_snd_WAR)
                endif
            endif

It just doesn't feel right using gg_snd_WAR there is no problem playing it for more then 1 player?

The way you did it is correct. You don't need to store the last created sound or anything like that.

In general, sounds are usually created once at the start of the map and used consistently throughout the map. Your code is MPI because it is stopping the sound locally and playing it locally. So let's say Player 1 and Player 2 both play the sound. If player 1 types in the command again, his sound will stop and start again, but nothing will happen for Player 2. As such, there is no potential for collision.
 
Status
Not open for further replies.
Top