Sound Every 2 kills

Status
Not open for further replies.
Level 4
Joined
Sep 15, 2013
Messages
53
I already have a working system that plays a unit response every time it kills a unit. Now.. Is it possible to only play it every 2nd kill? After the 2nd kill, it will reset its counter and wait for the 2nd kill again to play the sound. Hope somebody can help me.
 
Level 2
Joined
Apr 13, 2018
Messages
14
Hmm... If I understand you correctly, then you just have to use a counter and a boolean.

Increment the kill counter every unit kill, then check if it's equal to 2. If it is, then play the sound, then reset the counter to 0.

But this only works for one unit though, it's not exactly MUI yet. But based on what you're saying, I think the active killer is only the same one unit.
 
Level 4
Joined
Sep 15, 2013
Messages
53
How can i reset the counter? I intended this system to apply for all heroes.. Do I need to use MUI?
 
Level 2
Joined
Apr 13, 2018
Messages
14
Well, in simple terms

  • If - Counter is Greater than 2
  • Then -
  • Set Counter = 0
If you're going to apply it to every hero, then perhaps just turn the counter variable into an array, adding in each hero to that list and checking if that specific counter has reached 2.

I don't know a simpler way to do this at the moment, but it does share some similarities with an MUI system. You just have to be creative with your counters :)
 
Level 2
Joined
Apr 13, 2018
Messages
14
Another solution is to not reset the counter and instead use modulo to fire it off at a certain frequency.

counter mod 2 == 0 will fire every time counter is a multiple of 2, or every two counts.

Can you tell me if I get this right:

Modulo returns the remainder of the expression, so to check if the counter has a 0 remainder for that specific count, we check
  • If Counter mod 2 == 0
  • Then -
  • Do Stuff
  • Counter = Counter + 1
?
 
Level 4
Joined
Sep 15, 2013
Messages
53
  • Untitled Trigger 004
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is A Hero) Equal to False
      • ((Dying unit) is A structure) Equal to False
      • ((Owner of (Killing unit)) is an enemy of (Owner of (Dying unit))) Equal to True
    • Actions
      • Set killcount = (killcount + 1.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (killcount mod 2.00) Equal to 0.00
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Killing unit)) Equal to Archmage
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of (Killing unit) using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
        • Else - Actions
Like this?

---

Tried this. But it wont work.. Anything i did wrong?
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Modulo returns the remainder of the expression, so to check if the counter has a 0 remainder for that specific count, we check
Yes that looks about right, but GUI likely calls it something different.

Modulo is technically a performance intensive operation, executing around 40 times slower than addition and 10 times slower than multiplication. However JASS is so slow it does not matter anyway.
Like this?
Should be, but using integer instead of real is recommended. This is because at large kill counts, eg someone leaving the game running for days, it might run into machine epsilon error.
 
Level 4
Joined
Sep 15, 2013
Messages
53
It worked. Thanks! I used integer array instead so that every player can record their own killcount.
 
Last edited:
Status
Not open for further replies.
Top