How to get the color of an army?

Interesting mapping tools and mapping help.

Moderator: Morax

How to get the color of an army?

Postby Ghoustaq » 28 Apr 2018, 20:37

GetArmyColor? It seems that there's no such a command like this.

Only "SetArmyColor" exists. I tried to search on the github, but there's no answer to this.

I want to draw some lines around an area to form a boundary with the color of one player's army and the color should change if another army takes control of this area. But I don't know how to get ARMY's color. :roll:

That's all.
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to get the color of an army?

Postby speed2 » 29 Apr 2018, 07:14

LOG(repr(ScenarioInfo.ArmySetup)) should give you some clues
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to get the color of an army?

Postby nine2 » 29 Apr 2018, 08:26

what are you making ghost?
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: How to get the color of an army?

Postby CookieNoob » 30 Apr 2018, 13:07

In case the hint from speed wasnt sufficient:

Code: Select all
determineArmyColor = function (self)
    local tblArmy = ListArmies()
    local army = self:GetArmy()      -- or whatever way is needed in your case
    return ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor
end
Check out the next level of maps: viewtopic.php?f=53&t=13014
For adaptivity, customizability and less clutter in the vault.
User avatar
CookieNoob
Priest
 
Posts: 477
Joined: 02 Aug 2014, 17:07
Has liked: 65 times
Been liked: 249 times
FAF User Name: CookieNoob

Re: How to get the color of an army?

Postby speed2 » 30 Apr 2018, 16:09

CookieNoob wrote:In case the hint from speed wasnt sufficient:

Code: Select all
determineArmyColor = function (self)
    local tblArmy = ListArmies()
    local army = self:GetArmy()      -- or whatever way is needed in your case
    return ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor
end

I was lazy to code/test, but I dont think this will work, the format in the ArmySetup table is "ARMY_1" etc, while ListArmies() gives a table of armies' indexes (numbers).

But I guess that's up to OP to test and learn anyway :D
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to get the color of an army?

Postby Ghoustaq » 30 Apr 2018, 17:57

Anihilnine wrote:what are you making ghost?


In brief, it's a map based on the wars between the ancient states in history

In my design, the boundary of a state should adjust to its expansion or contraction just like what happens in the game "Total War".
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to get the color of an army?

Postby Ghoustaq » 30 Apr 2018, 21:00

@CookieNoob @speed2

Thank both of you! I wrote some code with the commands you offered. It does work.
Because the values of colors in ScenarioInfo.ArmySetup are just numbers from 1 to 10 according to the rank in the drop down list of 'color' in 'skirmish setup', I have to correlate the numbers with RGB Color Codes.


Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

function OnPopulate()
    ScenarioUtils.InitializeArmies()   
    ForkThread(DrawBoundaryLine)
end

function DrawBoundaryLine(self)
    local location
    local entities
    local units
    local Color0 = 'FFCEA984'    -- CIVILIAN Color
    local Color1 = 'FFe80a0a'    -- Cybran red
    local Color2 = 'ff2e8b57'    -- new green
    local Color3 = 'FF2929e1'    -- UEF blue
    local Color4 = 'ffa79602'    -- Sera golden
    local Color5 = 'ffffffff'    -- white
    local Color6 = 'FF2F4F4F'    -- dark green
    local Color7 = 'ff000000'    -- black
    local Color8 = 'ff901427'    -- dark red
    local Color9 = 'ff40bf40'    -- mid green
    local Color10 = 'FF5F01A7'   -- dark purple

    while true do
        for k = 1, 3 do
            location = ScenarioUtils.MarkerToPosition('BuffArea_' .. k)
            entities = GetUnitsInRect( Rect(location[1]-11, location[3]-11, location[1]+11, location[3]+11) )
            if entities then
                units = EntityCategoryFilterDown(categories.HYDROCARBON + categories.MASSEXTRACTION, entities)
            end
            if units then
                -- check first if the trigger unit is still present
                if units[1] and not units[1].Dead and not units[1]:BeenDestroyed() and units[1]:GetFractionComplete() == 1 then
                   for _,instigator in units do
                         local tblArmy = ListArmies()
                         local army = instigator:GetArmy()
                       if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyName) ~= '"ARMY_9"' then   
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '1' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color1 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '2' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color2 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '3' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color3 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '4' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color4 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '5' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color5 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '6' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color6 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '7' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color7 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '8' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color8 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '9' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color9 )
                         end
                         if repr(ScenarioInfo.ArmySetup[tblArmy[army]].ArmyColor) == '10' then
                                DrawLine({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color10 )
                         end
                      else
                                DrawLinePop({2684.5, 63.96, 489.5}, {2682.5, 63.96, 514.5}, Color0 )
                                DrawLinePop({2682.5, 63.96, 514.5}, {2684.5, 63.96, 489.5}, Color0 )
                      end
                   end
                end   
            end
        end
        WaitSeconds(0) -- waits 5 second. Can be reduced to 1 tick if needed
   end
end
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq


Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest