Snippet Regrowing Trees

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Regrowing trees... who wouldn't want that?
I tend to add it even to maps that can't even kill any :p

Anyway, given it's simple but still annoying to recreate it for every map, I made a library out of that thing.
Copy&paste to your map, map header for example, done.


Required edits:
- "RegrowAfter" is simply the time in seconds it takes a tree until it regrows.


JASS:
library REGROWTREES initializer Init
globals
    private constant real RegrowAfter = 23.0 // seconds to wait until tree regrows
    private unit u
endglobals
private function IsTree takes nothing returns boolean
    local boolean b
    call SetUnitX(u, GetWidgetX(GetFilterDestructable()))
    call SetUnitY(u, GetWidgetY(GetFilterDestructable()))
    set b = IssueTargetOrder(u, "harvest", GetFilterDestructable())
    call IssueImmediateOrder(u, "stop")
    return b
endfunction
private function Regrow takes nothing returns nothing
    call TriggerSleepAction(RegrowAfter)
    call DestructableRestoreLife(GetDyingDestructable(), GetDestructableMaxLife(GetDyingDestructable()), true)
endfunction
private function Register takes nothing returns nothing
    call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endfunction
private function Init takes nothing returns nothing
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nmpe', 0, 0, 0) // Mur'gul Slave...
    call SetUnitInvulnerable(u, true)
    call ShowUnit(u, false)
    call UnitAddAbility(u, 'Aloc') // Locust
    call UnitAddAbility(u, 'Ahrl') // Harvest Lumber
    set bj_destInRegionDiesTrig = CreateTrigger()
    call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function IsTree), function Register)
    call TriggerAddAction(bj_destInRegionDiesTrig, function Regrow)
    call RemoveUnit(u)
    set u = null
endfunction
endlibrary



Thanks to a brilliant idea by PitzerMike, no tree types or related input is required.
A tree is any destructible that can be harvested for Lumber.
Works on custom trees too.


By popular request, here's a version that waits for all units within a given range of the dead tree to first leave before it attempts to regrow:
JASS:
library REGROWTREES initializer Init
globals
    private constant real RegrowAfter = 23.0 // seconds to wait until tree regrows
    private constant real Range = 250.0      // distance around tree that needs to be free of units before regrowing
    private unit u
    private group g = CreateGroup()
    private boolexpr b
    private boolean ok
endglobals
private function IsTree takes nothing returns boolean
    local boolean b
    call SetUnitX(u, GetWidgetX(GetFilterDestructable()))
    call SetUnitY(u, GetWidgetY(GetFilterDestructable()))
    set b = IssueTargetOrder(u, "harvest", GetFilterDestructable())
    call IssueImmediateOrder(u, "stop")
    return b
endfunction
private function W2D takes widget w returns destructable
    return w // do not inline
    return null
endfunction
private function IsUnitNear takes nothing returns boolean
    if GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.5 then
        set ok = false
    endif
    return false
endfunction
private function Regrow takes nothing returns nothing
    local widget t = GetTriggerWidget()
    call TriggerSleepAction(RegrowAfter)
    loop
        set ok = true
        call GroupClear(g)
        call GroupEnumUnitsInRange(g, GetWidgetX(t), GetWidgetY(t), Range, b)
        exitwhen ok
        call TriggerSleepAction(3.0)
    endloop
    call DestructableRestoreLife(W2D(t), GetDestructableMaxLife(W2D(t)), true)
    set t = null
endfunction
private function Register takes nothing returns nothing
    call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endfunction
private function Init takes nothing returns nothing
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nmpe', 0, 0, 0) // Mur'gul Slave...
    call SetUnitInvulnerable(u, true)
    call ShowUnit(u, false)
    call UnitAddAbility(u, 'Aloc') // Locust
    call UnitAddAbility(u, 'Ahrl') // Harvest Lumber
    set bj_destInRegionDiesTrig = CreateTrigger()
    call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function IsTree), function Register)
    call TriggerAddAction(bj_destInRegionDiesTrig, function Regrow)
    set b = Condition(function IsUnitNear)
    call RemoveUnit(u)
    set u = null
endfunction
endlibrary


Usage is still as simple:
Copy&paste to your map, done.
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
589
JASS:
    return t == 'VTlt' or t == 'CTtr' or t == 'Cttc' // Edit tree-types as needed


Shove into the globals block?
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
589
JASS:
globals
    private constant real RegrowAfter = 23.0 // seconds to wait until tree regrows
    private constant integer TREE1 = 'VTlt'
    private constant integer TREE2 = 'CTtr'
    private constant integer TREE3 = 'Cttc'
    private constant integer TREE4-10 = blah
endglobals
private function TreeTypeFilter takes nothing returns boolean
    local integer t = GetDestructableTypeId(GetFilterDestructable())
    return t == TREE1 or t == TREE2 or t == TREE3 or t == TREE4-10
endfunction


