1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Making trees respawn

Discussion in 'World Editor Help Zone' started by Toppers, Jan 27, 2018.

Tags:
  1. Toppers

    Toppers

    Joined:
    Mar 25, 2017
    Messages:
    15
    Resources:
    0
    Resources:
    0
    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.
     
  2. Sieben

    Sieben

    Joined:
    Nov 23, 2013
    Messages:
    644
    Resources:
    0
    Resources:
    0
    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?
     
  3. Toppers

    Toppers

    Joined:
    Mar 25, 2017
    Messages:
    15
    Resources:
    0
    Resources:
    0
    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.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,594
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
    Code (vJASS):
    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.
     
  5. TheLordOfChaos201

    TheLordOfChaos201

    Joined:
    Jul 2, 2011
    Messages:
    1,723
    Resources:
    0
    Resources:
    0
    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 ^-^
     
  6. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,594
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Does the map not crash if it respawns on top of a unit? There is a reason people avoid tree respawn systems...
     
  7. Toppers

    Toppers

    Joined:
    Mar 25, 2017
    Messages:
    15
    Resources:
    0
    Resources:
    0
    ...That makes sense. Maybe it should be triggered by a spell or something.
     
  8. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,622
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Aren't there plenty of those systems in the spell section?
     
  9. Licheus

    Licheus

    Joined:
    Apr 18, 2009
    Messages:
    562
    Resources:
    0
    Resources:
    0
    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.
     

    Attached Files:

    Last edited: Jan 28, 2018
  10. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,622
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Probably not a good approach. Waits aside, would that not give a single trigger hundreds of events?

    Sounds like a good cause of lag.
     
  11. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    899
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    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

    Code (vJASS):

    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: Jan 28, 2018
  12. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,622
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Tree Revival 1.2.3.1

    Took a look at this, apparently it is accepted to just bombard a trigger with events.
     
  13. TheLordOfChaos201

    TheLordOfChaos201

    Joined:
    Jul 2, 2011
    Messages:
    1,723
    Resources:
    0
    Resources:
    0
    you can play my map... it doesn't crash

    the only bother is the fact that you can see the tree stump of the previous tree
     
  14. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,594
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    So?
    How so?

    The only concern is that 40,000 trees would mean 40,000 event handles which might aid handle resource depletion.
    So you admit it leaks destructables?
     
  15. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,622
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Well I imagine it would result in empty event pointers when a destructible die? or if it is removed from the game.
     
  16. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,594
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    No as the event can still fire again if the destructable is revived.
    In such a case one can reconstruct the trigger which will purge all events.
     
  17. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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!).
     
  18. TheLordOfChaos201

    TheLordOfChaos201

    Joined:
    Jul 2, 2011
    Messages:
    1,723
    Resources:
    0
    Resources:
    0
    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 (Text):
    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: Jan 29, 2018
  19. Sieben

    Sieben

    Joined:
    Nov 23, 2013
    Messages:
    644
    Resources:
    0
    Resources:
    0
    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: Jan 31, 2018
  20. TheLordOfChaos201

    TheLordOfChaos201

    Joined:
    Jul 2, 2011
    Messages:
    1,723
    Resources:
    0
    Resources:
    0
    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