I don't know of any way to that with xml right now. I do have a lua script that will spawn a scout for human player on first turn(i was messing around with create function).
The only problem right now is gamescripts will only load in new game, but that would be fine for this purpose.
pUnit = playerUnits:Create(iScout, unit:GetX(), unit:GetY())
local pUnit = playerUnits:Create(iScout, unit:GetX(), unit:GetY())
pUnit:JumpToNearestValidPlot();
local iScout = GameInfo.Units["UNIT_SCOUT"].Index
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local function OnPlayerTurnActivated( player, bIsFirstTime )
local pUnit;
print("running");
if (bIsFirstTime and player == Game.GetLocalPlayer()) then
local currentTurn = Game.GetCurrentGameTurn();
if 1 == currentTurn then
local pPlayer = Players[player]
if pPlayer:IsHuman() then
local adjacentPlot;
local playerUnits = pPlayer:GetUnits()
for i, unit in playerUnits:Members() do
local unitTypeName = UnitManager.GetTypeName(unit)
print("unitTypeName", unitTypeName) ;
if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
local pUnit = playerUnits:Create(iScout, unit:GetX(), unit:GetY())
pUnit:JumpToNearestValidPlot();
end
end
end
if pPlayer:IsHuman() then
local adjacentPlot;
local playerUnits = pPlayer:GetUnits()
for i, unit in playerUnits:Members() do
local unitTypeName = UnitManager.GetTypeName(unit)
print("unitTypeName", unitTypeName) ;
if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
local pUnit = playerUnits:Create(iSettler, unit:GetX(), unit:GetY())
pUnit:JumpToNearestValidPlot();
end
end
end
end
end
end
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
local iScout = GameInfo.Units["UNIT_SCOUT"].Index
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local function OnPlayerTurnActivated( player, bIsFirstTime )
local pUnit;
print("running");
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()
for i, unit in playerUnits:Members() do
local unitTypeName = UnitManager.GetTypeName(unit)
if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
SpawnTurn = 1;
unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
end
end
end
if SpawnTurn == 1 then
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
pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
end
end
end
end
Open Lua.log or launch firetuner. It will tell you the line with error.@gyogen2
Here's what I have for a single scout & settler, can you point out where I failed please?
local function OnPlayerTurnActivated( iPlayer, bIsFirstTime )
local pPlayer = Players[iPlayer]
if pPlayer:IsHuman() and Game.GetCurrentGameTurn() == 1 then
local pCapitalCity = pPlayer:GetCities():GetCapitalCity()
local pPlayerUnits = pPlayer:GetUnits()
local pUnit = pPlayerUnits:Create(GameInfo.Units["UNIT_SCOUT"].Index, pCapitalCity:GetX(), CapitalCity:GetY())
end
end
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
for i = 1, 2 do
-- unit creation code--
end
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, 2 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
pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
end
end
end
end
end
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)