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

[Trigger] Loop Animation Spawn Unit MUI/MPI

Status
Not open for further replies.
Level 2
Joined
Dec 19, 2015
Messages
12
I am not too experienced writing MUI/MPI so I knew I would have trouble with making a spell for multiple players or units.

The ability is really simple but I can't get my head around the whole MUI/MPI concept.

Once you cast an ability on the unit, a loop will start which will make the targeted unit of the ability play the death animation. The casting unit will also play the attack animation. There is a integer counter for up to 15 times that this animation plays through. Once it reaches 15, it will spawn a unit and it will turn off the trigger.

  • Make a Baby
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Make a Baby
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Target unit of ability being cast)) Equal to Village Wife
          • (Owner of (Target unit of ability being cast)) Equal to (Owner of (Triggering unit))
        • Then - Actions
          • Set MUI = (MUI + 1)
          • Set Make_a_Baby_Caster[MUI] = (Triggering unit)
          • Set Wife_Unit[MUI] = (Target unit of ability being cast)
          • Set Make_a_Baby_Count[MUI] = 0
          • Set RandomInteger[MUI] = (Random integer number between 1 and 10)
          • Trigger - Turn on Make a Baby Loop <gen>
        • Else - Actions


  • Make a Baby Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer MUI) from 1 to 11, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[MUI] Less than 15
            • Then - Actions
              • Set Make_a_Baby_Count[MUI] = (Make_a_Baby_Count[MUI] + 1)
              • Animation - Play Make_a_Baby_Caster[MUI]'s attack animation
              • Animation - Play Wife_Unit[MUI]'s death animation
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[MUI] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
              • Trigger - Turn off (This trigger)

I did make this trigger before with hashtables, but that was just purely messing around and not knowing what I was actually doing. Using indexing is more understandable for me, for right now. (I don't have the hashtable version of this trigger, it got deleted a while ago from losing my map.)

(I did look up a bunch of tutorials on MUI by the way. They helped some but as you can see I am still having trouble.)

I just need help with this one trigger and I am sure I will understand how to make more MUI triggers.

Thanks a lot guys.
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
you should not use for each (integer MUI) from 1 to 11
-->
for each (integer YourIntegerVar) from 1 to MUI

you also need to deindex an instance when its finished, otherwise you will permanently loop through the instance.
you do this by saving the fields of the last created instance (=MUI) into the the fields of the last deindexed/finished instance, and then reduce MUI by 1 (and also YourIntegerVar)

EDIT: your loop trigger turns off everytime an instance is "finished", that will cause bugs, you need to turn it off if MUI is equal to 0
 
Level 2
Joined
Dec 19, 2015
Messages
12
I don't quite understand how you deindex an instance.

This is what I thought you were talking about:

  • Make a Baby
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Make a Baby
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Target unit of ability being cast)) Equal to Village Wife
          • (Owner of (Target unit of ability being cast)) Equal to (Owner of (Triggering unit))
        • Then - Actions
          • Set MUI = (MUI + 1)
          • Set Make_a_Baby_Caster[MUI] = (Triggering unit)
          • Set Wife_Unit[MUI] = (Target unit of ability being cast)
          • Set Make_a_Baby_Count[MUI] = 0
          • Set RandomInteger[MUI] = (Random integer number between 1 and 10)
          • Trigger - Turn on Make a Baby Loop <gen>
        • Else - Actions


  • Make a Baby Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[MUI] Less than 15
            • Then - Actions
              • Animation - Play Make_a_Baby_Caster[MUI]'s attack animation
              • Animation - Play Wife_Unit[MUI]'s death animation
              • Set Make_a_Baby_Count[MUI] = (Make_a_Baby_Count[MUI] + 1)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[MUI] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions

I am not sure if I did this correctly or not.

Edit: It kind of works, the only problem is when more than one unit uses the ability at the same time, it stops the process of loop one so that loop two can finish and then after loop two finishes, loop one proceeds and finishes.
 
Last edited:
Level 17
Joined
Mar 21, 2011
Messages
1,597
you need to use Variable[Loop_Make_a_Baby] instead of Variable[MUI]
for deindexing you do:
set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
...
do that with every variable
and then do
set MUI = MUI - 1
set Loop_Make_a_Baby = Loop_Make_a_Baby - 1
 
