• 🏆 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] Does this leak?

Status
Not open for further replies.
Level 5
Joined
Aug 18, 2013
Messages
85
  • P1ReinCap
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacked unit) Equal to Reinforcements 0140 <gen>
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Attacking unit)) is an ally of Player 1 (Red)) Equal to True
          • (Owner of (Attacking unit)) Not equal to Player 1 (Red)
          • (Integer((Life of (Attacked unit)))) Less than or equal to 166
        • Then - Actions
          • Unit - Change ownership of (Attacked unit) to Player 1 (Red) and Change color
          • Wait 0.50 seconds
          • Unit - Set life of (Attacked unit) to 100.00%
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Life of (Attacked unit)))) Less than or equal to 166
            • Then - Actions
              • Unit - Change ownership of (Attacked unit) to (Owner of (Attacking unit)) and Change color
              • Unit - Set life of (Attacked unit) to 25.00%
              • Wait 0.50 seconds
              • Unit - Set life of (Attacked unit) to 50.00%
              • Wait 0.50 seconds
              • Unit - Set life of (Attacked unit) to 75.00%
            • Else - Actions
              • Do nothing
  • BlueQuit
    • Events
      • Player - Player 2 (Blue) leaves the game
    • Conditions
    • Actions
      • Player Group - Remove Player 2 (Blue) from TeamMalcolm
      • Set GroupVar = (Units owned by Player 2 (Blue))
      • Unit Group - Pick every unit in GroupVar and do (Unit - Change ownership of (Picked unit) to (Random player from TeamMalcolm) and Retain color)
      • Custom script: call DestroyGroup(udg_GroupVar)

Thank you
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
Doesn't seem like it leaks.

A few things tho:
Remove the "Do nothing" action. It actually calls a function which does nothing (still, you call a function for no reason). The "Else" block can be completely empty without any actions.

You should consider turning the trigger off once you change ownership I guess. The event "Unit is attacked" fires when attacking unit is preparing to attack (footman starts swinging his sword, archer starts preparing to shoot), but before the unit lands an attack. The problem here is that if you press 'S' button to Stop the unit, its AI will automatically try to attack the unit again, firing this event once again.

"Wait" actions are inaccurate. Even when you set wait time to 0.5 seconds, it is actually randomly somewhere between 0.27 and 1.00. Waits are even more inefficient in multiplayer maps (I just assume this is MP map), as it gets affected by latency I think and runs even when game is paused.

Last thing, you don't have to compare health using integers. Health is in reals and in the way you have it, there's no need to convert that into integer.
  • (Integer((Life of (Attacked unit)))) Less than or equal to 166
can be
  • (Life of (Attacked unit)) Less than or equal to 166.00
But that's up to you.
 
Level 13
Joined
Dec 21, 2010
Messages
541
It doesn't leak but it will make undesirable results.. because you are using "attacked unit" with waits.. if another unit is attacked, the same trigger will run and the other attacked unit will get the result.. if you really want to use "wait" just make a variable for the attacked unit at the beginning of the trigger.. besides, the event is a specific unit.

  • P1ReinCap
  • Events
    • Unit - A unit Is attacked
  • Conditions
    • (Attacked unit) Equal to Reinforcements 0140 <gen>
  • Actions
    • Set - Temp_Unit = (Attacked unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Owner of (Attacking unit)) is an ally of Player 1 (Red)) Equal to True
        • (Owner of (Attacking unit)) Not equal to Player 1 (Red)
        • (Integer((Life of (Temp_Unit)))) Less than or equal to 166
      • Then - Actions
        • Unit - Change ownership of (Temp_Unit) to Player 1 (Red) and Change color
        • Wait 0.50 seconds
        • Unit - Set life of (Temp_Unit) to 100.00%
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Integer((Life of (Temp)))) Less than or equal to 166
          • Then - Actions
            • Unit - Change ownership of (Temp_Unit) to (Owner of (Attacking unit)) and Change color
            • Unit - Set life of (Temp_Unit) to 25.00%
            • Wait 0.50 seconds
            • Unit - Set life of (Temp_Unit) to 50.00%
            • Wait 0.50 seconds
            • Unit - Set life of (Temp_Unit) to 75.00%
          • Else - Actions
 
Last edited:
Level 13
Joined
Dec 21, 2010
Messages
541
^I think you made a wait-working spell not MUI.
At least your approach is not MUI for sure. The variable may get overwritten during the wait.
According to this attacked unit should work just fine.

It's a wait working spell.. it's not even meant for MUI purposes.. he just asked if the trigger leaks... he didn't ask for how to make it MUI..
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
It's a wait working spell.. it's not even meant for MUI purposes.. he just asked if the trigger leaks... he didn't ask for how to make it MUI..
He didnt ask because... he already knew it was MUI?
He definately didnt ask to make it non-MUI.

To answer the original question... no it doesnt leak.
However, just do what Nichilus said (except the part of the attacking unit) and ignore every other post in this thread.
Then you are fine.
 
^You did.

it will make undesirable results.. because you are using "attacked unit" with waits.. if another unit is attacked, the same trigger will run and the other attacked unit will get the result.. if you really want to use "wait" just make a variable for the attacked unit at the beginning of the trigger
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Because it is a global variable and every single time that that variable is written, all other usages might be broken.

The variable that you used is a TempVariable, meaning it may be used by every single trigger but never stores the value over a duration.

Also...
"Unit - Change ownership of (Temp_Unit) to (Owner of (Temp_Unit)) and Change color"
You wot?
 
Status
Not open for further replies.
Top