math.max( 2, 0 ) = 2
math.max( 2, 1 ) = 2
math.max( 2, 2 ) = 2
math.max( 2, 3 ) = 3
math.max( 2, 4 ) = 4
math.max( 2, NewCap )SetArmyUnitCap(INDEX, math.max( 2, NewCap ) )Statistics: Posted by Uveso — 25 Feb 2018, 20:39
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')
function OnPopulate()
    ScenarioUtils.InitializeArmies()
    ScenarioFramework.SetPlayableArea('AREA_1', false)
end
function OnStart(self)
    ForkThread(MexWatcher)
end
function MexWatcher(self)
    -- Set variables to local use only.
    local MassExtractorUnitList
    local MexCount
    local CurrentCap
    local NewCap
    while true do
        -- Loop over every Army in this game
        for INDEX,BRAIN in ArmyBrains do
            -- Get all Extractors owned by this Brain (Army)
            MassExtractorUnitList = BRAIN:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)
            -- Reset the MexCounter
            MexCount = 0
            -- Loop over all extractors inside MassExtractorUnitList
            for index, extractor in MassExtractorUnitList do
                -- Is the extractor completed (or still in build)
                if extractor:GetFractionComplete() == 1 then
                    -- OK this extractor is finished and will count for the armycap
                    MexCount = MexCount + 1
                end
            end
            -- Get the current UnitCap (We don't need the value (CurrentCap) except for debugmessages)
            CurrentCap = GetArmyUnitCap(INDEX)
            -- Calculate the new unitcap. (extractors * 10)
            NewCap = MexCount * 10
            -- We need at least a unitcap of 2 to build the first massextractor. (Commander + new Massextractor = 2)
            if NewCap < 2 then
                NewCap = 2
            end
            -- Set the new unitcap
            SetArmyUnitCap(INDEX, NewCap)
            -- DebugMessage to the [F9] DebugWindow 
            LOG('* MexWatcher: Army('..INDEX..') has ('..MexCount..') Extractors. - Set unitcap from ('..CurrentCap..') to ('..NewCap..')')
        end
        -- Wait a second before we loop again. (if you don't wait here, the game will freeze in a deadloop)
        WaitSeconds(1)
    end
end
INFO: * MexWatcher: Army(1) has (0) Extractors. - Set unitcap from (625) to (2)
INFO: * MexWatcher: Army(2) has (0) Extractors. - Set unitcap from (625) to (2)
INFO: * MexWatcher: Army(3) has (0) Extractors. - Set unitcap from (625) to (2)

 By the way, I suggest modifying "NewCap = MexCount * 2" to "NewCap = MexCount* 2 + 2" so that the NewCap will not be less than 2.
 By the way, I suggest modifying "NewCap = MexCount * 2" to "NewCap = MexCount* 2 + 2" so that the NewCap will not be less than 2.Statistics: Posted by Ghoustaq — 24 Feb 2018, 16:52
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')
function OnPopulate()
    ScenarioUtils.InitializeArmies()
    ScenarioFramework.SetPlayableArea('AREA_1', false)
end
function OnStart(self)
    ForkThread(MexWatcher)
end
function MexWatcher(self)
    -- Set variables to local use only.
    local MassExtractorUnitList
    local MexCount
    local CurrentCap
    local NewCap
    while true do
        -- Loop over every Army in this game
        for INDEX,BRAIN in ArmyBrains do
            -- Get all Extractors owned by this Brain (Army)
            MassExtractorUnitList = BRAIN:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)
            -- Reset the MexCounter
            MexCount = 0
            -- Loop over all extractors inside MassExtractorUnitList
            for index, extractor in MassExtractorUnitList do
                -- Is the extractor completed (or still in build)
                if extractor:GetFractionComplete() == 1 then
                    -- OK this extractor is finished and will count for the armycap
                    MexCount = MexCount + 1
                end
            end
            -- Get the current UnitCap (We don't need the value (CurrentCap) except for debugmessages)
            CurrentCap = GetArmyUnitCap(INDEX)
            -- Calculate the new unitcap. (extractors * 10)
            NewCap = MexCount * 10
            -- We need at least a unitcap of 2 to build the first massextractor. (Commander + new Massextractor = 2)
            if NewCap < 2 then
                NewCap = 2
            end
            -- Set the new unitcap
            SetArmyUnitCap(INDEX, NewCap)
            -- DebugMessage to the [F9] DebugWindow 
            LOG('* MexWatcher: Army('..INDEX..') has ('..MexCount..') Extractors. - Set unitcap from ('..CurrentCap..') to ('..NewCap..')')
        end
        -- Wait a second before we loop again. (if you don't wait here, the game will freeze in a deadloop)
        WaitSeconds(1)
    end
end
INFO: * MexWatcher: Army(1) has (0) Extractors. - Set unitcap from (625) to (2)
INFO: * MexWatcher: Army(2) has (0) Extractors. - Set unitcap from (625) to (2)
INFO: * MexWatcher: Army(3) has (0) Extractors. - Set unitcap from (625) to (2)

Statistics: Posted by Uveso — 23 Feb 2018, 22:13
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)count = table.getn(MassExtractorUnitList)currentCap = GetArmyUnitCap(brain.index)SetArmyUnitCap(brain.index, newCap) Can you check it? I'm sure there is something wrong with it  'causeI am not professional in scripting.
   Can you check it? I'm sure there is something wrong with it  'causeI am not professional in scripting.Statistics: Posted by Ghoustaq — 23 Feb 2018, 18:08
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)count = table.getn(MassExtractorUnitList)currentCap = GetArmyUnitCap(brain.index)SetArmyUnitCap(brain.index, newCap)
Statistics: Posted by Ghoustaq — 21 Feb 2018, 15:33
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)count = table.getn(MassExtractorUnitList)currentCap = GetArmyUnitCap(brain.index)SetArmyUnitCap(brain.index, newCap)Statistics: Posted by Uveso — 21 Feb 2018, 06:49

Statistics: Posted by Ghoustaq — 20 Feb 2018, 13:58