Snippet Regrowing Trees

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
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
590
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
590
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
590
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
609
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,495
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
609
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
964
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
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top