• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

playsound on custom hero

Level 1
Joined
Jun 3, 2025
Messages
1
I'm trying to figure out how to randomly play a sound when clicking on a custom hero unit. Right now, when I click on the unit, two sounds play at the same time. I'm new to this and just experimenting with custom heroes and custom sound effects.
 

Attachments

  • test-hero-custom.w3m
    610.3 KB · Views: 3
Welcome to the Hive! :D

You might have better luck posting in the World Editor Help Zone next time (usually the "Requests" forum is for resource requests):

The reason it is playing two sounds with your current logic is because it first tries to play "Vereesa_What1", and then because the unit you're selecting is a hero (so it passes your "If - Condition", instead of "Skipping the remaining actions"), it'll continue with the rest of the code and play "Vereesa_What2".

It looks like you're roughly trying to use that integer variable to control which sound to play. For something like that, arrays are perfect. They're basically a special type of variable that can hold many values, each at a particular index (a number). So first, I'd recommend creating a sound array variable, e.g. VereesaSounds:
1748977992493.png

Then create a trigger with the event "Map Initialization" (so it runs just before the map starts) to set up the variable with values:
  • Sound Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet VereesaSounds[1] = Vereesa_What1 <gen>
      • Set VariableSet VereesaSounds[2] = Vereesa_What2 <gen>
      • Set VariableSet VereesaSounds[3] = Vereesa_What3 <gen>
Finally, you can update your trigger to play a random sound by simply using "Sound - Play Sound", choosing that variable, and then using "Math - Random" to select a random index between 1 and 3:
  • RandomClickHero1
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to bolapi
    • Actions
      • Sound - Play VereesaSounds[(Random integer number between 1 and 3)]
I'll attach the map below (but I'm using the latest patch, so it may not open for you if you're running on an older patch).



However, for custom sound-sets, it's usually recommended to replace an existing sound set and use that instead. That way you get all the default wc3 sound behavior for free (e.g. selection sounds, "yes" sounds, attack sounds, etc.). To do that:
  1. Open the sound editor
  2. Find a sound-set that you're unlikely to use, e.g. "Units/Human/KnightNoRider" or "Units/Naga/NagaMyrmidon". You'll usually want to use one that has a similar number of sounds as you have.
  3. Right-click a sound, e.g. KnightNoRiderWhat1.flac, and replace it with your sound (e.g. Vereesa_What1.wav). You'll need to select it from your hard drive. If it gives you an error saying that file already exists, then I recommend deleting the sound from the import manager and then going back to the sound editor to try again.
    1748982139311.png
  4. Once you've replaced the sound, double-click the sound (or right-click -> play) to make sure it plays the sound you expect.
  5. Once you're done replacing all the sounds, go to the unit in the object editor and update its sound set to the one you replaced, e.g. KnightNoRider.
Usually that is the recommended route over using triggers. With triggers, it is hard to get it to behave exactly like the native wc3 set-up for all those weird edge cases (e.g. when a unit is selected as part of a group but isn't the "primary" selection, it shouldn't play the sound).
 

Attachments

  • test-hero-custom.w3m
    1.4 MB · Views: 2
Top