• 🏆 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!

[General] Is it ok this function?

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
I created a function in JASS to destroy the last played sound when it finished, but when I called it the game doesn't recognize it, what I'm doing bad?, and by the way tell me if the function is good or there are better options.
JASS:
function dlps takes nothing returns nothing
    local sound s
    set s=GetLastPlayedSound()
    call WaitForSoundBJ(s,0)
    call KillSoundWhenDoneBJ(s)
endfunction
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
LastPlayedSound only works if you are using the GUI function, aka BJ function.

In fact pretty much all of those functions are bad practice to use.

For example, what's the point of using last played sound? wouldn't it be easier to just save the sound manually after being played and then use it as an argument rather than an ugly global.
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
LastPlayedSound only works if you are using the GUI function, aka BJ function.

In fact pretty much all of those functions are bad practice to use.

For example, what's the point of using last played sound? wouldn't it be easier to just save the sound manually after being played and then use it as an argument rather than an ugly global.
I'm very noob in JASS, and I don't know how to create functions that uses arguments, I followed what the tutorials of this forums tells, but I get errors.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Lua:
function Play3DSound(sndstring, soundx, soundy)
    local snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    local point = Location(soundx, soundy)
    SetSoundChannel(snd, 0)
    SetSoundDistances(snd, 600.00, 10000.00 )
    SetSoundDistanceCutoff(snd, 3000.00)
    SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    SetSoundVolume(snd, 127)
    SetSoundConeAngles(snd, 0.0, 0.0, 127)
    SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    SetSoundPitch(snd, 1.0)
    PlaySoundAtPointBJ(snd, 100, point, 0.00)
    KillSoundWhenDone(snd)
    RemoveLocation(point)
end
Here's what i'm using to play sounds in Lua. Not sure if all of this is even necessary.

It's very similar to Jass, just missing some syntax like call/set/takes nothing returns nothing.
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
Lua:
function Play3DSound(sndstring, soundx, soundy)
    local snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    local point = Location(soundx, soundy)
    SetSoundChannel(snd, 0)
    SetSoundDistances(snd, 600.00, 10000.00 )
    SetSoundDistanceCutoff(snd, 3000.00)
    SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    SetSoundVolume(snd, 127)
    SetSoundConeAngles(snd, 0.0, 0.0, 127)
    SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    SetSoundPitch(snd, 1.0)
    PlaySoundAtPointBJ(snd, 100, point, 0.00)
    KillSoundWhenDone(snd)
    RemoveLocation(point)
end
Here's what i'm using to play sounds in Lua. Not sure if all of this is even necessary.

It's very similar to Jass, just missing some syntax like call/set/takes nothing returns nothing.
Thanks but, if I don't about JASS less about Lua although it looks easier than JASS but I don't how to use that (if that is something of the recent version, I can't use it because I'm using the 1.26), can you translate it to JASS please?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Try this.
vJASS:
function Play3DSound takes string sndstring, location l returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, 600.00, 10000.00 )
    call SetSoundDistanceCutoff(snd, 3000.00)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call PlaySoundAtPointBJ(snd, 100, l, 0.00)
    call KillSoundWhenDone(snd)
    call RemoveLocation(l)
    set snd = null
    set sndstring = null
    set l = null
endfunction
Example:
  • Example
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", Location(0, 0) )
And you could add more arguments to Play3DSound() so you could modify things like volume and distance cutoff.

Some other examples of creating a Sound at the position of the Triggering Unit, the position of the Target unit of ability being cast, and the Target point of ability being cast.
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetUnitLoc(GetTriggerUnit()) )
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetUnitLoc(GetSpellTargetUnit()) )
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetSpellTargetLoc() )
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
Try this.
vJASS:
function Play3DSound takes string sndstring, location l returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, 600.00, 10000.00 )
    call SetSoundDistanceCutoff(snd, 3000.00)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call PlaySoundAtPointBJ(snd, 100, l, 0.00)
    call KillSoundWhenDone(snd)
    call RemoveLocation(l)
    set snd = null
    set sndstring = null
    set l = null
endfunction
Example:
  • Example
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", Location(0, 0) )
And you could add more arguments to Play3DSound() so you could modify things like volume and distance cutoff.

Some other examples of creating a Sound at the position of the Triggering Unit, the position of the Target unit of ability being cast, and the Target point of ability being cast.
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetUnitLoc(GetTriggerUnit()) )
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetUnitLoc(GetSpellTargetUnit()) )
  • Custom script: call Play3DSound( "Sound/Interface/SubGroupSelectionChange1.wav", GetSpellTargetLoc() )
