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

Making trees respawn

Status
Not open for further replies.
Level 2
Joined
Mar 25, 2017
Messages
15
I've tried various things from various forums but I can't find anything that helps me specifically. It's either a single selected tree, or none at all.
 
Level 11
Joined
Nov 23, 2013
Messages
665
What exactly are you trying to do? Do you want trees to respawn automatically after a while? Or do you want them to respawn after a specific event?
 
Level 2
Joined
Mar 25, 2017
Messages
15
What exactly are you trying to do? Do you want trees to respawn automatically after a while? Or do you want them to respawn after a specific event?
Respawn after awhile, ideally, or perhaps after a certain event so I can proc it with a skill or something. I like it when maps have a bunch of trees in them, and it bothers me quite a bit when they're all gone towards the end. Usually I'd fix it by just giving them a lot of health, but you can't do that with the Keeper of the Grove, so.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Have you tried closing the trees after a while?

Yes this is a serious response. It seems some destructables can be resurrected by setting their life to greater than 0. This is how door open/close works.
JASS:
function ModifyGateBJ takes integer gateOperation,destructable d returns nothing
    if (gateOperation == bj_GATEOPERATION_CLOSE) then
        if (GetDestructableLife(d) <= 0) then
            call DestructableRestoreLife(d, GetDestructableMaxLife(d), true)
        endif
        call SetDestructableAnimation(d, "stand")
    elseif (gateOperation == bj_GATEOPERATION_OPEN) then
        if (GetDestructableLife(d) > 0) then
            call KillDestructable(d)
        endif
        call SetDestructableAnimation(d, "death alternate")
    elseif (gateOperation == bj_GATEOPERATION_DESTROY) then
        if (GetDestructableLife(d) > 0) then
            call KillDestructable(d)
        endif
        call SetDestructableAnimation(d, "death")
    else
    endif
endfunction
If this works to resurrect trees is a different question.
 
Level 19
Joined
Jul 2, 2011
Messages
2,162
I've tried various things from various forums but I can't find anything that helps me specifically. It's either a single selected tree, or none at all.
I've made trees respawn before in my map

you trigger the event when a destructible dies, the condition you select destructible type to the exact type of tree

then for the action you just places a new tree of type triggering unit.

done your trees now repawn ^-^
 
Level 10
Joined
Apr 18, 2009
Messages
576
A long time ago, some guy told me to use this:

  • Trigger - Add to Tree Respawn <gen> the event (Destructible - (Picked destructible) dies)
So you pick all trees at map startup, add them as event to a trigger where there's a wait (don't tell anyone though, this is the only place I use waits because I can't be bothered, but they'll burn me alive if they find out) and then the action Resurrect dying destructable. It can be done in a single-digit number of GUI lines if you do it like this, and I've never had any problems with this system. Check out the attached example map.
 

Attachments

  • Tree Respawn System - Example Map by Licheus.w3x
    3 MB · Views: 174
Last edited:
Level 18
Joined
Nov 21, 2012
Messages
835
something like this tree ressurection I made some time ago. It respawns trees after delay.
in 1st trigger you decide what trees should be able to ressurect
in second you can change this 10seconds to higher value as ressurection delay. It also checks if there are any alive units around the tree to ressurect it.
To make 2nd trigger: create new trigger and name it "TreeRespawn". Convert to Custom Text, delete all inside and copy/paste below code.
  • TreeInit
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set ug = (Units in (Playable map area))
      • -------- --- --------
      • Destructible - Pick every destructible in (Playable map area) 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 TreePine [2]
            • Then - Actions
              • Trigger - Add to TreeRespawn <gen> the event (Destructible - (Picked destructible) dies)
            • Else - Actions
JASS:
function IsUnitAlive takes unit u returns boolean
    return not (GetUnitTypeId(u) == 0 or IsUnitType(u, UNIT_TYPE_DEAD))
endfunction
function TreeRespawn_AreUnitsAround takes real x, real y returns boolean
    local unit u=null
    call GroupEnumUnitsInRange(udg_ug, x, y, 400.00, null)
    loop
        set u = FirstOfGroup(udg_ug)
        exitwhen u == null
        if IsUnitAlive(u) then
            set u=null
            return true
        endif  
        call GroupRemoveUnit(udg_ug, u)
    endloop
    return false
