AceHart
Your Friendly Neighborhood Admin
- Reaction score
- 1,497
Regrowing trees... who wouldn't want that?
I tend to add it even to maps that can't even kill any
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.
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:
Usage is still as simple:
Copy&paste to your map, done.
I tend to add it even to maps that can't even kill any
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), 039;nmpe039;, 0, 0, 0) // Mur'gul Slave...
call SetUnitInvulnerable(u, true)
call ShowUnit(u, false)
call UnitAddAbility(u, 039;Aloc039;) // Locust
call UnitAddAbility(u, 039;Ahrl039;) // 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), 039;nmpe039;, 0, 0, 0) // Mur'gul Slave...
call SetUnitInvulnerable(u, true)
call ShowUnit(u, false)
call UnitAddAbility(u, 039;Aloc039;) // Locust
call UnitAddAbility(u, 039;Ahrl039;) // 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.