Now I have the problem that when I called it, the editor doesn't recognize it
upload_2020-9-2_22-9-3.png


upload_2020-9-2_22-8-27.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Not sure, maybe the older version doesn't support something i'm doing in the Jass.

Try removing all of the code between "set snd" and "KillSoundWhenDone" and see if it runs.

Also, it looks like you still have the Play3DSound trigger. Make sure to delete that.

And can you show me the trigger that's using Play3DSound.
 
Level 13
Joined
May 10, 2009
Messages
868
Keep in mind that when referencing file paths directly in JASS, you need to use double backslashes (\\) instead of one.
JASS:
call Play3DSound("Sound\Interface\SubGroupSelectionChange1.wav", Location(0, 0))
turns into
JASS:
call Play3DSound("Sound\\Interface\\SubGroupSelectionChange1.wav", Location(0, 0))
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Keep in mind that when referencing file paths directly in JASS, you need to use double backslashes (\\) instead of one.
JASS:
call Play3DSound("Sound\Interface\SubGroupSelectionChange1.wav", Location(0, 0))
turns into
JASS:
call Play3DSound("Sound\\Interface\\SubGroupSelectionChange1.wav", Location(0, 0))
It was actually working in my tests without the double slashes, oddly enough.

At least for: Sound/Interface/SubGroupSelectionChange1.wav
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
I test again in a new map doing:
Not sure, maybe the older version doesn't support something i'm doing in the Jass.

Try removing all of the code between "set snd" and "KillSoundWhenDone" and see if it runs.

Also, it looks like you still have the Play3DSound trigger. Make sure to delete that.

And can you show me the trigger that's using Play3DSound.
And
Keep in mind that when referencing file paths directly in JASS, you need to use double backslashes (\\) instead of one.
JASS:
call Play3DSound("Sound\Interface\SubGroupSelectionChange1.wav", Location(0, 0))
turns into
JASS:
call Play3DSound("Sound\\Interface\\SubGroupSelectionChange1.wav", Location(0, 0))
And that worked, but I tried do it in my map and the map runs but don't play the sound, this is too complicate.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Looks like you're playing the sound at the center of the map:
  • Custom script: call Play3DSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav", Location(0,0))
See where it says Location(0,0), that's the coordinates for where the sound is played. I showed you examples of what you should set it to if you aren't using x/y coordinates.

Edit: Hmm, still not working though, I'll keep messing with it.
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
upload the file here
Nah, I prefer save it in my drive.
Pastebin is nice since you can send me the map privately.
Ah that's what it's for.
Looks like you're playing the sound at the center of the map:
  • Custom script: call Play3DSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav", Location(0,0))
See where it says Location(0,0), that's the coordinates for where the sound is played. I showed you examples of what you should set it to if you aren't using x/y coordinates.

Edit: Hmm, still not working though, I'll keep messing with it.
Yes, I tried that, but nothing, I see you get noticed.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
I'm working on the problem now. It's not an issue with the map.

It's working ALMOST as intended, the only issue is that you need vision of the area in which the sound is created (since it's a 3D sound). Even if I adjust it so it has a huge cutoff distance that spans the entire map, you still need to have vision of the initial point to hear the sound.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Okay, I fixed it and added some new stuff.

Here are the two functions that you want to add to your map header.
vJASS:
function Play3DSound takes string sndstring, location l, real mindist, real maxdist, real cutoff returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, mindist, maxdist)
    call SetSoundDistanceCutoff(snd, cutoff)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call SetSoundPosition(snd, GetLocationX(l), GetLocationY(l), GetLocationZ(l))
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
    set sndstring = null
endfunction

function PlayGlobalSound takes string sndstring returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, 0, 250000.00)
    call SetSoundDistanceCutoff(snd, 250000.00)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call SetSoundPosition(snd, GetLocationX(udg_GlobalSoundPoint), GetLocationY(udg_GlobalSoundPoint), 0)
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
    set sndstring = null
endfunction

You also need to create a new Point variable called GlobalSoundPoint and add this to your Map Initialization trigger (Datos de Inicio):
  • Actions
    • Set Variable GlobalSoundPoint = (Point(-8000.00, -8000.00))
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from GlobalSoundPoint to a radius of 128.00.
You'll see that the Point is set to the bottom left corner of the map (in the boundaries), this is because I needed to create Vision there for PlayGlobalSound to work. It shouldn't cause any problems since it's out of your view.


