function HarvestLoop takes nothing returns nothing
local unit fog = null
local destructable d = null
if FirstOfGroup(udg_Harvest_Group[0]) == null then
call PauseTimer(LoadTimerHandle(udg_Harvest_Hashtable, 0, 0))
return
endif
loop
set fog = FirstOfGroup(udg_Harvest_Group[0])
exitwhen fog == null
call GroupRemoveUnit(udg_Harvest_Group[0], fog)
if GetWidgetLife(fog) > .405 then
call GroupAddUnit(udg_Harvest_Group[1], fog)
set d = LoadDestructableHandle(udg_Harvest_Hashtable, GetHandleId(fog), 0)
if d != null and GetWidgetLife(d) > .405 and IsUnitInRangeXY(fog, GetDestructableX(d), GetDestructableY(d), udg_Harvest_Distance) then
call SetWidgetLife(d, GetWidgetLife(d) + udg_Harvest_Heal)
endif
set d = null
else
call GroupRemoveUnit(udg_Harvest_Group[0], fog)
call FlushChildHashtable(udg_Harvest_Hashtable, GetHandleId(fog))
endif
endloop
// Swap
set udg_Harvest_Group[2] = udg_Harvest_Group[0]
set udg_Harvest_Group[0] = udg_Harvest_Group[1]
set udg_Harvest_Group[1] = udg_Harvest_Group[2]
endfunction
function HarvestOrder takes nothing returns nothing
local destructable d = GetOrderTargetDestructable()
local unit u = GetTriggerUnit()
if GetUnitTypeId(u) == udg_Harvest_Worker and udg_Harvest_TreeChecker != u then
if IssueTargetOrderById(udg_Harvest_TreeChecker, 852018, d) and (GetUnitCurrentOrder(u) == 851971 or GetUnitCurrentOrder(u) == 852018 or GetUnitCurrentOrder(u) == 851970) then
if FirstOfGroup(udg_Harvest_Group[0]) == null then
call TimerStart(LoadTimerHandle(udg_Harvest_Hashtable, 0, 0), udg_Harvest_Interval, true, function HarvestLoop)
endif
call GroupAddUnit(udg_Harvest_Group[0], u)
call SaveDestructableHandle(udg_Harvest_Hashtable, GetHandleId(u), 0, d)
else
call GroupRemoveUnit(udg_Harvest_Group[0], u)
call FlushChildHashtable(udg_Harvest_Hashtable, GetHandleId(u))
endif
call IssueImmediateOrderById(udg_Harvest_TreeChecker, 851972)
endif
set d = null
set u = null
endfunction
//===========================================================================
function InitTrig_Harvest takes nothing returns nothing
local trigger harvest = CreateTrigger()
//=============CONFIG==============//
//set udg_Harvest_Worker = 'hpea' // The raw code of your worker.
//set udg_Harvest_Interval = 1. // This is the interval that it takes to heal a tree.
//set udg_Harvest_Heal = 2. // How much life should a tree receive for every Harvest_Interval. (Default: 2 HP/sec)
//set udg_Harvest_Distance = 150. // The maximum distance your worker must be from the tree in order to start healing it.
//=============CONFIG==============//
// Harvest order
call TriggerRegisterAnyUnitEventBJ(harvest, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterAnyUnitEventBJ(harvest, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterAnyUnitEventBJ(harvest, EVENT_PLAYER_UNIT_ISSUED_ORDER)
call TriggerAddAction(harvest, function HarvestOrder)
// Tree Checker
set udg_Harvest_TreeChecker = CreateUnit(Player(15), 'hpea', 0, 0, 270)
call UnitAddAbility(udg_Harvest_TreeChecker, 'Aloc')
call UnitAddAbility(udg_Harvest_TreeChecker, 'Ahar')
call SetUnitUseFood(udg_Harvest_TreeChecker, false)
call ShowUnit(udg_Harvest_TreeChecker, false)
set udg_Harvest_Hashtable = InitHashtable()
call SaveTimerHandle(udg_Harvest_Hashtable, 0, 0, CreateTimer())
set harvest = null
endfunction