technical support from this forum.

Forged Alliance Forever Forums
Moderator: Morax
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)
Uveso wrote:Hello Ghoustaq,
You need the following commands:
To get a list of all your massextractors:
- Code: Select all
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)
To count all extractors inside the list:
- Code: Select all
count = table.getn(MassExtractorUnitList)
If you want to know the actual unit cap of your army:
- Code: Select all
currentCap = GetArmyUnitCap(brain.index)
And to set a new unit cap:
- Code: Select all
SetArmyUnitCap(brain.index, newCap)
Uveso wrote:Hello Ghoustaq,
You need the following commands:
To get a list of all your massextractors:
- Code: Select all
MassExtractorUnitList = aiBrain:GetListOfUnits(categories.MASSEXTRACTION * (categories.TECH1 + categories.TECH2 + categories.TECH3), false, false)
To count all extractors inside the list:
- Code: Select all
count = table.getn(MassExtractorUnitList)
If you want to know the actual unit cap of your army:
- Code: Select all
currentCap = GetArmyUnitCap(brain.index)
And to set a new unit cap:
- Code: Select all
SetArmyUnitCap(brain.index, newCap)
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)
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: Select all
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: Select all
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
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 ) )
Users browsing this forum: No registered users and 1 guest