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

IF THEN ELSE Alternative? death splash system

Level 5
Joined
Nov 3, 2018
Messages
80
Hello everyone!
i am trying to make an death system for zergs that checks their death and spawns a gory effect but s there a way to make this trigger less complex / messy? i know its a disaster but it works i heard something about index array and array and loops for checking stuff but i couldnt find an updated tutorial on how to do it

(all my other triggers with spells that check levels for doing different things use a lot of if then else mess too :( )
i do everything in GUI mostly


1708447890395.jpeg
 
Last edited:

Remixer

Map Reviewer
Level 31
Joined
Feb 19, 2011
Messages
1,957
You could tidy it up by executing the actions only after defining the desired death sound and effect.
  • Death Explosions
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit Type A
          • (Unit-type of (Triggering unit)) Equal to Unit Type B
          • (Unit-type of (Triggering unit)) Equal to Unit Type C
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit Type A
        • Then - Actions
          • Set VariableSet Sound_Death = Death Sound A <gen>
          • Set VariableSet SpecialEffectString = Abilities\Spells\Human\DispelMagic\DeathExplosionA.mdl
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Unit Type B
            • Then - Actions
              • Set VariableSet Sound_Death = Death Sound B <gen>
              • Set VariableSet SpecialEffectString = Abilities\Spells\Human\DispelMagic\DeathExplosionB.mdl
            • Else - Actions
              • Set VariableSet Sound_Death = Death Sound C <gen>
              • Set VariableSet SpecialEffectString = Abilities\Spells\Human\DispelMagic\DeathExplosionC.mdl
      • Sound - Play Sound_Death at 100.00% volume, attached to (Triggering unit)
      • Special Effect - Create a special effect attached to the origin of (Triggering unit) using SpecialEffectString
      • Special Effect - Destroy (Last created special effect)
This works assuming you have only a few unit types this mechanic applies to. If you happen to have more then you'd want to consider defining unit-types by integer and loop through them to find the correct one and match it to sound and effect string.
I didn't include the Wait function here - what is the purpose of the wait as it might lead to issues.
 

Remixer

Map Reviewer
Level 31
Joined
Feb 19, 2011
Messages
1,957
Thank you remixer for replying , yeah i have about 23 units that have that visual effect that might work?
And each of those units have individual unique death sound and effect? 23 is quite a lot already so you might want to define the death conditions through variable indexing.

Edit:
So since you have numerous unit, sound and effects defined you might want to save them to an array on map start (like this):
  • Melee Start
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet UnitType[1] = Footman
      • Set VariableSet UnitType[2] = Knight
      • Set VariableSet UnitType[3] = Rifleman
      • Set VariableSet UnitType[4] = Mortar Team
      • Set VariableSet UnitType[5] = Flying Machine
      • Set VariableSet UnitType[6] = Gryphon Rider
      • Set VariableSet UnitType[7] = Priest
      • Set VariableSet EffectString[1] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[2] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[3] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[4] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[5] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[6] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet EffectString[7] = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Set VariableSet SoundDeath[1] = Death A
      • Set VariableSet SoundDeath[2] = Death B
      • Set VariableSet SoundDeath[3] = Death C
      • Set VariableSet SoundDeath[4] = Death D
      • Set VariableSet SoundDeath[5] = Death E
      • Set VariableSet SoundDeath[6] = Death F
      • Set VariableSet SoundDeath[7] = Death G
And then your death trigger would become much simpler and you would only need to loop through the arrays to find the match and do the correct actions:
  • Death Explosions
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Knight
          • (Unit-type of (Triggering unit)) Equal to Rifleman
          • (Unit-type of (Triggering unit)) Equal to Mortar Team
          • (Unit-type of (Triggering unit)) Equal to Flying Machine
          • (Unit-type of (Triggering unit)) Equal to Gryphon Rider
          • (Unit-type of (Triggering unit)) Equal to Priest
    • Actions
      • For each (Integer Index) from 1 to 7, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to UnitType[Index]
            • Then - Actions
              • Sound - Play SoundDeath[Index] at 100.00% volume, attached to (Triggering unit)
              • Special Effect - Create a special effect attached to the origin of (Triggering unit) using EffectString[Index]
              • Special Effect - Destroy (Last created special effect)
              • Set VariableSet SoundDeath[Index] = WarlordPissed1 <gen>
            • Else - Actions
              • Do nothing
 
Last edited:
Level 5
Joined
Nov 3, 2018
Messages
80
And each of those units have individual unique death sound and effect? 23 is quite a lot already so you might want to define the death conditions through variable indexing.
all of them have the same special effect for death but i just resize each effect or each one according to which unit died
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
Check my post above for example of array indexing the unit types.
The Array/For Loop is a good idea but you don't need or want to do this anymore:
  • Conditions
    • Or - Any (Conditions) are true
      • Conditions
        • (Unit-type of (Triggering unit)) Equal to Footman
        • (Unit-type of (Triggering unit)) Equal to Knight
        • (Unit-type of (Triggering unit)) Equal to Rifleman
        • (Unit-type of (Triggering unit)) Equal to Mortar Team
        • (Unit-type of (Triggering unit)) Equal to Flying Machine
        • (Unit-type of (Triggering unit)) Equal to Gryphon Rider
        • (Unit-type of (Triggering unit)) Equal to Priest
That's what the For Loop does for you already and is part of what makes this design great.

Also, you probably already know this but this is useless:
  • Do nothing
Also, you can add this Custom Script to the For Loop to make the Loop even more efficient:
  • Set VariableSet SoundDeath[Index] = WarlordPissed1 <gen>
  • Custom script: extitwhen true
That'll exit the loop early so we don't make anymore redundant checks.
 
Last edited:
Level 5
Joined
Nov 3, 2018
Messages
80
The Array/For Loop is a good idea but you don't need or want to do this anymore:
  • Conditions
    • Or - Any (Conditions) are true
      • Conditions
        • (Unit-type of (Triggering unit)) Equal to Footman
        • (Unit-type of (Triggering unit)) Equal to Knight
        • (Unit-type of (Triggering unit)) Equal to Rifleman
        • (Unit-type of (Triggering unit)) Equal to Mortar Team
        • (Unit-type of (Triggering unit)) Equal to Flying Machine
        • (Unit-type of (Triggering unit)) Equal to Gryphon Rider
        • (Unit-type of (Triggering unit)) Equal to Priest
That's what the For Loop does for you already and is part of what makes this design great.

Also, you probably already know this but this is useless:
  • Do nothing
Also, you can add this Custom Script to the For Loop to make the Loop even more efficient:
  • Set VariableSet SoundDeath[Index] = WarlordPissed1 <gen>
  • Custom script: extitwhen true
That'll exit the loop early so we don't make anymore redundant checks.
Thank you friend this is great!
For a hero that has multiple skills and each skill has different levels i have a HUGE ugly if then else that is kinda like the one i posted
this is all from my old map back when i was editing 5 years ago and i just got back into the scene. instead of getting comfy with what i know i want to learn and improve and this is exactly what i needed

this is my ugly skill trigger
1708456305534.png
 
Level 20
Joined
Feb 27, 2019
Messages
592
In the spirit of efficiency. Instead of checking for each unit-type one could give each unit-type an ability and only check if the dying unit has that ability. The way to do that is to check if the level of the ability is 1.
 
Top