1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

How can I add a starting unit in eras.xml so that only human players get it, not AI?

Discussion in 'Civ6 - Creation & Customization' started by jwsimms42, Nov 7, 2016.

  1. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
  2. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    Okay, so I finally got back to mucking about with this... and I cannot for the life of me figure out how to get different quantities for each unit type I want.

    Or rather, the correct amount of quantities I want... I did manage to get myself 5 scouts and 10 settlers. *wry*

    So what needs to change so I can specify;
    Scouts x4
    Settlers x2
    Warriors x5
    >other unit< = 7
     
  3. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    1st, make sure you define each unit you want,

    exp:
    Code:
    local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
    then place each creation command within a for argument:

    Code:
    for i = 1, 2 do
       pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())   
    end
    change the 2 to the number you wish to spawn. You can also add the function to get adjacent plot if you don't want them to spawn in same tile.
     
  4. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    I knew to define the units I wanted...

    Gotcha. Now hopefully I can go do that without screwing it up. :p

    Thanks again for the help! :)
     
  5. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    Okay... this doesn't work... Am I missing an 'end' in here somewhere or is it something else I'm doing wrong?

    Code:
    local iScout = GameInfo.Units["UNIT_SCOUT"].Index
    local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
    
    
    local function OnPlayerTurnActivated( player, bIsFirstTime )
    local pUnit;
    
        if (bIsFirstTime and player == Game.GetLocalPlayer()) then
        local currentTurn = Game.GetCurrentGameTurn();
        local SpawnTurn = 0;
        local playerUnits;
        local adjacentPlot;
        local unitPlot;
            if 1 == currentTurn then
            local pPlayer = Players[player]
                if pPlayer:IsHuman() then
                 playerUnits = pPlayer:GetUnits()
    
    print("SpawnTurn", SpawnTurn)    ;
                    for i, unit in playerUnits:Members() do
                        local unitTypeName = UnitManager.GetTypeName(unit)
    print("unitTypeName", unitTypeName)    ;
                        if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
                            SpawnTurn = 1;
                            unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
                            print("SpawnTurn", SpawnTurn)    ;
                        end
                    end
                end
    
                if SpawnTurn == 1 then
    print("yeps", SpawnTurn)    ;
                for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break
                            end
                        end
    
                for i = 1, 2 do
                       pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
                end
                 
                end
            end
        end
    end
    
    
    
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
    
     
  6. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    you end of functions are off:
    paste this over, of just adjust so "end"s are in right place.
    Code:
    local iScout = GameInfo.Units["UNIT_SCOUT"].Index
    local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
    
    
    local function OnPlayerTurnActivated( player, bIsFirstTime )
    local pUnit;
    
        if (bIsFirstTime and player == Game.GetLocalPlayer()) then
        local currentTurn = Game.GetCurrentGameTurn();
        local SpawnTurn = 0;
        local playerUnits;   
        local adjacentPlot;
        local unitPlot;
            if 1 == currentTurn then   
            local pPlayer = Players[player]
                if pPlayer:IsHuman() then
                 playerUnits = pPlayer:GetUnits()
                    
    print("SpawnTurn", SpawnTurn)    ;               
                    for i, unit in playerUnits:Members() do
                        local unitTypeName = UnitManager.GetTypeName(unit)
    print("unitTypeName", unitTypeName)    ;
                        if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
                            SpawnTurn = 1;
                            unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
                            print("SpawnTurn", SpawnTurn)    ;       
                        end
                    end
                end       
                
                if SpawnTurn == 1 then
    
                    for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())   
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break       
                            end
                        end
                        
                    end
                    for i = 1, 2 do       
                        pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())   
                        
                        
                        
                    end   
                    Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
                end
                
            end
        end
    end
                
    
    
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
     
  7. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    Ah, so I need the;
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)

    after each unit that I do this for as well. Got it.

    I think. ;)
     
  8. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    No you only need that line once at bottom.
    The other one is to remove the event from triggering again (note .Add and .Remove)

    The problem with your code was the placement of the end of functions (end)
    Your Code:
    Code:
               for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break
                            end
                        end
    
                for i = 1, 2 do
                       pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
                end
           
                end
    You see the diffenece with the placement of "end"
    Code:
                   for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break  
                            end
                        end
                   
                    end
                    for i = 1, 2 do  
                        pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
                   
                    end   
     
  9. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    Yes, I got it now. Finally. :D

    You sir and or madame, are a god/goddess among mere mortals. ;)
     
  10. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    okay, apparently I don't get it.

    I did add to the top;
    local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index

    Code:
    
                    for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break
                            end
                        end
    
                    end
                    for i = 1, 2 do
                        pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
    
                    end
                    Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
    
    
                    for i = 1, 1 do
                        pUnit3 = playerUnits:Create(iBuilder, adjacentPlot:GetX(), adjacentPlot:GetY())
                    end
                         Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
    
    
                end
            end
        end
    end
    
    
    
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
    
     
  11. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    Take out the first:
    Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)

    You are removing the event before finishing.
    This needs to be the last entry.
     
  12. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    okay... I'm missing something else... again. I removed the 1st .Remove and fired up the game... nothing triggered.

    Here's what I have as of this moment;

    Code:
    local iScout = GameInfo.Units["UNIT_SCOUT"].Index
    local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
    local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index
    
    local function OnPlayerTurnActivated( player, bIsFirstTime )
    local pUnit;
    
        if (bIsFirstTime and player == Game.GetLocalPlayer()) then
        local currentTurn = Game.GetCurrentGameTurn();
        local SpawnTurn = 0;
        local playerUnits;
        local adjacentPlot;
        local unitPlot;
            if 1 == currentTurn then
            local pPlayer = Players[player]
                if pPlayer:IsHuman() then
                 playerUnits = pPlayer:GetUnits()
    
    print("SpawnTurn", SpawnTurn)    ;
                    for i, unit in playerUnits:Members() do
                        local unitTypeName = UnitManager.GetTypeName(unit)
    print("unitTypeName", unitTypeName)    ;
                        if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
                            SpawnTurn = 1;
                            unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
                            print("SpawnTurn", SpawnTurn)    ;
                        end
                    end
                end
    
                if SpawnTurn == 1 then
    
                    for i = 1, 5 do
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(pUnit:GetX(), pUnit:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break
                            end
                        end
    
                    end
                    for i = 1, 2 do
                        pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
                    end
    
                    for i = 1, 1 do
                        pUnit3 = playerUnits:Create(iBuilder, adjacentPlot:GetX(), adjacentPlot:GetY())
                    end
    
                         Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
    
                end
            end
        end
    end
    
    
    
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
    
     
  13. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    I don't immediately see anything wrong, are you loading it as a gamescript ?

    Here's code I was messing with, I included a worker too,. It's basically same except I was toying with spawn plots.
    Code:
    local iScout = GameInfo.Units["UNIT_SCOUT"].Index
    local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
    local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index
    
    [SPOILER]local function OnPlayerTurnActivated( player, bIsFirstTime )
    local pUnit;
    
        if (bIsFirstTime and player == Game.GetLocalPlayer()) then
        local currentTurn = Game.GetCurrentGameTurn();
        local SpawnTurn = 0;
        local playerUnits;   
        local adjacentPlot;
        local unitPlot;
            if 1 == currentTurn then   
            local pPlayer = Players[player]
                if pPlayer:IsHuman() then
                 playerUnits = pPlayer:GetUnits()
                    
    print("SpawnTurn", SpawnTurn)    ;               
                    for i, unit in playerUnits:Members() do
                        local unitTypeName = UnitManager.GetTypeName(unit)
    print("unitTypeName", unitTypeName)    ;
                        if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
                            SpawnTurn = 1;
                            unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
                            print("SpawnTurn", SpawnTurn)    ;       
                        end
                    end
                end       
                
                if SpawnTurn == 1 then
                    local lastPlot = unitPlot;
                    for i = 1, 5 do
                            
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() + 1), lastPlot:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break       
                            end
                        end
                        pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
                        lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
                    end
                    
                    for i = 1, 2 do   
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() ), lastPlot:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break       
                            end
                        end
                        pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())   
                        lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
                    end   
    
                     for i = 1, 1 do
                        for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
                            adjacentPlot = Map.GetAdjacentPlot(lastPlot:GetX(), lastPlot:GetY(), direction);
                            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                                break       
                            end
                        end
                        pUnit3 = playerUnits:Create(iBuilder, lastPlot:GetX(), lastPlot:GetY())
                        lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
                    end
                    Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
                end
                
            end
        end
    end
                
    
    
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
    [/SPOILER]

    This works on mine, so try running it to see if problem is elsewhere.
     
  14. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    I've been trying everything I can... Cleared out cache, deleted/readded files into the mods section, scanned through the logs, even rebooted my machine just in case...

    Somewhere along the way, it just started working. I don't know why... I don't know what it was... because I launched the game after every single thing tried...

    After the reboot and on the 2nd try, it just worked. Launched the game 5 times and each time it worked. *shakes head* I have no idea....

    Came back to tell you that and now I see a pretty new mess I want to go play with... I also don't want to press my luck since it's working now lol.
     
  15. Mynex

    Mynex Warlord

    Joined:
    Sep 30, 2010
    Messages:
    287
    oh and yea, I was loading it as a gamescript. Made sure my ModID was unique as well.

    Like I said, I don't know what it was, but at least it's working now.
     
  16. wotan321

    wotan321 Emperor

    Joined:
    Oct 25, 2001
    Messages:
    1,218
    Location:
    NC, USA
    For those of us who have not modded in Civ V or Civ VI, what file does this code go into?

    Thanks.
     
  17. gyogen2

    gyogen2 Emperor

    Joined:
    May 8, 2014
    Messages:
    1,201
    It doesn't go into a vanilla file, it is from a mod. You can find it here , or Mynex had a version on nexus (see his signature under his post)
     
  18. wotan321

    wotan321 Emperor

    Joined:
    Oct 25, 2001
    Messages:
    1,218
    Location:
    NC, USA
    Thanks. That is very helpful.
     
  19. Pusperk

    Pusperk Chieftain

    Joined:
    Dec 24, 2015
    Messages:
    28
    Add units on start for human only

    Code:
    <GameInfo>
        <Modifiers>
            <!--Grant Unit-->
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <ModifierType>MODIFIER_SINGLE_CITY_GRANT_UNIT_IN_CITY</ModifierType>
                <RunOnce>true</RunOnce>
                <Permanent>true</Permanent>
                <OwnerRequirementSetId>PLAYER_IS_HUMAN</OwnerRequirementSetId>
            </Row>
        </Modifiers>
        <ModifierArguments>
            <!--Grant Unit-->
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <Name>UnitType</Name>
                <Value>UNIT_SCOUT</Value>
            </Row>
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <Name>Amount</Name>
                <Value>1</Value>
            </Row>
        </ModifierArguments>
    </GameInfo>
     
  20. Pusperk

    Pusperk Chieftain

    Joined:
    Dec 24, 2015
    Messages:
    28
    I forget add modifier to building

    Code:
    <GameInfo>
        <Modifiers>
            <!--Grant Unit-->
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <ModifierType>MODIFIER_SINGLE_CITY_GRANT_UNIT_IN_CITY</ModifierType>
                <RunOnce>true</RunOnce>
                <Permanent>true</Permanent>
                <OwnerRequirementSetId>PLAYER_IS_HUMAN</OwnerRequirementSetId>
            </Row>
        </Modifiers>
        <ModifierArguments>
            <!--Grant Unit-->
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <Name>UnitType</Name>
                <Value>UNIT_SCOUT</Value>
            </Row>
            <Row>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
                <Name>Amount</Name>
                <Value>1</Value>
            </Row>
        </ModifierArguments>
        <BuildingModifiers>
            <!--Grant Unit-->
            <Row>
                <BuildingType>BUILDING_PALACE</BuildingType>
                <ModifierId>TCS_PALACE_GRANT_SCOUT</ModifierId>
            </Row>
        </BuildingModifiers>
    </GameInfo>
     

Share This Page