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

How to play sound for one (or two) player(s)

Status
Not open for further replies.
Level 5
Joined
Jun 12, 2018
Messages
148
You could use a trigger like this :

  • Play sound at location
    • Events
    • Conditions
    • Actions
      • Set tempPoint = (Position of myLocation)
      • Player Group - Pick every player in myPlayers and do (Actions)
        • Loop - Actions
          • Sound - Play mySound at 100.00% volume, located at tempPoint with Z offset 0.00
      • Custom script: call RemoveLocation(udg_tempPoint)
 
Level 5
Joined
Aug 16, 2018
Messages
39
You could use a trigger like this :

  • Play sound at location
    • Events
    • Conditions
    • Actions
      • Set tempPoint = (Position of myLocation)
      • Player Group - Pick every player in myPlayers and do (Actions)
        • Loop - Actions
          • Sound - Play mySound at 100.00% volume, located at tempPoint with Z offset 0.00
      • Custom script: call RemoveLocation(udg_tempPoint)
I tryed that but it was not what I wanted.
 
Level 5
Joined
Aug 16, 2018
Messages
39
Custom script: if GetLocalPlayer() == Player (0)
Sound - Play (Sound)
Custom script: endif

-----------------------

Player(0) means Player Red in this example.
I tried that but i get this
Screenshot (31).png
What am I doing wrong?
 
Level 5
Joined
Jun 12, 2018
Messages
148
What do you exactly want to achieve ?

My previous code means to play a sound for a group of players at a specific location, what do you want more ?

Edit : For the other code I think there is a "then" missing, correct line would be
  • Custom script: if GetLocalPlayer() == Player (0) then
 
Level 10
Joined
Apr 4, 2010
Messages
286
This is kind of basic but just in case it's new to you: In the Sound Editor, you need to set whether the sound is marked as 3D or not.

If it's a 3D sound -> It has to be played on a location, it won't play otherwise.
If it's not a 3D sound -> It has to be played normally (not on a location), it won't play on a location.

So Step 1, mark it 3D or not based on how you want to play it.
Step 2, have your trigger play it (on a location or not) based on whether it's 3D.
 
Level 5
Joined
Jun 12, 2018
Messages
148
What want the sound to start playing when someone enters a location not at the location. sorry

Ehm, why don't you just change tempPoint variable to :

  • Set tempPoint = (Position of (Triggering Unit))
This works assuming you did what @JackKessler said on his post.
 
Level 5
Joined
Aug 16, 2018
Messages
39
In order to do it for teams you have to set the sound for the players you want it to playe for. EXAMPLE: player 1 would be this
Screenshot (32).png
And player 2 would be somthing like this
Screenshot (33).png
and remember to put custom script: endif

That's how I know to do it, it may take time but it works.
If there's an easyer way feel free to tell me.
 
Level 5
Joined
Jun 12, 2018
Messages
148
This is not really how it should be done in my opinion.It is painful to develop, if you want to add one condition or action in the future you will have to manually copy everything for every trigger.

Besides, you are playing a sound for everyone here and you wanted to play a sound only for a team.

You should pick a sound in the Sound Editor -> Right Clic -> "Use as sound" and check "3D sound" is enabled.

A trigger that plays a sound for a every player in a team when a unit from this team enters the region may be :

  • Play sound for a team
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set tempLocation = (Position of (Triggering unit))
      • Player Group - Pick every player in (All players matching (((Owner of (Triggering unit)) Equals to (Matching player)) or (((Triggering unit) belongs to an ally of (Matching player)) Equals to TRUE))) and do (Actions)
        • Loop - Actions
          • Custom script: if (GetLocalPlayer() == GetEnumPlayer()) then
          • Sound - Play CUSTOM_SOUND at 100.00% volume, located at tempLocation with Z offset 0.00
          • Custom script: endif
      • Custom script: call RemoveLocation(udg_tempLocation)
When you are using the "Sound - Play" function alone, it will play the sound for everyone.

Tell me if this clear for you :)
 
Last edited:
Level 5
Joined
Aug 16, 2018
Messages
39
This is not really how it should be done in my opinion.It is painful to develop, if you want to add one condition or action in the future you will have to manually copy everything for every trigger.

Besides, you are playing a sound for everyone here and you wanted to play a sound only for a team.

You should pick a sound in the Sound Editor -> Right Clic -> "Use as sound" and check "3D sound" is enabled.

A trigger that plays a sound for a every player in a team when a unit from this team enters the region may be :

  • Play sound for a team
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set tempLocation = (Position of (Triggering unit))
      • Player Group - Pick every player in (All players matching (((Owner of (Triggering unit)) Equals to (Matching player)) or (((Triggering unit) belongs to an ally of (Matching player)) Equals to TRUE))) and do (Actions)
        • Loop - Actions
          • Sound - Play CUSTOM_SOUND at 100.00% volume, located at tempLocation with Z offset 0.00
      • Custom script: call RemoveLocation(udg_tempLocation)
When you are using the "Sound - Play" function alone, it will play the sound for everyone.

Tell me if this clear for you :)
Yes it's clear. I was about to post another reply on how to do it for all players at the same time, but this way is better and more orginized.
Thanks. But I wont use a 3d sound or that trigger FYI
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
This is not really how it should be done in my opinion.It is painful to develop, if you want to add one condition or action in the future you will have to manually copy everything for every trigger.

Besides, you are playing a sound for everyone here and you wanted to play a sound only for a team.

You should pick a sound in the Sound Editor -> Right Clic -> "Use as sound" and check "3D sound" is enabled.

A trigger that plays a sound for a every player in a team when a unit from this team enters the region may be :

  • Play sound for a team
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Set tempLocation = (Position of (Triggering unit))
      • Player Group - Pick every player in (All players matching (((Owner of (Triggering unit)) Equals to (Matching player)) or (((Triggering unit) belongs to an ally of (Matching player)) Equals to TRUE))) and do (Actions)
        • Loop - Actions
          • Sound - Play CUSTOM_SOUND at 100.00% volume, located at tempLocation with Z offset 0.00
      • Custom script: call RemoveLocation(udg_tempLocation)
When you are using the "Sound - Play" function alone, it will play the sound for everyone.

Tell me if this clear for you :)

I think you forgot GetLocalPlayer usage here, since Player Group stuff is pointless and you just play same sound at same position N times, and to all players.
 
Level 5
Joined
Jun 12, 2018
Messages
148
This should make the trick, this solution only implies a simple trigger.

  • Play sound for a team
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equals to TRUE
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • -------- Play a simple sound for the owner of the unit and his team --------
      • Player Group - Pick every player in (All players matching (((Owner of (Triggering unit)) Equals to (Matching player)) or (((Triggering unit) belongs to an ally of (Matching player)) Equals to TRUE))) and do (Actions)
        • Loop - Actions
          • Custom script: if (GetLocalPlayer() == GetEnumPlayer()) then
          • Sound - Play YOUR_SOUND <gen>
          • Custom script: endif
I think you forgot GetLocalPlayer usage here, since Player Group stuff is pointless and you just play same sound at same position N times, and to all players.

Yes indeed, I've fixed the previous code
 
Status
Not open for further replies.
Top