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

Trying to learn MUI

Status
Not open for further replies.
So I am taking upon me to finally learn MUI. A task I have been postponing for a long time, but now I can't postpone it anymore.

While some find it extremely simple to do it, I don't really understand the logic behind it completely just yet. If possible I would like to learn array MUI, preferably not hash tables.

I get the concept behind MUI and I am able to create some simple triggers, but when it comes to more advanced lightning systems is where logic really starts to elude me.

Here's a spell I have been trying to make work for some time now:


This trigger successfully creates a new instance of the lightning and it removes it in the same order that I cast it, just as I want it:
  • MIL
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Inner Fire
    • Actions
      • Unit Group - Add (Target unit of ability being cast) to MI_Group
      • Set MIC = (MIC + 1)
      • Set MC[MIC] = (Triggering unit)
      • Set MT[MIC] = (Target unit of ability being cast)
      • Set MP1[MIC] = (Position of MC[MIC])
      • Set MP2[MIC] = (Position of MT[MIC])
      • Custom script: set udg_MIL[udg_MIC] = AddLightningEx("DRAL", true , GetLocationX(udg_MP1[udg_MIC]), GetLocationY(udg_MP1[udg_MIC]), GetLocationZ(udg_MP1[udg_MIC]) + 70, GetLocationX(udg_MP2[udg_MIC]), GetLocationY(udg_MP2[udg_MIC]), GetLocationZ(udg_MP2[udg_MIC]) + 70)
      • Set LightningCount = (LightningCount + 1)
      • Custom script: call RemoveLocation (udg_MP1[udg_MIC])
      • Custom script: call RemoveLocation (udg_MP2[udg_MIC])
      • Wait 10.00 seconds
      • Set MIT = (MIT + 1)
      • Lightning - Destroy MIL[MIT]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MIC Equal to MIT
        • Then - Actions
          • Set MIC = 0
          • Set MIT = 0
        • Else - Actions


However I don't want the lightning to end from a timed wait, but rather when the affected unit dies so I tried doing this:
  • MIL
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Inner Fire
    • Actions
      • Unit Group - Add (Target unit of ability being cast) to MI_Group
      • Set MIC = (MIC + 1)
      • Set MC[MIC] = (Triggering unit)
      • Set MT[MIC] = (Target unit of ability being cast)
      • Set MP1[MIC] = (Position of MC[MIC])
      • Set MP2[MIC] = (Position of MT[MIC])
      • Custom script: set udg_MIL[udg_MIC] = AddLightningEx("DRAL", true , GetLocationX(udg_MP1[udg_MIC]), GetLocationY(udg_MP1[udg_MIC]), GetLocationZ(udg_MP1[udg_MIC]) + 70, GetLocationX(udg_MP2[udg_MIC]), GetLocationY(udg_MP2[udg_MIC]), GetLocationZ(udg_MP2[udg_MIC]) + 70)
      • Set LightningCount = (LightningCount + 1)
      • Custom script: call RemoveLocation (udg_MP1[udg_MIC])
      • Custom script: call RemoveLocation (udg_MP2[udg_MIC])

  • MIL Target dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in MI_Group) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from MI_Group
      • Set MIT = (MIT + 1)
      • Lightning - Destroy MIL[MIT]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MIC Equal to MIT
        • Then - Actions
          • Set MIC = 0
          • Set MIT = 0
        • Else - Actions

Needless to say this didn't work as I hoped it would as the units doesn't necessarily die in the order they were affected by the spell.


And then comes the part that really gets me. Actually moving every single instance of lightning to their respective units. This is what I tried:
  • MIL Periodic
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • (Number of units in MI_Group) Greater than 0
    • Actions
      • Set MP1[MIC] = (Position of MC[MIC])
      • Set MP2[MIC] = (Position of MT[MIC])
      • Custom script: call MoveLightningEx(udg_MIL[udg_MIC], true , GetLocationX(udg_MP1[udg_MIC]), GetLocationY(udg_MP1[udg_MIC]), GetLocationZ(udg_MP1[udg_MIC]) + 70, GetLocationX(udg_MP2[udg_MIC]), GetLocationY(udg_MP2[udg_MIC]), GetLocationZ(udg_MP2[udg_MIC]) + 70)
      • Custom script: call RemoveLocation (udg_MP1[udg_MIC])
      • Custom script: call RemoveLocation (udg_MP2[udg_MIC])

