• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Turn on/off ambient sound

Status
Not open for further replies.
Level 3
Joined
Dec 2, 2013
Messages
25
Hi everyone, I have a sound problem : I need to play a certain ambient sound when a unit enters a region. I also need to turn off ambient sound (wich is Lordaeron summer) and music.

I use the local player script to do this in order to play the sound only for the one who enters the region.
OK this part works fine

When the unit leaves the region, I have to turn back on music AND ambient sound (Lordaeron summer) and stop my previous sound (the cave sound).

But here is the prob, the GUI action to do this
Sound - Use the Lordaeron summer daytime ambient theme causes desync.

So here is my question : is there a way to turn on and off the ambient sound (such as Lordaeon summer) using Local player script WITHOUT desync ?

I'm really bad at JASS but maybe there is something like :
call PlaySound(bj_dayAmbientSound, true, true)

Here are the triggers that I used (uploaded img)
 

Attachments

  • Trigger.jpg
    Trigger.jpg
    220 KB · Views: 39

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,905
Variables should never be set on the local block (inside this condition)
Leaving unit is the triggering unit, use the latter one instead, because it's faster.
Don't post screenshots of triggers, post them with the standard method: rightclick your trigger name (not the trigger name where folders are, the other one near "trigger functions") and click on copy as text. Then you simply come here and type [trigger]paste your trigger[/trigger]
 
Level 12
Joined
Jan 30, 2020
Messages
875
Actually @Wrda , you are wrong about setting variables.

What desyncs is creating handles in the local player context.

In this case, what causes the desync are the actions using the Lordaeron Summer daytime and nighttime ambient themes.
Because here is the source of the action from Blizzard.j:
JASS:
function SetAmbientDaySound takes string inLabel returns nothing
    local real ToD

    // Stop old sound, if necessary
    if (bj_dayAmbientSound != null) then
        call StopSound(bj_dayAmbientSound, true, true)
    endif

    // Create new sound
    set bj_dayAmbientSound = CreateMIDISound(inLabel, 20, 20)

    // Start the sound if necessary, based on current time
    set ToD = GetTimeOfDay()
    if (ToD >= bj_TOD_DAWN and ToD < bj_TOD_DUSK) then
        call StartSound(bj_dayAmbientSound)
    endif
endfunction
The first issue is the line " local real ToD" because the game creates a real handle only for the local player.
The second issue is the creation of a sound object ifor the local player only in the line " set bj_dayAmbientSound = CreateMIDISound(inLabel, 20, 20)"

You could create the variable outside the local player test (first create a global sound variable called Ambient for example) :
  • Actions
    • Custom script: set udg_Ambient= CreateMIDISound(""LordaeronSummerDayl", 20, 20)
and then inside the local player test :

  • Actions
    • Custom script: call StartSound(udg_Ambient)
Then use the same method for the nighttime ambient sound.
 
Level 3
Joined
Dec 2, 2013
Messages
25
I tried several thing this morning, and I've found a way to do this using this :

call StartSound(bj_dayAmbientSound)

it doesn't desync now !

EDIT : Damn I should press F5 more often ^^

Anyway StartSound works.

Thank you guys
 
Status
Not open for further replies.
Top