It'll make it more newbie friendly. And you can do up to 10 and throw in instructions on how to go over 10.
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
589
You can do the
JASS:
return t == TREE1 or t == TREE2 or t == TREE3 or t == TREE4 or t == TREE5 or t == TREE6 or t == TREE7 or t == TREE8 or t == TREE9 or t == TREE10

Just make it so that users can easily change them.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Considering this is a 21 line snippet, I'm pretty confident people can locate the 7:th line with the comment "//Edit tree-types as needed".
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
Nice script :thup: I was just wondering if a unit is in the way does it get moved out of the area or does the tree not grow?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
The trees ALWAYS grow back :p
In theory, it's possible to end up with a configuration that traps a unit in the middle of a forest.
Though that's dark theory only, and not "limited" to this script.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
The trees ALWAYS grow back :p
In theory, it's possible to end up with a configuration that traps a unit in the middle of a forest.
Though that's dark theory only, and not "limited" to this script.

Oh :p I didn't know because usually I play melee games and the trees never grow back to know what will happen.
 

Romek

Super Moderator
Reaction score
963
You could use this:

JASS:
t == 'ATtr' or t=='BTtw'or t=='KTtw' or t=='YTft' or t=='JTct' or t=='YTst' or t=='YTct' or t=='YTwt' or t=='JTwt' or t=='DTsh' or t=='FTtw' or t=='CTtr' or t=='ITtw' or t=='NTtw' or t=='OTtw' or t=='ZTtw' or t=='WTst' or t=='LTlt' or t=='GTsh' or t=='Xtlt' or t=='WTtw' or t=='Attc' or t=='BTtc' or t=='CTtc' or t=='ITtc' or t=='NTtc' or t=='ZTtc'


And maybe make another function where the user can put in their own trees:
JASS:
private function TreeFilterCustom takes nothing returns boolean
    local integer t = GetDestructableTypeId(GetFilterDestructable())
    return false // Remove "false" and put in the Raw codes of custom trees here
endfunction

private function TreeTypeFilter takes nothing returns boolean
    local integer t = GetDestructableTypeId(GetFilterDestructable())
    return t == 'ATtr' or t=='BTtw'or t=='KTtw' or t=='YTft' or t=='JTct' or t=='YTst' or t=='YTct' or t=='YTwt' or t=='JTwt' or t=='DTsh' or t=='FTtw' or t=='CTtr' or t=='ITtw' or t=='NTtw' or t=='OTtw' or t=='ZTtw' or t=='WTst' or t=='LTlt' or t=='GTsh' or t=='Xtlt' or t=='WTtw' or t=='Attc' or t=='BTtc' or t=='CTtc' or t=='ITtc' or t=='NTtc' or t=='ZTtc' or TreeFilterCustom() 
endfunction
 

Matrix

New Member
Reaction score
5
I remember that there is a IsDestTree function, try to search on wc3jass.com or hive
 

Matrix

New Member
Reaction score
5
JASS:
//=======================================//
//Credits to PitzerMike for this function//
//=======================================//

globals
    private constant integer DUMMY_ID = 'h000'
endglobals

private function TreeFilter takes nothing returns boolean
    local destructable d = GetFilterDestructable()
    local boolean i = IsDestructableInvulnerable(d)
    local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID, GetWidgetX(d), GetWidgetY(d), 0)
    local boolean result = false

    call UnitAddAbility(u, 'Ahrl')

    if i then
        call SetDestructableInvulnerable(d, false)
    endif

    set result = IssueTargetOrder(u, "harvest", d)
    call RemoveUnit(u)

    if i then
      call SetDestructableInvulnerable(d, true)
    endif

    set u = null
    set d = null
    return result
endfunction
 

Charapanga

New Member
Reaction score
46
Quick noob question:
How do i copy and paste it to my map?
And is this for all types of trees?

(i'm a noob at jass, i know what some mean, not all)
 
E

eraserboy

Guest
i'm very noob

sory but... can u explain how to copy to the map? i'm very very noob TT

in my map.... copy to..... where?

maybe i should open anything else first ?
after i opened the map...
then paste it....

thx..
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Make a new trigger.
Go to "Edit -> Convert to Custom Text".
Erase what's there and paste the script into it.
Save the map.
GG!

Oh, and nice snippet AceHart!
Might use this in my AoS.
 
E

eraserboy

Guest
error =C

i just did what u told me to do to paste the config wolf... but there's an error when i saved the map...

it said "script error"
all script are error....

how's that?

maybe there is another editor?

i only use editor that i got from the frozen throne cd

the error is like this

47 compile error
...
Note: rest edited out
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Put all that in a quote tag please :eek: .
And you need Jass NewGen WE (i think?)

EDIT: @AceHart: Could you make the unit "holdposition" instead of "stop"?
I know it's easily configured, but for people who don't know how it's nice.
 
General chit-chat
Help Users
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top