I am well aware that the reason this isn't working is because it will only move the most recent instance of MIL[udg_MIC] to the caster, leaving the old lightnings stuck on the ground. I have tried thinking out some way to successfully reference the correct lightnings with a simple periodic trigger but I just can't wrap my head around how to do it.

Any help is appreciated.
 
The method you are using (dual indexes) works, but it’s not really what you should be doing because it fails when you encounter scenarios like you described above. Instead what you should be doing is: Visualize: Dynamic Indexing


Ok thanks I got the periodic trigger working by reading the link you gave me, but I have encountered a new problem.

When I deallocate the instances one of the arrays stops looping. Posting map as example. Here's my triggers:

  • MIL
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Inner Fire
    • Actions
      • Unit Group - Add (Target unit of ability being cast) to MI_Group
      • Set MIC = (MIC + 1)
      • Set MC[MIC] = (Triggering unit)
      • Set MT[MIC] = (Target unit of ability being cast)
      • Set MP1[MIC] = (Position of MC[MIC])
      • Set MP2[MIC] = (Position of MT[MIC])
      • Custom script: set udg_MIL[udg_MIC] = AddLightningEx("DRAL", true , GetLocationX(udg_MP1[udg_MIC]), GetLocationY(udg_MP1[udg_MIC]), GetLocationZ(udg_MP1[udg_MIC]) + 70, GetLocationX(udg_MP2[udg_MIC]), GetLocationY(udg_MP2[udg_MIC]), GetLocationZ(udg_MP2[udg_MIC]) + 70)
      • Custom script: call RemoveLocation (udg_MP1[udg_MIC])
      • Custom script: call RemoveLocation (udg_MP2[udg_MIC])

  • MIL Periodic
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • (Number of units in MI_Group) Greater than 0
    • Actions
      • For each (Integer MICL) from 1 to MIC, do (Actions)
        • Loop - Actions
          • Set MP1[MICL] = (Position of MC[MICL])
          • Set MP2[MICL] = (Position of MT[MICL])
          • Custom script: call MoveLightningEx(udg_MIL[udg_MICL], true , GetLocationX(udg_MP1[udg_MICL]), GetLocationY(udg_MP1[udg_MICL]), GetLocationZ(udg_MP1[udg_MICL]) + 70, GetLocationX(udg_MP2[udg_MICL]), GetLocationY(udg_MP2[udg_MICL]), GetLocationZ(udg_MP2[udg_MICL]) + 70)
          • Custom script: call RemoveLocation (udg_MP1[udg_MICL])
          • Custom script: call RemoveLocation (udg_MP2[udg_MICL])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (MT[MICL] is dead) Equal to True
            • Then - Actions
              • Set MC[MICL] = MC[MIC]
              • Set MT[MICL] = MT[MIC]
              • Set MIC = (MIC - 1)
              • Lightning - Destroy MIL[MICL]
              • Set MICL = (MICL - 1)
            • Else - Actions


Also how can I make it so that if the priest dies all the lightnings connected to him gets destroyed? I am guessing I need to use hash tables for that.


EDIT: It seems it only deallocates properly when killing the units in the same order as I cast the ability.
 

Attachments

  • MUI Test.w3x
    19.2 KB · Views: 14
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
You also need to bring the lightning object from the last index to the current one. Otherwise, the object (lightning) will be left behind and possibly become a leak.
  • Set MIL[MICL] = MIL[MIC]
Also, I don't get why you're using a unit group in this case... Anyway, you shouldn't use this in your loop
  • (Number of units in MI_Group) Greater than 0
Because, as soon as the last instance/unit dies, your loop trigger will return false and not be able to remove the lightning effect in time. Maybe replacing that condition with the one below should be enough.
  • MIC Greater than 0
 

Attachments

  • MUI Test.w3x
    19.1 KB · Views: 9
You also need to bring the lightning object from the last index to the current one. Otherwise, the object (lightning) will be left behind and possibly become a leak.
  • Set MIL[MICL] = MIL[MIC]
Also, I don't get why you're using a unit group in this case... Anyway, you shouldn't use this in your loop
  • (Number of units in MI_Group) Greater than 0
Because, as soon as the last instance/unit dies, your loop trigger will return false and not be able to remove the lightning effect in time. Maybe replacing that condition with the one below should be enough.
  • MIC Greater than 0
Awesome, it works perfectly. Thanks!
 
Status
Not open for further replies.
Top