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

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
 
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.
 
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)
 
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)
 
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
 
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)
 
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)
 
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.
 
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.
 
For those of us who have not modded in Civ V or Civ VI, what file does this code go into?

Thanks.
 
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>
 
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>
 
Back
Top Bottom