Level 2
Joined
Dec 19, 2015
Messages
12
I think I am getting really close.

Both units can execute the trigger but the only problem is that both units that spawn, they both spawn at one wife unit.

I didn't change anything with the first trigger which is why I didn't post it here.

  • Make a Baby Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
      • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[Loop_Make_a_Baby] Less than 15
            • Then - Actions
              • Animation - Play Make_a_Baby_Caster[Loop_Make_a_Baby]'s attack animation
              • Animation - Play Wife_Unit[Loop_Make_a_Baby]'s death animation
              • Set Make_a_Baby_Count[Loop_Make_a_Baby] = (Make_a_Baby_Count[Loop_Make_a_Baby] + 1)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[Loop_Make_a_Baby] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
              • Game - Display to (All players) the text: Trigger start,
              • Trigger - Turn on Baby Grows up <gen>
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
I tried putting: set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]

inside the loop, but that wasn't working.


Edit: So this updated trigger apparently works other than the fact that all instances end at the same time. I was just messing with the trigger and indexes because it wasn't working how I wanted it to and this is what I came up with.

  • Make a Baby Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[Loop_Make_a_Baby] Less than 15
            • Then - Actions
              • Animation - Play Make_a_Baby_Caster[Loop_Make_a_Baby]'s attack animation
              • Animation - Play Wife_Unit[Loop_Make_a_Baby]'s death animation
              • Set Make_a_Baby_Count[Loop_Make_a_Baby] = (Make_a_Baby_Count[Loop_Make_a_Baby] + 1)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[MUI] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
              • Game - Display to (All players) the text: Trigger start,
              • Trigger - Turn on Baby Grows up <gen>
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
      • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
      • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]

This part confused me: (Owner of Make_a_Baby_Caster[MUI]) at (Position of Wife_Unit[MUI]) facing Default building facing degrees

I have no idea if that's even correct. Because I thought all variables are supposed to have Loop_Make_a_Baby and not MUI for the index.


Edit 2: This is what I have so far.

  • Make a Baby
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Make a Baby
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Target unit of ability being cast)) Equal to Village Wife
          • (Owner of (Target unit of ability being cast)) Equal to (Owner of (Triggering unit))
        • Then - Actions
          • Set MUI = (MUI + 1)
          • Set Make_a_Baby_Caster[MUI] = (Triggering unit)
          • Set Wife_Unit[MUI] = (Target unit of ability being cast)
          • Set Make_a_Baby_Count[MUI] = 0
          • Set RandomInteger[MUI] = (Random integer number between 1 and 10)
          • Trigger - Turn on Make a Baby Loop <gen>
        • Else - Actions


  • Make a Baby Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[Loop_Make_a_Baby] Less than 15
            • Then - Actions
              • Animation - Play Make_a_Baby_Caster[Loop_Make_a_Baby]'s attack animation
              • Animation - Play Wife_Unit[Loop_Make_a_Baby]'s death animation
              • Set Make_a_Baby_Count[Loop_Make_a_Baby] = (Make_a_Baby_Count[Loop_Make_a_Baby] + 1)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[Loop_Make_a_Baby] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
                  • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
                  • Set Babies_Total = (Babies_Total + 1)
                  • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
                  • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
                  • Set MUI = (MUI - 1)
                  • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
              • Game - Display to (All players) the text: Trigger start,
              • Trigger - Turn on Baby Grows up <gen>
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI Equal to 0
                • Then - Actions
                  • Game - Display to (All players) the text: Make a baby end.
                  • Trigger - Turn off (This trigger)
                • Else - Actions
I still don't know what I am doing wrong.
 
Last edited:
Level 17
Joined
Mar 21, 2011
Messages
1,597
  • Loop
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • Set Make_a_Baby_Count[Loop_Make_a_Baby] = (Make_a_Baby_Count[Loop_Make_a_Baby] + 1)
          • Animation - Play Make_a_Baby_Caster[Loop_Make_a_Baby]'s attack animation
          • Animation - Play Wife_Unit[Loop_Make_a_Baby]'s death animation
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[Loop_Make_a_Baby] equal to 15
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[Loop_Make_a_Baby] smaller or equal to 5
                • Then - Actions
                  • Unit - Create ....
                • Else - Actions
                  • Unit - Create ....
              • Set Babies_Total = (Babies_Total + 1)
              • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
              • Set Make_a_Baby_Caster[MUI] = no unit
              • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
              • Set Wife_Unit[MUI] = no unit
              • Set Make_a_Baby_Count[Loop_Make_a_Baby] = Make_a_Baby_Count[MUI]
              • Set RandomInteger[Loop_Make_a_Baby] = RandomInteger[MUI]
              • Set MUI = (MUI - 1)
              • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