Play3DSound() will play a Sound at a Point. This works like other 3D sounds, meaning you need vision of the Point and you need to be within a certain distance of the Point to hear it.
So in your Vortice termina trigger you would do this:
  • Custom script: call Play3DSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav", udg_Locacion_Variable[62], 0, 3000, 3000)
So it takes the Sound, the Point (Location), the Minimum Distance to hear it, the Maximum Distance to hear it, and the Cutoff Distance.

PlayGlobalSound() will play a Sound for ALL players at any given time. This fixes all of the issues that Play Sound has in GUI.
  • Custom script: call PlayGlobalSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav")
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
Okay, I fixed it and added some new stuff.

Here are the two functions that you want to add to your map header.
vJASS:
function Play3DSound takes string sndstring, location l, real mindist, real maxdist, real cutoff returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, mindist, maxdist)
    call SetSoundDistanceCutoff(snd, cutoff)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call SetSoundPosition(snd, GetLocationX(l), GetLocationY(l), GetLocationZ(l))
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    call RemoveLocation(l)
    set snd = null
    set sndstring = null
    set l = null
endfunction

function PlayGlobalSound takes string sndstring returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, 0, 250000.00)
    call SetSoundDistanceCutoff(snd, 250000.00)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call SetSoundPosition(snd, GetLocationX(udg_GlobalSoundPoint), GetLocationY(udg_GlobalSoundPoint), 0)
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
    set sndstring = null
endfunction

You also need to create a new Point variable called GlobalSoundPoint and add this to your Map Initialization trigger (Datos de Inicio):
  • Actions
    • Set Variable GlobalSoundPoint = (Point(-8000.00, -8000.00))
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from GlobalSoundPoint to a radius of 128.00.
You'll see that the Point is set to the bottom left corner of the map (in the boundaries), this is because I needed to create Vision there for PlayGlobalSound to work. It shouldn't cause any problems since it's out of your view.


Play3DSound() will play a Sound at a Point. This works like other 3D sounds, meaning you need vision of the Point and you need to be within a certain distance of the Point to hear it.
So in your Vortice termina trigger you would do this:
  • Custom script: call Play3DSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav", udg_Locacion_Variable[62], 0, 3000, 3000)
So it takes the Sound, the Point (Location), the Minimum Distance to hear it, the Maximum Distance to hear it, and the Cutoff Distance.

PlayGlobalSound() will play a Sound for ALL players at any given time. This fixes all of the issues that Play Sound has in GUI.
  • Custom script: call PlayGlobalSound("Abilities\\Spells\\Human\\Flare\\FlareTarget1.wav")
Wow, that's dedication, but remember, I use 1.26, although I don't think if you know its limits, it worked well for the current version, but not for 1.26, I'm sorry, still thanks for helping.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
I feel like this should be compatible with 1.26 seeing as how I discovered the original function in a thread from like 2012, lol.

Remember, you need vision of the point that the sound is created at if you use Play3DSound.

Also, can you post your trigger that is using Play3DSound.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Yes, but when I opened your map you were doing it incorrectly. Can I see how you're doing it now?

Also, I made a mistake in the Play3DSound function, it was destroying the Point when it shouldn't have been. I updated it:
vJASS:
function Play3DSound takes string sndstring, location l, real mindist, real maxdist, real cutoff returns nothing
    local sound snd
    set snd = CreateSound(sndstring, false, true, true, 10, 10, "DefaultEAXON")
    call SetSoundChannel(snd, 0)
    call SetSoundDistances(snd, mindist, maxdist)
    call SetSoundDistanceCutoff(snd, cutoff)
    call SetSoundDuration(snd, GetSoundFileDuration(sndstring))
    call SetSoundVolume(snd, 127)
    call SetSoundConeAngles(snd, 0.0, 0.0, 127)
    call SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
    call SetSoundPitch(snd, 1.0)
    call SetSoundPosition(snd, GetLocationX(l), GetLocationY(l), GetLocationZ(l))
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
    set sndstring = null
endfunction

Edit:
I tested your map "Sonidos", were you saying that this map didn't work for you? Because it worked for me. Also, there was a weird 3rd trigger in it that wasn't doing anything, not sure why.

Unfortunate if it doesn't work :(
 
Last edited:
Status
Not open for further replies.
Top