endfunction

function Trig_TreeRespawn_Actions takes nothing returns nothing
    local destructable tree=GetDyingDestructable()
    call TriggerSleepAction(10.00)
    loop
        exitwhen not TreeRespawn_AreUnitsAround(GetDestructableX(tree), GetDestructableY(tree))
        call TriggerSleepAction(2.00)
    endloop
    call DestructableRestoreLife(tree, GetDestructableMaxLife(tree), true )//ressurect tree
    set tree=null
endfunction
//===========================================================================
function InitTrig_TreeRespawn takes nothing returns nothing
    set gg_trg_TreeRespawn = CreateTrigger(  )
    call TriggerAddAction( gg_trg_TreeRespawn, function Trig_TreeRespawn_Actions )
endfunction

edit: generally this solution is almost the same as @Licheus , (mine just checks units around additionally to not make unit stuck in between the trees)
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Level 11
Joined
Jun 2, 2004
Messages
849
I have zero evidence for this having not looked at the game code, but I imagine each individual tree object is merely given a pointer to run the trigger when it dies. It's not like it checks every single tree for every single event to see if it's the correct one that died (Blizz did some silly things but nothing quite that silly!).
 
Level 19
Joined
Jul 2, 2011
Messages
2,162
ok enough deliberation!

I'm getting on my computer after work and we will sort this out together

For kingdom
for glory
for the HORDE! !!!!

EDIT!

Here is the solution, and look how lovely and short it is

Code:
trees can die
    Events
        Destructible - A destructible within Region 043 <gen> dies
        Destructible - A destructible within Region 044 <gen> dies
        Destructible - A destructible within Region 034 <gen> dies
    Conditions
    Actions
        Destructible - Resurrect (Dying destructible) with (Max life of (Dying destructible)) life and Show birth animation
 
Last edited:
Level 11
Joined
Nov 23, 2013
Messages
665
Here is the solution, and look how lovely and short it is

Code:
trees can die
    Events
        Destructible - A destructible within Region 043 <gen> dies
        Destructible - A destructible within Region 044 <gen> dies
        Destructible - A destructible within Region 034 <gen> dies
    Conditions
    Actions
        Destructible - Resurrect (Dying destructible) with (Max life of (Dying destructible)) life and Show birth animation
But with this trigger, the reviving is instant, and I think the OP wants the trees to resurrect after a while. And if you use waits, you'll have trouble to resurrect the right tree at the right moment.
Secondly, the event Destructible - A destructible within Region takes only 64 destructibles into account, therefore you won't be able to resurrect the other ones.

Here is what I tried:

One trigger to add the event:
  • Initialisation
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Playable map area) and do (Actions)
        • Loop - Actions
          • Trigger - Add to RespawnTrees the event (Destructible - (Picked destructible) dies)
The action may be run at map initilization or whenever you want it to fire

  • RespawnTrees
    • Events
    • Conditions
      • (Destructible-type of (Dying destructible)) Equals Some Tree <Select here which type of tree your map contains>
    • Actions
      • Set TreeIndex01 = (TreeIndex01 + 1)
      • Set Tree[TreeIndex01] = (Dying destructible)
      • Wait 10.00 seconds
      • Set TreeIndex02 = (TreeIndex02 + 1)
      • Destructible - Resurrect Tree[TreeIndex02] with (Max life of (Last created destructible)) life and Show birth animation
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TreeIndex02 Equals TreeIndex01
        • Then - Actions
          • Set TreeIndex01 = 0
          • Set TreeIndex02 = 0
        • Else - Actions
Variable Tree is a destructible array, TreeIndex01 and TreeIndex02 are integers.
If you want to add new trees in the game for some reason, run again the first trigger so the new trees can be taken into account for the respawning stuff.
If your map contains more than one type of tree, just use a OR condition in the second trigger:
  • RespawnTrees
    • Events
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Destructible-type of (Dying destructible)) Equals Tree X
          • (Destructible-type of (Dying destructible)) Equals Tree Y
          • (Destructible-type of (Dying destructible)) Equals Tree Z
