Hi, im working on a new map and I was looking for a trigger to make trees respawn.
I found this:
Well, my problem is that i searched a lot and couldn't find HOW THE HELL DO I MAKE THIS USEFUL!
I tried making a new trigger called "regrowth", converted to personally edited text and copypasted (after erasing the previous text)
And when i test the map with World Editor, TFT opens its main screen... Not the map. So, i switched off the trigger with the library and it worked fine.
I found this:
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
Well, my problem is that i searched a lot and couldn't find HOW THE HELL DO I MAKE THIS USEFUL!
I tried making a new trigger called "regrowth", converted to personally edited text and copypasted (after erasing the previous text)
And when i test the map with World Editor, TFT opens its main screen... Not the map. So, i switched off the trigger with the library and it worked fine.