try this, i hope i didnt make any mistake. I didnt have an editor.
 
Level 2
Joined
Dec 19, 2015
Messages
12
It works perfectly now, thank you.

I am only confused about the deindexing. You said if you don't deindex your instances, it will forever loop? Someone on a website said you have to Null the variable values when the trigger is finished, is that the same as deindexing?
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
example:
3 units cast your spells (not at the same time, but with a small offset)

Instance 1:
Caster[1] = bla
Target[1] = bla
Time[1] = 2

Instance 2:
Caster[2] = bla
Target[2] = bla
Time[2] = 5

Instance 3:
Caster[3] = bla
Target[3] = bla
Time[3] = 1

Now, if the 2nd instance finishes, we need to recycle it. how do we do that? if we just null all the variables of the 2nd instance, it will look like this:

Instance 1:
Caster[1] = bla
Target[1] = bla
Time[1] = 2

Instance 2:
Caster[2] = null
Target[2] = null
Time[2] = 0

Instance 3:
Caster[3] = bla
Target[3] = bla
Time[3] = 1

however, this will never get recycled, and because of the maximum array size of 8192, we could reach a limit (also, you loop through empty instances)
what to do: we want to save the latest instance (in this case instance 3) into the instance that we nulled (the 2nd) because there is a free space now. we also null the latest instance.

Instance 1:
Caster[1] = bla
Target[1] = bla
Time[1] = 2

Instance 2:
Caster[2] = bla
Target[2] = bla
Time[2] = 1

Instance 3:
Caster[3] = null
Target[3] = null
Time[3] = 0

now, you can save the next instance into 3 and you can continue your loop without any empty instances.
 
Level 2
Joined
Dec 19, 2015
Messages
12
I think I understand now.

Also, the debug message of "Make a baby end." doesn't execute at the bottom of the trigger.

  • Make a Baby Loop
    • Events
      • Time - Every 0.40 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop_Make_a_Baby) from 1 to MUI, do (Actions)
        • Loop - Actions
          • Set Make_a_Baby_Count[Loop_Make_a_Baby] = (Make_a_Baby_Count[Loop_Make_a_Baby] + 1)
          • Animation - Play Make_a_Baby_Caster[Loop_Make_a_Baby]'s attack animation
          • Animation - Play Wife_Unit[Loop_Make_a_Baby]'s death animation
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Make_a_Baby_Count[Loop_Make_a_Baby] Greater than or equal to 15
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInteger[Loop_Make_a_Baby] Less than or equal to 5
                • Then - Actions
                  • Unit - Create 1 Baby Boy for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
                • Else - Actions
                  • Unit - Create 1 Baby Girl for (Owner of Make_a_Baby_Caster[Loop_Make_a_Baby]) at (Position of Wife_Unit[Loop_Make_a_Baby]) facing Default building facing degrees
              • Set Babies_Total = (Babies_Total + 1)
              • Set Make_a_Baby_Caster[Loop_Make_a_Baby] = Make_a_Baby_Caster[MUI]
              • Set Make_a_Baby_Caster[MUI] = No unit
              • Set Wife_Unit[Loop_Make_a_Baby] = Wife_Unit[MUI]
              • Set Wife_Unit[MUI] = No unit
              • Set Make_a_Baby_Count[Loop_Make_a_Baby] = Make_a_Baby_Count[MUI]
              • Set RandomInteger[Loop_Make_a_Baby] = RandomInteger[MUI]
              • Set MUI = (MUI - 1)
              • Set Loop_Make_a_Baby = (Loop_Make_a_Baby - 1)
            • Else - Actions
              • Game - Display to (All players) the text: Trigger start,
              • Trigger - Turn on Baby Grows up <gen>
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MUI Equal to 0
                • Then - Actions
                  • Game - Display to (All players) for 30.00 seconds the text: Make a baby end.
                  • Trigger - Turn off (This trigger)
                • Else - Actions
 
Status
Not open for further replies.
Top