• 🏆 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] Having trouble with MUI

Status
Not open for further replies.
Level 10
Joined
Apr 4, 2010
Messages
509
[Solved] Having trouble with MUI

How this trigger is meant to work is, when a chicken dies, a wisp spawns from where the chicken died. Then more wisp spawn around the first wisp, the first wisp that spawned is the leader and all the other wisp follow the leader. If 60% of the followers die, then the leader dies. If the leader dies, then all the followers die.

The problem that I'm having is when I kill two chickens, the followers of the leader wisp of the first dead chicken abandon their leader to follow the newly spawned leader wisp. Also when the leader dies, the follows don't die and vice versa. I'm really bad at this MUI Indexing stuff let alone GUI, I really need this to work to complete my map. Please help. :goblin_cry:

  • Chunks
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Chicken
    • Actions
      • Set Chunks_Index = (Chunks_Index + 1)
      • Set Chunks_Unit_DeathTrigger[Chunks_Index] = (Dying unit)
      • Set Chunks_Summon_Point[Chunks_Index] = (Position of (Dying unit))
      • Unit - Create 1 Peasant for (Owner of Chunks_Unit_DeathTrigger[Chunks_Index]) at Chunks_Summon_Point[Chunks_Index] facing Default building facing degrees
      • Set Chunks_Core[Chunks_Index] = (Last created unit)
      • For each (Integer Chunks_Spawn_Loop_Integer) from 1 to 15, do (Actions)
        • Loop - Actions
          • Set Chunks_Random_Spawn = ((Position of Chunks_Core[Chunks_Index]) offset by 100.00 towards (Random angle) degrees)
          • Set Chunk_Follow_Index = (Chunk_Follow_Index + 1)
          • Unit - Create 1 Peasant for (Owner of Chunks_Core[Chunks_Index]) at Chunks_Random_Spawn facing Default building facing degrees
          • Set Chunk_Followers[Chunk_Follow_Index] = (Last created unit)
          • Unit Group - Add (Last created unit) to Chunks_TempGroup
          • Custom script: call RemoveLocation (udg_Chunks_Random_Spawn)
      • Set Chunks_Particle_Group[Chunks_Index] = Chunks_TempGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chunks_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Chunks Move <gen>
        • Else - Actions
      • Custom script: call DestroyGroup (udg_Chunks_TempGroup)
  • Chunks Move
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Chunks_Core[Chunks_Index] is dead) Equal to True
        • Then - Actions
          • For each (Integer Chunks_Loop_Integer) from 1 to Chunk_Follow_Index, do (Actions)
            • Loop - Actions
              • Unit Group - Pick every unit in Chunks_Particle_Group[Chunks_Loop_Integer] and do (Unit - Kill (Picked unit))
          • Set Chunks_Index = (Chunks_Index - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Chunks_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
            • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Chunks_Particle_Group[Chunks_Index]) Less than or equal to ((Number of units in Chunks_Particle_Group[Chunks_Index]) - 5)
        • Then - Actions
          • For each (Integer Chunks_Loop_Integer) from 1 to Chunk_Follow_Index, do (Actions)
            • Loop - Actions
              • Unit Group - Pick every unit in Chunks_Particle_Group[Chunks_Loop_Integer] and do (Unit - Kill (Picked unit))
          • For each (Integer Chunks_Loop_Integer) from 1 to Chunks_Index, do (Actions)
            • Loop - Actions
              • Unit - Kill Chunks_Core[Chunks_Index]
          • Set Chunks_Index = (Chunks_Index - 1)
          • Set Chunk_Follow_Index = (Chunk_Follow_Index - Chunk_Follow_Index)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Chunk_Follow_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
            • Else - Actions
        • Else - Actions
      • For each (Integer Chunks_Loop_Integer) from 1 to Chunk_Follow_Index, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Chunk_Followers[Chunks_Loop_Integer] is dead) Equal to True
            • Then - Actions
              • Unit Group - Remove Chunk_Followers[Chunks_Loop_Integer] from Chunks_Particle_Group[Chunks_Loop_Integer]
            • Else - Actions
          • Set Chunks_Random_Move = (((Position of Chunks_Core[Chunks_Index]) offset by 75.00 towards (Facing of Chunks_Core[Chunks_Index]) degrees) offset by (Random real number between 20.00 and 100.00) towards (Random angle) degrees)
          • Unit - Order Chunk_Followers[Chunks_Loop_Integer] to Attack-Move To Chunks_Random_Move
          • Custom script: call RemoveLocation (udg_Chunks_Random_Move)
 

Attachments

  • Locust Swarm Test v1.w3x
    23.1 KB · Views: 39
Last edited:
Not sure if this is the main issue, but you're destroying Chunks_TempGroup. When you assign Chunks_Particle_Group to Chunks_TempGroup, you aren't copying the group. You're just making the two variables point to the same object in memory. So when you destroy Chunks_TempGroup at the end of the function, you are also destroying Chunks_Particle_Group.

As such, you only need to use DestroyGroup() when your spell is finished (i.e. when you reduce Chunks_Index - 1).
 
Level 10
Joined
Apr 4, 2010
Messages
509
Oh, right. I just fixed that but it's still having the same issue. The Chunks_Core is being overridden and I don't know what to do. I've been looking at your Dynamic Indexing tutorial actually to try and help me make this work, but I have Units following a Unit and I don't know how to accomplish that. I hope you can download the map and have a fiddle around.
 
It is a bit weird. In your second trigger, you are using Chunks_Loop_Integer outside of the looping portion. That is probably why it follows the wrong unit.

But let me propose a better design. You'll have two main pieces of data per chicken death: (1) a leader (2) a unit group filled with all the follower wisps.

