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

This trigger can causes MUI issues?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,141
Hello everyone. Yesterday i was trying to detect unit getting hit by ability and created this trigger.

  • Test1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Wait until (((Target unit of ability being cast) has buff Stunned) Equal to True), checking every 0.10 seconds
      • -------- actions --------
This one was working but i have realized it is not works when i cast and move.
Then i have created this one

  • Test2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Firebolt (Neutral Hostile)
        • Then - Actions
          • Set TempCaster = (Casting unit)
          • Set TempTarget = (Target unit of ability being cast)
          • Wait until ((TempTarget has buff Stunned) Equal to True), checking every 0.10 seconds
          • Unit - Cause TempCaster to damage TempTarget, dealing 100.00 damage of attack type Spells and damage type Magic
          • Game - Display to (All players) the text: 31
          • Set TempCaster = No unit
          • Set TempTarget = No unit
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Storm Bolt
        • Then - Actions
          • -------- Other abilities will use the same TempCaster and TempTarget --------
        • Else - Actions
This one worked well. When i cast firebolt and stay or move, it works. But my problem is other spells.
For example i have added Storm Bolt in there (with different buff) with different projectile speed.
When it hits target, trigger will set the Caster and Target. Is it causes any MUI issues? MUI and MPI is my nightmare. I never understand how it works. This is why i am creating systems and abilities for eachh 22 player slots (10 for old version) sadly...
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,561
Neither of those triggers are MUI.

To understand MUI/MPI you first need to understand how a global variable works (TempCaster, TempTarget, etc). Global variables can only have one value at a time and this value is GLOBAL meaning it can be accessed from any other trigger at any time. If two triggers use the same global variables then there's a potential issue if you don't handle things appropriately. This issue is mainly caused by using the Wait action since it introduces a gap of time in which the global variables can have their values changed to something else from a different trigger.

Using your Test2 trigger as an example, if two different units were to cast Firebolt (Neutral Hostile) at the same time, Test2 would run twice and create two separate instances of the trigger. Then one of those two instances would get chosen to happen first, and then the second one would happen last. The problem is that both trigger instances are using the same global variables, and like I said before these can only have one value at a time so one of the trigger instances is going to take priority. In this case, TempCaster/TempTarget would end up being Set to the Units in the trigger instance that ran last.

In addition to global variables you also have Event Responses, which can either act like global or local variables and can have some unexpected behavior like getting unset after a Wait. This thread explains which ones are MUI safe and which are not: Event Response Myths

The things you're doing in your triggers would actually work fine and be MUI if you were using local variables instead of global variables, unfortunately, local variables are not easily accessible in GUI (the basic trigger editor). However, there are some tricks you can do to use local variables, like this one: local udg_
But that trick isn't perfect either (read the comments for more info).

The best way to learn how this stuff works is to visualize it ingame. I recommend using text messages to get a visual idea of how and when your triggers are running. This helps a lot in understanding what is happening when a trigger runs. For example, instead of displaying "31" in Test2, you should try displaying the Names of both TempCaster and TempTarget. You can also add another text message at the start of the trigger before the Wait happens so you know the exact moment that the trigger runs. Finally, give the Firebolt (Neutral Hostile) ability to two different units (make sure they have different names) and then in-game you should order them to cast Firebolt at the same time one the same target and also with two different targets. Make sure you do this fast enough so that both spells run before any of the Waits finish.

Also, I'm not sure why you're doing this but it doesn't look necessary:
  • Set TempCaster = No unit
  • Set TempTarget = No unit
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,141
@Uncle Thank you for your amazing explanation. But i forgot to mention something.

During the game, only 1 unit will use this ability.
I am asking for TempTarget and TempCaster part.
Can i use this TempCaster and TempTarget as i want? OR do i need TempTarget2 TempCaster2, TempTarget3 TempCaster3 for different abilities?
My bad. Second part is Storm Bolt
And third part is will be different ability etc etc goes on like this.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,561
Global variables are shared between ALL of your triggers, so there's potential for issues when reusing them. HOWEVER, this doesn't mean that you shouldn't share/reuse global variables, it just means that you should learn when and why you can reuse them. The issue mainly happens because of the Wait action since it creates a gap of time where the variables can change to something else.

Since your trigger uses a Wait it's not safe to be reusing those variables. A quick solution would be to use unique variables for that specific trigger, for example:
  • Set FireboltCaster = (Casting unit)
  • Set FireboltTarget = (Target unit of ability being cast)

Also, if only 1 unit can use Firebolt then you may want to get rid of FireboltCaster and just reference the unit directly:
  • Unit - Cause FireWizard to damage FireboltTarget, dealing 100.00 damage of attack type Spells and damage type Magic
This would save you some hassle if your unit used multiple triggers since you could just reference FireWizard in all of them.
 
Last edited:
Status
Not open for further replies.
Top