Forged Alliance Forever Forged Alliance Forever Forums 2018-02-25T20:39:55+02:00 /feed.php?f=53&t=15932 2018-02-25T20:39:55+02:00 2018-02-25T20:39:55+02:00 /viewtopic.php?t=15932&p=161229#p161229 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
Math max is using the highest number from all given args:
Code:
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

So we can use this to get the unitcap:
Code:
math.max( 2, NewCap )

Now we can build the following optimized code:
Code:
SetArmyUnitCap(INDEX, math.max( 2, NewCap ) )

This way you will have always a minimum cap of 2.

Statistics: Posted by Uveso — 25 Feb 2018, 20:39


]]>
2018-02-24T16:52:01+02:00 2018-02-24T16:52:01+02:00 /viewtopic.php?t=15932&p=161202#p161202 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
Uveso wrote:
Hello Ghoustaq,

well it's hard to see whats going wrong if i can't see the whole script.
Here an working example, ready for copy + paste to your MAP_script.lua:
Code:
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


The script will print debugmessages to the logwindow (open with [F9]) like this:
Code:
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)


This should push you in the right direction :)

WOW! It's really working! Thanks very much for directing me. :D 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


]]>
2018-02-23T22:13:31+02:00 2018-02-23T22:13:31+02:00 /viewtopic.php?t=15932&p=161186#p161186 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
well it's hard to see whats going wrong if i can't see the whole script.
Here an working example, ready for copy + paste to your MAP_script.lua:
Code:
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


The script will print debugmessages to the logwindow (open with [F9]) like this:
Code:
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)


This should push you in the right direction :)

Statistics: Posted by Uveso — 23 Feb 2018, 22:13


]]>
2018-02-23T18:08:45+02:00 2018-02-23T18:08:45+02:00 /viewtopic.php?t=15932&p=161181#p161181 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
Uveso wrote:
Hello Ghoustaq,

You need the following commands:

To get a list of all your massextractors:
Code:
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)

To count all extractors inside the list:
Code:
count = table.getn(MassExtractorUnitList)

If you want to know the actual unit cap of your army:
Code:
currentCap = GetArmyUnitCap(brain.index)

And to set a new unit cap:
Code:
SetArmyUnitCap(brain.index, newCap)


hello!Uveso:

I wrote a segment of the script.lua as below:

local tblArmy = ListArmies()
for index,army in tblArmy do
local MassExtractorUnitList = tblArmy:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)
local count = table.getn(MassExtractorUnitList)
local currentCap = GetArmyUnitCap(army)
SetArmyUnitCap(army, count/0.5)
end

Unfortunately, it doesn't work in my skirmish map. :roll: 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


]]>
2018-02-21T15:33:18+02:00 2018-02-21T15:33:18+02:00 /viewtopic.php?t=15932&p=161110#p161110 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
Uveso wrote:
Hello Ghoustaq,

You need the following commands:

To get a list of all your massextractors:
Code:
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)

To count all extractors inside the list:
Code:
count = table.getn(MassExtractorUnitList)

If you want to know the actual unit cap of your army:
Code:
currentCap = GetArmyUnitCap(brain.index)

And to set a new unit cap:
Code:
SetArmyUnitCap(brain.index, newCap)


truly grateful for your help!Master! :lol:

Statistics: Posted by Ghoustaq — 21 Feb 2018, 15:33


]]>
2018-02-21T06:49:32+02:00 2018-02-21T06:49:32+02:00 /viewtopic.php?t=15932&p=161101#p161101 <![CDATA[Re: How to make the unitcap related to the number of mass-ex]]>
You need the following commands:

To get a list of all your massextractors:
Code:
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)

To count all extractors inside the list:
Code:
count = table.getn(MassExtractorUnitList)

If you want to know the actual unit cap of your army:
Code:
currentCap = GetArmyUnitCap(brain.index)

And to set a new unit cap:
Code:
SetArmyUnitCap(brain.index, newCap)

Statistics: Posted by Uveso — 21 Feb 2018, 06:49


]]>
2018-02-20T13:58:42+02:00 2018-02-20T13:58:42+02:00 /viewtopic.php?t=15932&p=161074#p161074 <![CDATA[How to make the unitcap related to the number of mass-ex?]]> technical support from this forum. :roll:

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


]]>