Still WIP but it's almost finished.
library LumberSystem initializer myInit
globals
private hashtable h = InitHashtable()
private group g
private group mills = CreateGroup()
private unit tempUnit
endglobals
function workerFunction takes nothing returns nothing
local unit u = GetEnumUnit()
if IsUnitLoadedBJ(u) == false and LoadBoolean(h, GetHandleId(u), 3) == true then
call SaveBoolean(h, GetHandleId(u), 3, false)
call GroupRemoveUnit(LoadGroupHandle(h, GetHandleId(tempUnit), 1), u)
call SaveInteger(h, GetHandleId(tempUnit), 2, LoadInteger(h, GetHandleId(tempUnit), 2) - 1)
call BJDebugMsg("exit")
endif
endfunction
function groupFunction takes nothing returns nothing
local unit u = GetEnumUnit()
local group tGroup = LoadGroupHandle(h, GetHandleId(u), 1)
local integer i = CountUnitsInGroup(tGroup)
local texttag t = CreateTextTag()
local integer loopi = 1
local integer ih = GetHandleId(u)
if i > 0 then
call SetTextTagText(t, I2S(10 * i), 0.023)
call SetTextTagPos(t, GetUnitX(u), GetUnitY(u), 100)
call SetTextTagColor(t, 0, 255, 0, 0)
call SetTextTagVelocityBJ(t, 64, 90)
call SetTextTagPermanent(t, false)
call SetTextTagFadepoint(t, 1)
call SetTextTagLifespan(t, 3)
endif
set tempUnit = u
call ForGroup(tGroup, function workerFunction)
set t = null
endfunction
function periodicLumber takes nothing returns nothing
call ForGroup(mills, function groupFunction)
endfunction
function unitEntersMill takes nothing returns nothing
local integer i = GetHandleId(GetTransportUnit())
local integer count = LoadInteger(h, i, 2)
call SaveInteger(h, i, 2, count + 1)
call GroupAddUnit(LoadGroupHandle(h, i, 1), GetTriggerUnit())
call SaveBoolean(h, GetHandleId(GetTriggerUnit()), 3, true)
endfunction
function newLumberMill takes nothing returns nothing
set g = CreateGroup()
call SaveGroupHandle(h, GetHandleId(GetConstructedStructure()), 1, g)
call GroupAddUnit(mills, GetConstructedStructure())
endfunction
function newLumberMillInit takes nothing returns nothing
set g = CreateGroup()
call SaveGroupHandle(h, GetHandleId(GetEnumUnit()), 1, g)
call GroupAddUnit(mills, GetEnumUnit())
endfunction
function myInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddAction(t, function newLumberMill)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_LOADED )
call TriggerAddAction(t, function unitEntersMill)
set t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 1.0)
call TriggerAddAction(t, function periodicLumber)
call ForGroup(GetUnitsOfTypeIdAll('h001'), function newLumberMillInit)
set t = null
endfunction
endlibrary
xD