function Trig_HarvestLumber_Conditions takes nothing returns boolean
return GetUnitAbilityLevel(GetTriggerUnit(),'A000') >= 1
endfunction
function isTree takes nothing returns boolean
local destructable tree = GetFilterDestructable()
local integer ID = GetDestructableTypeId(tree)
return (ID == 'LTlt' or ID == 'BTtw' or ID == 'JTtw' or ID == 'VTlt' or ID == 'DTsh') and not (GetDestructableLife(tree) <= 0)
// LTlt means lordearon sommer tree, you can check the id's with ctrl+D in the object editor, use destructables only!
endfunction
function Trig_HarvestLumber_Timer takes nothing returns nothing
local timer T = GetExpiredTimer()
local unit mill = LoadUnitHandle(udg_Hash, GetHandleId(T), StringHash("millOFtimer"))
local player P = GetOwningPlayer(mill)
local real range = 300 // 300 in top , bottom, left and right
local real damage = 10
local integer gain = 10
local real x = GetUnitX(mill)
local real y = GetUnitY(mill)
local destructable d = null
local rect r = Rect(x-range,y+range,x+range,y-range)
//local string eff = "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl"
set d = RandomDestructableInRectBJ(r, Filter(function isTree))
if GetUnitState(mill, UNIT_STATE_LIFE) <=0 then
call DestroyTimer(T)
call FlushChildHashtable(udg_Hash,GetHandleId(T))
call FlushChildHashtable(udg_Hash,GetHandleId(mill))
elseif d != null then
call SetDestructableLife(d, GetDestructableLife(d)-damage)
call SetPlayerState(P,PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(P,PLAYER_STATE_RESOURCE_LUMBER)+gain)
endif
set T = null
set mill = null
call RemoveRect(r)
set r = null
set d = null
set P = null
endfunction
function Trig_HarvestLumber_Actions takes nothing returns nothing
local unit mill = GetTriggerUnit()
local timer T = CreateTimer()
local real interval = 0.1
call SaveUnitHandle(udg_Hash, GetHandleId(T), StringHash("millOFtimer"), mill)
call TimerStart(T, interval, true, function Trig_HarvestLumber_Timer)
set mill = null
set T = null
endfunction
//===========================================================================
function InitTrig_HarvestLumber takes nothing returns nothing
set gg_trg_HarvestLumber = CreateTrigger( )
call TriggerRegisterEnterRectSimple( gg_trg_HarvestLumber, GetEntireMapRect() )
call TriggerAddCondition( gg_trg_HarvestLumber, Condition( function Trig_HarvestLumber_Conditions ) )
call TriggerAddAction( gg_trg_HarvestLumber, function Trig_HarvestLumber_Actions )
endfunction