• 🏆 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] Custom sound when dying while holding item

Level 3
Joined
May 27, 2013
Messages
48
Pretty much what it says in the title. I want to make a trigger that plays a sound when a unit dies while holding a particular item, and only that item. I know the event is "Unit dies" and the effect is "Play Sound" but I can't seem to get the conditions worked out. Any thoughts?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
To check if a Unit has an Item or not you would use a Boolean comparison. It either has the Item (true) or doesn't (false).
  • Conditions
    • ((Dying unit) has an item of type Boots of Speed) Equal to True
Some of the functions regarding items have names and descriptions directed towards heroes despite normal units being capable of holding items as well. Don't be fooled, these will work for ANY unit that can hold an item.
 
Level 3
Joined
May 27, 2013
Messages
48
To check if a Unit has an Item or not you would use a Boolean comparison. It either has the Item (true) or doesn't (false).
  • Conditions
    • ((Dying unit) has an item of type Boots of Speed) Equal to True
Some of the functions regarding items have names and descriptions directed towards heroes despite normal units being capable of holding items as well. Don't be fooled, these will work for ANY unit that can hold an item.

Tried that. The sound wouldn't play. And I tried other conditions and the sound played then, but it played even when I didn't want it.
 
Level 12
Joined
Jan 10, 2023
Messages
191
I'm not sure if this is how it works, but is it because maybe a dead unit "doesn't have an item" or returns null on an item check if the unit is dead?
 
Level 3
Joined
May 27, 2013
Messages
48
It's not the sound. I'm just using the built in sound that the elves make when a gold mine collapses. It'll work when I tell it to play if my Gold Giant dies (a custom unit that is basically a mobile gold mine) but I can't make it work when something holing a Mine Stone (a held item that gives anything holding it the ability to be mined) runs out.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
It's not the sound. I'm just using the built in sound that the elves make when a gold mine collapses. It'll work when I tell it to play if my Gold Giant dies (a custom unit that is basically a mobile gold mine) but I can't make it work when something holing a Mine Stone (a held item that gives anything holding it the ability to be mined) runs out.
It's most likely the sound, as I tested it and confirmed that the Condition works and the trigger is running fine. My sound didn't play at first but that's because I had it on the wrong Channel.

If you don't hear the Sound but all of the other Actions work then it's obviously a Sound issue.

Although, maybe turning a Unit into a Gold Mine creates some weirdness. I highly doubt that Buildings would break the Condition but maybe?

Edit: Tested an Entangled Gold Mine and Ancient of War and both work fine. I'm on the latest patch if that matters.
 
Last edited:
Level 3
Joined
May 27, 2013
Messages
48
Tristronic: I have tested the item's ability. The holders can be mined just fine. If you are saying have the trigger check for the ability, how do I do that?

It's most likely the sound, as I tested it and confirmed that the Condition works and the trigger is running fine. My sound didn't play at first but that's because I had it on the wrong Channel.

If you don't hear the Sound but all of the other Actions work then it's obviously a Sound issue.

Although, maybe turning a Unit into a Gold Mine creates some weirdness. I highly doubt that Buildings would break the Condition but maybe?
As I said before, the sound works just fine under other conditions. There is nothing wrong with the sound. If I say "((dying unit) is a Gold Giant) equals True" it plays, but if I change it to "((dying unit) has an item of type Mine Stone) equals True" then it doesn't.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
It doesn't play the sound or the Actions don't run? It's important to make this distinction.

In my tests the Condition works fine but maybe your Mine Stone is some kind of weird exception.

You could be Removing the Unit rather than Killing it, which wouldn't fire the "A unit dies" Event.

Also, try using (Triggering unit) instead of (Dying unit).
 
Level 3
Joined
May 27, 2013
Messages
48
Like I said, it works if I limit it to "((dying unit) is a Gold Giant) equals True", so clearly it can tell when the unit dies. It's finding the item that seems to be the hard part.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
I guess whatever strange Unit you've created doesn't have a working Inventory (at least one that can be checked upon death). Instead, you can try the Acquire/Lose item Events and mark the Unit in another way.

A unit Acquires an Item -> Item = Your Item Type -> Set Custom value of (Triggering unit) to (Custom value of (Triggering unit)) + 1

A unit Loses an Item -> Item = Your Item Type -> Set Custom value of (Triggering unit) to (Custom value of (Triggering unit)) - 1

Then you can check the Custom Value of your (Dying unit), if it's > 0 then it has the Item.

I'd use a Unit Indexer instead of directly modifying Custom Value, but try this first.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
Could you possibly send me a demo map so I can play around with this bug?
  • Acquire Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to YourItem
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
  • Lose Item
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to YourItem
      • ((Triggering unit) is alive) Equal to True
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) - 1)
  • Death
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
      • (Custom value of (Triggering unit)) Greater than 0
    • Actions
      • Sound - Play No sound
Edit: The test map is missing the "Is alive" condition in the Lose Item trigger, don't forget to add that.
 

Attachments

  • Test.w3m
    16.2 KB · Views: 2
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
Your Volume is set to 0. It could also be on the wrong Effect/Channel.
1689372468658.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
It's a custom sound, I imagine the night elves use the original sound. Or perhaps you've set the volume inside of the trigger.

Anyway, I tested it after adjusting the volume and the sound plays just fine, although only one of these Sounds can play at a time due to the Channel limitations. I don't really know if there's a way around that without using 3d sounds.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
Then how come it played just fine if the trigger was linked to the Gold Giants, but not to the Mine Stone?
Then it's something to do with the unit, which is why I suggested that alternate solution using Custom Value (ideally it'd be using a Unit Indexer).

I would use that method as well as fix the volume, although I can't guarantee it'll work.

[Edit]
You'll want to make sure that the unit is alive when it loses the item:
  • Lose Item
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to YourItem
      • ((Triggering unit) is alive) Equal to True
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) - 1)
The issue was that the unit was dropping the items upon death which happened before the "A unit dies" Event occurred. So it didn't actually have the items anymore. In my previous tests I was using Inventory abilities that didn't drop items upon death so this issue didn't occur for me.
 
Last edited:
Top