The setup trigger is trivial--it is mostly just setting up the dummies. Let's construct that real quick:
  • Chunks
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Chicken
    • Actions
      • Set Chunks_Index = (Chunks_Index + 1)
      • Set Chunks_Point = (Position of (Dying unit))
      • Unit - Create 1 Peasant for (Triggering player) at Chunks_Point facing Default building facing degrees
      • Set Chunks_Core[Chunks_Index] = (Last created unit)
      • Custom script: if udg_Chunks_Particle_Group[udg_ChunksIndex] == null then
      • Custom script: set udg_Chunks_Particle_Group[udg_ChunksIndex] = CreateGroup()
      • Custom script: endif
      • For each (Integer Chunks_Spawn_Loop_Integer) from 1 to 15, do (Actions)
        • Loop - Actions
          • Set Chunks_Random_Spawn = (Chunks_Point offset by 100.00 towards (Random angle) degrees)
          • Unit - Create 1 Peasant for (Triggering player) at Chunks_Random_Spawn facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Chunks_Particle_Group[ChunksIndex]
          • Custom script: call RemoveLocation(udg_Chunks_Random_Spawn)
      • Custom script: call RemoveLocation(udg_Chunks_Point)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chunks_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Chunks Move <gen>

Let me explain what's going on. This trigger creates the wisp, then it creates all 15 followers and adds them to a group. Both the main unit and the unit group are stored within the array (so we can use them in the other trigger).

The confusing part may come at the custom scripts--the first chunk (the if/then statement) is just to create the group if necessary. When you create a group array in the variable editor, the editor asks for a "size" argument. This determines how many empty unit groups are created in the array by default. By adding the if/then statements, I'll create the unit group if the editor hasn't done so already. The other custom scripts (RemoveLocation) are just to get rid of the location leaks.

Next, we'll move on to the main periodic trigger. We want to loop through each "leader" and its corresponding group and determine whether they should be killed or issued a move order:
  • Chunks Move
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Chunks_Loop_Integer) from 1 to Chunks_Index, do (Actions)
        • Loop - Actions
          • Set Chunks_Point = (Position of Chunks_Core[Chunks_Loop_Integer])
          • Set Chunks_Count = 0
          • Unit Group - Pick every unit in Chunks_Particle_Group[Chunks_Loop_Integer] and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is dead) Equal to True
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from Chunks_Particle_Group[Chunks_Loop_Integer]
                • Else - Actions
                  • Set Chunks_Count = (Chunks_Count + 1)
                  • Set Chunks_Random_Move = Chunks_Point offset by 75.00 towards (Facing of Chunks_Core[Chunks_Loop_Integer]) degrees) offset by (Random real number between 20.00 and 100.00) towards (Random angle) degrees
                  • Unit - Order (Picked unit) to Attack-Move to Chunks_Random_Move
                  • Custom script: call RemoveLocation(udg_Chunks_Random_Move)
          • Custom script: call RemoveLocation(udg_Chunks_Point)
          • If (All Conditions are True) then do (Then Actions) else do (Else actions)
            • If - Conditions
              • Or - Any conditions are true
                • Chunks_Count is Less than or Equal to 6
                • (Chunks_Core[Chunks_Loop_Integer] is dead) Equal to True
            • Then - Actions
              • Unit - Kill Chunks_Core[Chunks_Loop_Integer]
              • Unit Group - Pick every unit in Chunks_Particle_Group[Chunks_Loop_Integer] and do (Unit - Kill (Picked unit))
              • Custom script: call DestroyGroup(udg_Chunks_Particle_Group[udg_Chunks_Loop_Integer])
              • Custom script: set udg_Chunks_Particle_Group[udg_Chunks_Loop_Integer] = null
              • Set Chunks_Core[Chunks_Loop_Integer] = Chunks_Core[Chunks_Index]
              • Set Chunks_Particle_Group[Chunks_Loop_Integer] = Chunks_Particle_Group[Chunks_Index]
              • Set Chunks_Index = Chunks_Index - 1
              • Set Chunks_Loop_Integer = Chunks_Loop_Integer - 1
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Chunks_Index Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions

This trigger is the tough part to grasp. I recommend rereading my tutorial if you feel lost in what's going on. I'm only going to cover the rough idea of what this trigger should accomplish. (Note that the triggers above were just written freehand so they are bound to have errors)

Going back to the setup trigger, we start off by creating all our "instances" of the spell. In the timer trigger, we loop through each "instance", hence the "For each..." loop that contains all the code. Chunks_Core[Chunks_Loop_Integer] will be the current leader wisp we are dealing with, and Chunks_Particle_Group[Chunks_Loop_Integer] will be the corresponding follower group for that particular instance.

The first half of the code does unit group management:
  • Is the follower dead? If so, remove him from the group.
  • Otherwise, order him to attack-move to a random location nearby the leader.

The latter half of the code determines if we need to end the current instance (i.e. are 60% (9) of the followers dead? or is the leader dead?) If so, it kills the leader and all the followers. Then it performs deindexing (see the tutorial if you're confused about this), and it removes this instance from the timer.

I may not have grasped 100% of the functionality you wanted (and I didn't test it, so it might not work). But it seems correct in my head. Try adapting it to your situation, and make the necessary changes. Report back if you have issues or if you're stuck.
 
Level 10
Joined
Apr 4, 2010
Messages
509
Works great now, thanks PurgeandFire. :thumbs_up:

I just needed to add the under score for the Chunks_Index in the script.
Everthing else is awesome.
  • Custom script: if udg_Chunks_Particle_Group[udg_Chunks_Index] == null then
People at HWS are awesome.
 
Status
Not open for further replies.
Top