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

Play a sound when multiple units die

Status
Not open for further replies.
Level 3
Joined
Oct 16, 2011
Messages
39
Erm..I need this trigger: Play a sound when a player kills multiple units(5) at the same time(units owned by neutral hostile)

Can anyone write this trigger? Thanks in advance
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Event: A Unit Dies

Actions -
- Set i = GetHandleId(GetKillingUnit())
- Set Kills = (Load 0 of i in Hash) + 1
- Save Kills as 0 of i in Hash
- If Kills Is greater than or equal to 5 then *Play Sound* Else Save 0 as 0 of i in Hash

Not sure if works, but should.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Checking the instant kill doesn't work. What we do, is check the number of kills the unit achieves in 0.03 seconds. That's almost "at the same time". Pay attention to the Custom scripts, they must be typed exactly as they are, otherwise the map wont run. These Custom scripts are common GUI options but converted into code to make it look better and avoid the blank "else" blocks.

To increase or reduce the number of kills for a reward just change the number five in the second trigger.
... "Custom script: if udg_Kills >= 5 then"

The actions you want to do when the unit kills that amount of units simultaneously can be anything between the red lines. You can delete those 2 comments and the game text display if you want. Whatever you place there will happen when the unit kills 5.

Custom script: if udg_Kills >= 5 then
-------- ^^ UNDER THIS YOU DO YOUR ACTIONS ^^ --------
Game - Display to (All players) the text: YOU KILLED 5!!
-------- vv OVER THIS YOU DO YOUR ACTIONS vv --------

Custom script: endif

This is efficient, non laggy, leakless.

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hash = (Last created hashtable)
  • Killer Add
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: set udg_in = GetHandleId(GetKillingUnit())
      • Set Kills = ((Load 0 of in from Hash) + 1)
      • Hashtable - Save Kills as 0 of in in Hash
      • Unit Group - Add (Killing unit) to Killers
      • Trigger - Turn on Killers <gen>
  • Killers
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Killers and do (Actions)
        • Loop - Actions
          • Custom script: set udg_in = GetHandleId(GetEnumUnit())
          • Set Kills = (Load 0 of in from Hash)
          • Custom script: if udg_Kills >= 5 then
          • -------- ^^ UNDER THIS YOU DO YOUR ACTIONS ^^ --------
          • Game - Display to (All players) the text: YOU KILLED 5!!
          • -------- vv OVER THIS YOU DO YOUR ACTIONS vv --------
          • Custom script: endif
          • Hashtable - Save 0 as 0 of in in Hash
          • Unit Group - Remove (Picked unit) from Killers
          • -------- This turns off the trigger if the Group is empty. --------
          • Custom script: if CountUnitsInGroup(udg_Killers) == 0 then
          • Custom script: call DisableTrigger( GetTriggeringTrigger())
          • Custom script: endif
In the test map I gave the peasand an absurd amount of damage and Cleave. If you kill the big ball of soldiers, you'll get the reward.

EDIT: Improved Trigger. Re-attached the map.
 

Attachments

  • MultiKill.w3x
    17.5 KB · Views: 39
Level 3
Joined
Oct 16, 2011
Messages
39
Just tested it. Man, this is amazing!!Just what I needed! Thanks a lot for the help!

edit: How can I make this system use a different action when a larger number of mobs are killed? (at 5 killed units do 1 action, at 10 killed units do another action) I tried to copy the trigger and change the custom script kill value, but it didn't work.
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
You change the conditions. This is a simple if/then/else chain.

  • Custom script: if udg_Kills >= 5 then
  • -------- Here you do your actions for 5 kills --------
  • Custom script: elseif udg_Kills >= 10 then
  • -------- Here you do your actions for 10 kills --------
  • Custom script: elseif udg_Kills >= 15 then
  • -------- And so on... --------
  • Custom script: endif
As you can see, changed the "endif" for "elseif" and when I had no more "else" actions, I "endif" it's like "Close the 'if' condition chain"

Also, if you're using more bonuses, you can't use "major than or equal to" condition, since 15 is major than 10, and 5. It would run the trigger for 5, 10, and 15. You would have to make a doble comparison: "Greater than or equal to 5 AND less than 10"

  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Number of units in Killers) Greater than 0
      • Then - Actions
        • Unit Group - Pick every unit in Killers and do (Actions)
          • Loop - Actions
            • Custom script: set udg_in = GetHandleId(GetEnumUnit())
            • Set Kills = (Load 0 of in from Hash)
            • Custom script: if udg_Kills >= 5 and udg_Kills < 10 then
            • Game - Display to (All players) the text: You killed more tha...
            • Custom script: elseif udg_Kills >= 10 and udg_Kills < 15 then
            • Game - Display to (All players) the text: You killed more tha...
            • Custom script: elseif udg_Kills >= 15 then
            • Game - Display to (All players) the text: You're the supreme ...
            • Custom script: endif
            • Hashtable - Save 0 as 0 of in in Hash
            • Unit Group - Remove (Picked unit) from Killers
      • Else - Actions
        • Trigger - Turn off (This trigger)
Notice that I made a mistake in the map triggers. I added the "If/Then/Else" to turn off the trigger inside the loop. Please, correct it and make it like in the last trigger example above (the Pick every Unit is inside the If/Then/Else that turns off the trigger if the team is empty)
 
Last edited:
Status
Not open for further replies.
Top