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

Destroy units in area

Status
Not open for further replies.
Level 3
Joined
Jun 1, 2013
Messages
47
When any Player uses Last Hope, all enemy units in the area "Rot <gen>" shall explode.

This is my try, I have not figured out how to make it for all players at once, so I just did it for red. But the trigger kills all units including Red and allied units instead of just enemies.

  • Spieler 1 uses LAST HOPE
    • Ereignisse
      • Einheit - |cFF008080Rebels Keep |r 0016 <gen> Vollendet Forschung
    • Bedingungen
      • (Researched tech-type) Gleich |cFF008080Last Hope|r
    • Aktionen
      • Set PlayerAlive[1] = False
      • Einheitengruppe - Pick every unit in (Units in Rot <gen> matching ((Owner of (Picked unit)) Ungleich Spieler 1 (Rot))) and do (Actions)
        • Schleifen - Aktionen
          • Einheit - Explode (Picked unit)
      • Spiel - Display to (All players) the text: ((Name of (Triggering player)) + has used last hope!)
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Wrong forum. This should be in Triggers & Scripts.


You shouldn't use Matching Unit to filter out your unit groups, when you have over 3+ checks, it becomes extremely ugly and hard to read. Here's a solution to your problem + a better way to filter them out.
  • Set caster = (Triggering unit)
  • Set playerVariable = (Owner of caster)
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in Rot <gen>) and do (Actions)
    • Loop - Actions
      • Set tempUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (tempUnit belongs to an enemy of player) Equal to True
          • -------- you can add other filters like magic immune, not a structure, is alive, etc--------
        • Then - Actions
          • -------- unit passed filters; explode picked unit --------
        • Else - Actions
          • -------- unit did not pass filters; do nothing --------
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Well, the problem he has is that he has a region named Red, so I assume there is a region for each player. So what he must do is use a region array and set each player's region to the array using the player number as the array index.

Oh woops. I misunderstood his question. Thank you.


You will need to make a region variable with an array element that is the same as their player number.
  • Map Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set regionVariable[1] = Player Red's region
      • Set regionVariable[2] = Player Blue's region
      • Set regionVariable[3] = Player Teal's region
      • -------- continue for all players --------

Then when they cast the spell, this is exactly how it will look like.
  • Set caster = (Triggering unit)
  • Set playerVariable = (Owner of caster)
  • Set intVariable = (Player number of playerVariable)
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in regionVariable[intVariable]) and do (Actions)
    • Loop - Actions
      • Set tempUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (tempUnit belongs to an enemy of playerVariable) Equal to True
          • -------- you can add other filters like magic immune, not a structure, is alive, etc--------
        • Then - Actions
          • -------- unit passed filters; explode picked unit --------
        • Else - Actions
          • -------- unit did not pass filters; do nothing --------
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The cause of his problem is that he used "Picked unit" instead of "Matching unit" inside a filter check.
I recommend not using filters at all, especially in GUI, but even if you use them, then you still have to use the right function calls to get the data you expect.
 
Level 7
Joined
Nov 19, 2015
Messages
283
Wrong forum. This should be in Triggers & Scripts.


You shouldn't use Matching Unit to filter out your unit groups, when you have over 3+ checks, it becomes extremely ugly and hard to read. Here's a solution to your problem + a better way to filter them out.
  • Set caster = (Triggering unit)
  • Set playerVariable = (Owner of caster)
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in Rot <gen>) and do (Actions)
    • Loop - Actions
      • Set tempUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (tempUnit belongs to an enemy of player) Equal to True
          • -------- you can add other filters like magic immune, not a structure, is alive, etc--------
        • Then - Actions
          • -------- unit passed filters; explode picked unit --------
        • Else - Actions
          • -------- unit did not pass filters; do nothing --------

I know your way is easier to read but is it easier for the game?
I have a create group for my missile trigger to detect units in range matching conditions. Would it always be adding units to a group that don't need to be in the group or does it not really matter?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Filters work almost exactly the same as an If/Then/Else.
It may or may not create a new thread for each iteration but it will run for each individual unit ofcourse.

@Bribe:
It's a matter of opening 1 thread per unit versus opening 1 thread and another one for each unit that passes the filter per unit. (If the filter creates a new thread at least.)
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
If you crash a filter thread with 1/0, any subsequent units will still be checked. So yes, another thread. The only things publicly accessible to the users are the main thread and whatever the user triggers. There's no way to run code without that code being run in a new thread. The only difference is with function calls.
 
Status
Not open for further replies.
Top