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

Repeatedly resurrect and kill selected doodads

Status
Not open for further replies.
Level 2
Joined
Nov 15, 2010
Messages
16
Hi, I have some doodads that start the game dead, but I want to resurrect them at the start of the game, and then after some time kill them again. I can select all the dead doodads and resurrect them just fine, but then the game refuses to kill them again. Is there a way to kill the same selected doodads after resurrecting them? Map attached

  • ReviveTrees
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is dead) Equal to True
            • Then - Actions
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
              • -------- The actions below this line do not work :( --------
              • Wait 5.00 seconds
              • Destructible - Kill (Picked destructible)
              • -------- The actions above this line do not work :( --------
            • Else - Actions
              • Do nothing
 

Attachments

  • treestumps - Copy.w3x
    18.8 KB · Views: 6
Level 28
Joined
Feb 18, 2014
Messages
3,580
You can't use waits during map initialization because the actions you put below them trigger after the map finishes loading. In your case picked destructible returns null after the wait which why you can't destroy them. So you should use a timer instead.

Also remove Do Nothing it's kinda useless.
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
one simple reason that this isn't working is bc the computer only saves 1 variable for "picked destructible" in memory. when it is looping through them, it keeps rewriting that variable. so by the time that 5 second timer expires - it is probably just one tree.

there may be other issues too, but to circumvent the above problem (which may solve the issue) - you could jsut split this into 2 triggers. have the second trigger fire 5 seconds after the game starts, loop through the trees you want to kill and kill them.

in order to find the trees that you spawned and want to kill (assuming there are other trees) - one eeasy way to do this is to create a custom tree doodad that is a copy of the other trees but with a different name. so you could loop through and kill the custom trees but not the rest.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
This should work fine:
  • ReviveTrees
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is dead) Equal to True
            • Then - Actions
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
            • Else - Actions
      • Wait 5.00 seconds
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is dead) Equal to False
            • Then - Actions
              • Destructible - Kill (Picked destructible)
            • Else - Actions
If you want to do this continuously throughout the game I recommend storing the Destructibles in an Array and using a For Loop to enumerate over them. You could use a Timer or Periodic Interval to do this every X seconds. Also, Waits are generally bad practice.
 
Level 2
Joined
Nov 15, 2010
Messages
16
This should work fine:
  • ReviveTrees
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is dead) Equal to True
            • Then - Actions
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
            • Else - Actions
      • Wait 5.00 seconds
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is dead) Equal to False
            • Then - Actions
              • Destructible - Kill (Picked destructible)
            • Else - Actions
If you want to do this continuously throughout the game I recommend storing the Destructibles in an Array and using a For Loop to enumerate over them. You could use a Timer or Periodic Interval to do this every X seconds. Also, Waits are generally bad practice.
Ah yes, but that will kill all the trees in map, not just the ones I resurected in the beginning
I was thinking more of a
  • ReviveTrees
    • Events
      • Time - Elapsed game time is 3.00 seconds
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Entire map) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
              • ((Picked destructible) is alive) Equal to False
            • Then - Actions
              • Unit Group - Add (Picked unit) to Trees
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
            • Else - Actions
      • Trigger - Turn off (This trigger)
and
  • KillTrees
    • Events
      • Time - Elapsed game time is 6.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Trees and do (Unit - Kill (Picked unit))
      • Trigger - Turn off (This trigger)
but unit groups only work with units, and not with doodads

And how can I store the Destructibles in an Array and using a For Loop to enumerate over them please?
 
Last edited:
Level 21
Joined
Mar 29, 2020
Messages
1,237
but unit groups only work with units, and not with doodads

And how can I store the Destructibles in an Array and using a For Loop to enumerate over them please?
I suggested a solution to this in my first reply:

"in order to find the trees that you spawned and want to kill (assuming there are other trees) - one eeasy way to do this is to create a custom tree doodad that is a copy of the other trees but with a different name. so you could loop through and kill the custom trees but not the rest."

basically - create a custom destructible and then you can just filter this by destructible type.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
And how can I store the Destructibles in an Array and using a For Loop to enumerate over them please?
Create a new Destructible variable and enable it as an Array. Then create a new Integer variable.

Now when you Pick through the trees at the start of the game you simply do this:
  • Destructible - Pick every destructible in (Entire map) and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
          • ((Picked destructible) is dead) Equal to True
        • Then - Actions
          • Set Variable TreeCount = TreeCount + 1
          • Set Variable Tree[TreeCount] = (Picked destructible)
        • Else - Actions
Now you've stored all of your Trees in an Array with an [index] starting at 1 and ending at TreeCount. In other words, your trees are stored like so:
Tree[1] = First tree, Tree[2] = Second tree, Tree[3] = Third tree, etc.
TreeCount is equal to the total number of trees in the Array.

Now you can use a For Loop to enumerate over these trees whenever you want:
  • For each (Integer A) from 1 to TreeCount, do (Actions)
    • Loop - Actions
      • Destructible - Kill Tree[(Integer A)]
 
Status
Not open for further replies.
Top