Thanks to Magtheridon96, who helped me understand the basics of MUI with his tutorial :D

It seems to work just fine. There is no issue when a unit is standing at the position of a reviving tree.

Any suggestion about this? Does it leak or anything?
 
Last edited:
Level 19
Joined
Jul 2, 2011
Messages
2,162
But with this trigger, the reviving is instant, and I think the OP wants the trees to resurrect after a while. And if you use waits, you'll have trouble to resurrect the right tree at the right moment.
Secondly, the event Destructible - A destructible within Region takes only 64 destructibles into account, therefore you won't be able to resurrect the other ones.

Here is what I tried:

One trigger to add the event:
  • Initialisation
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Destructible - Pick every destructible in (Playable map area) and do (Actions)
        • Loop - Actions
          • Trigger - Add to RespawnTrees the event (Destructible - (Picked destructible) dies)
The action may be run at map initilization or whenever you want it to fire

  • RespawnTrees
    • Events
    • Conditions
      • (Destructible-type of (Dying destructible)) Equals Some Tree <Select here which type of tree your map contains>
    • Actions
      • Set TreeIndex01 = (TreeIndex01 + 1)
      • Set Tree[TreeIndex01] = (Dying destructible)
      • Wait 10.00 seconds
      • Set TreeIndex02 = (TreeIndex02 + 1)
      • Destructible - Resurrect Tree[TreeIndex02] with (Max life of (Last created destructible)) life and Show birth animation
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TreeIndex02 Equals TreeIndex01
        • Then - Actions
          • Set TreeIndex01 = 0
          • Set TreeIndex02 = 0
        • Else - Actions
Variable Tree is a destructible array, TreeIndex01 and TreeIndex02 are integers.
If you want to add new trees in the game for some reason, run again the first trigger so the new trees can be taken into account for the respawning stuff.
If your map contains more than one type of tree, just use a OR condition in the second trigger:
  • RespawnTrees
    • Events
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Destructible-type of (Dying destructible)) Equals Tree X
          • (Destructible-type of (Dying destructible)) Equals Tree Y
          • (Destructible-type of (Dying destructible)) Equals Tree Z
Thanks to Magtheridon96, who helped me understand the basics of MUI with his tutorial :D

It seems to work just fine. There is no issue when there is a unit standing at the position of a reviving tree.

Any suggestion about this? Does it leak or anything?
Ok let me see.....There are a number of problems

first off using wait can cause problems in lan games, you have to remember that wait is determined by the computer not the game. Luckily there is a simple fix for this one, which is , "wait in game" which is a wait option

the second thing is that in your event RespawnTrees you use the command of ,'Destructible - Resurrect Tree[TreeIndex02] with (Max life of (Last created destructible)) life and Show birth animation'

Last created destructible will mean that any destructible created in the last few seconds before this event, will represent the live points of this try. What you should do is set that value to max life of TreeIndex02

Hmm yeah I think those are the only problems :)

Good luck with it all
 
Level 11
Joined
Nov 23, 2013
Messages
665
first off using wait can cause problems in lan games, you have to remember that wait is determined by the computer not the game. Luckily there is a simple fix for this one, which is , "wait in game" which is a wait option
Yes, I know waits can be problematic, but I'm not very experienced in advanced triggering :cconf: I figured using a wait in this very specific case shouldn't be a big issue, since respawning tree doesn't require to be very accurate (I guess resurrection will occur maybe every 5 or 10 or so). However, I wasn't aware of that multiplayer issue, thanks for pointing that out.

the second thing is that in your event RespawnTrees you use the command of ,'Destructible - Resurrect Tree[TreeIndex02] with (Max life of (Last created destructible)) life and Show birth animation'

Last created destructible will mean that any destructible created in the last few seconds before this event, will represent the live points of this try. What you should do is set that value to max life of TreeIndex02
Well spotted, I totally missed that one.

Thanks for your feedback! :csmile:
 
Level 3
Joined
Mar 22, 2020
Messages
24
I can't even add the Event's
 

Attachments

  • wood.PNG
    wood.PNG
    43.5 KB · Views: 26
Status
Not open for further replies.
Top