Bernard Vink

Chieftain
Joined
Nov 9, 2016
Messages
10
Can anybody make a code that plot city on tile In certain years.
Because then I have option for telling historical story in my scenario what i make.
I have seen many posible code, only that works not for my mod.

I have make use the mod Unit spawn Handler
And this is now the code that work for unit to spawn on the map, also to declare war and peace between countries. It will be great when It also possible is to make also city spawn in certain turn on map.
I have also tried to make code work with giving the settler a push mission to found a city a certain turn.
But I did not get the code working in my mod.

Can anybody make so code for my but also for other mod makers.

<code>
-- ExampleMainLua
-- Author: LeeS Update: Bernard Vink and Troller0001
-- DateCreated: 5/11/2015 7:44:55 AM
--------------------------------------------------------------
include("UnitSpawnHandler.lua")

function TokyoExpress(iPlayer)
local pPlayer = Players[iPlayer]
if not pPlayer:IsAlive() then return end
---------------------------------------------------------------------------------------------------------
--CODE FOR JAPAN
---------------------------------------------------------------------------------------------------------
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JAPAN"] then
if Game.GetGameTurn() == 1 then
--here is where we would create the units

SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 109, 47, 0, 0, "NO_NAME", "NO_PROMOTION")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 109, 47, 0, 0, "NO_NAME", "NO_PROMOTION")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 109, 47, 0, 0, "NO_NAME", "NO_PROMOTION")
--1634 Poland peace with Ottoman and Russia
local pPlayer = Players[10];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[5];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[10];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[12];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );

if (pPlayer:IsHuman()) then
local TokyoExpress = "Tokyo Express Units Added!"
Events.GameplayAlertMessage(TokyoExpress)
end

print("French declare war on Spanish and join allies against The House of Habsburg in the Thirty Years' War ")
elseif Game.GetGameTurn() == 2 then
print("No Tokyo Express Units Added")
--1635 France declar war on Spain / Austria
local pPlayer = Players[1];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[2];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
local pPlayer = Players[1];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[4];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
local pPlayer = Players[6];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[13];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );

elseif Game.GetGameTurn() == 6 then
print("No Tokyo Express Units Added")
--1640 Portugal declar war on Spain
local pPlayer = Players[7];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[2];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );

elseif Game.GetGameTurn() == 14 then
print("No Tokyo Express Units Added")
--1648 Peace of Munster and the end of eight years war and thirty years war
local pPlayer = Players[3];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[5];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[3];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[2];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[6];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[2];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[6];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[5];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[5];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[8];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[2];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[8];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
end
end
---------------------------------------------------------------------------------------------------------
--CODE FOR ENGLAND
---------------------------------------------------------------------------------------------------------
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_OTTOMAN"] then
if Game.GetGameTurn() == 1 then
--here is where we would create the units

SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 48, 50, 0, 0, "Ottomans", "PROMOTION_MORALE")

if (pPlayer:IsHuman()) then
local BritishUnits = "British Units Added!"
Events.GameplayAlertMessage(BritishUnits)
end
print("Peace with Ottomans empire and the Persian Empire ")
elseif Game.GetGameTurn() == 5 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 48, 50, 0, 0, "Ottomans", "NO_PROMOTION")
print("No Tokyo Express Units Added")
--1635
local pPlayer = Players[12];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[15];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[14];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[40];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
end
end
---------------------------------------------------------------------------------------------------------
--CODE FOR FRANCE
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_FRANCE"] then
if Game.GetGameTurn() == 1 then
--here is where we would create the units
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 55, 9, 0, 0, "French East Indie Company1")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 55, 9, 0, 0, "French East Indie Company3", "PROMOTION_MORALE")
--SpawnInitialCity(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 160, 66, 0, 0, "Swedish South Company", "PROMOTION_MORALE")
--pPlayer ~= -1 and iPlayer or Map:GetPlot(iX,iY):GetOwner()
--local eOwner = playerStartPlot:GetOwner();
--local eOwner = pPlayerPlot:GetOwner(160, 66);
--if (plot:GetOwner() ~160, 66) then
--if (adjPlot:GetOwner() ~= 160, 66) then
--local initialSettler = player:InitUnit(SETTLER, startX, startY)



--if settler:GetPlot() == plot then
--settler:pushMission( MissionTypes.MISSION_FOUND )
--return
--pUnit:pushOrder (OrderTypes.ORDER_MISSION_FOUND, GameInfo.Units["UNIT_SETTLER"].ID, -1, 0, false, false);
--local city = pPlayer:InitCity(start_plot:GetX(73), start_plot:GetY(68));
--city:SetPopulation(5, true);
--SetInitialCityBuilds();

--function OnFirstCity(iPlayer, x, y)
--Dprint ("-------------------------------------")
--Dprint ("New city founded...")
--local player = Players[iPlayer]
----local city = GetPlot(x,y):GetPlotCity()
--local pCity = Map.GetPlot(29,59):GetPlotCity();
--if (player:GetNumCities() == 1 and not player:IsMinorCiv()) then
--Dprint ("-------------------------------------")
--Dprint ("Initializing first city for " .. tostring(player:GetName()))
--if Game.GetElapsedGameTurns() > ELAPSED_TURNS_FOR_BALANCE then
-- SpawnInitialCity(city)
--end
--end
--end
-- GameEvents.PlayerCityFounded.Add(OnFirstCity) -- in main Lua

if (pPlayer:IsHuman()) then
local FrenchUnits = "French Units Added!"
Events.GameplayAlertMessage(French East Indie CompanyUnits)
end
print("Peace with Ottomans empire and the Persian Empire ")
elseif Game.GetGameTurn() == 2 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "French East Indie Company")
print("No Tokyo Express Units Added")
elseif Game.GetGameTurn() == 3 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "French East Indie Company")
print("No Tokyo Express Units Added")
end
end
---------------------------------------------------------------------------------------------------------
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_SWEDEN"] then
if Game.GetGameTurn() == 1 then
--here is where we would create the units

SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "Swedish South Company1")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "Swedish South Company2", "PROMOTION_MORALE")
--SpawnInitialCity(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 160, 66, 0, 0, "Swedish South Company", "PROMOTION_MORALE")
--pPlayer ~= -1 and iPlayer or Map:GetPlot(iX,iY):GetOwner()
--local eOwner = playerStartPlot:GetOwner();
--local eOwner = pPlayerPlot:GetOwner(160, 66);
--if (plot:GetOwner() ~160, 66) then
--if (adjPlot:GetOwner() ~= 160, 66) then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 162, 64, 0, 0, "Swedish South Company3", "PROMOTION_MORALE")
--local initialSettler = player:InitUnit(SETTLER, startX, startY)



--if settler:GetPlot() == plot then
--settler:pushMission( MissionTypes.MISSION_FOUND )
--return
--pUnit:pushOrder (OrderTypes.ORDER_MISSION_FOUND, GameInfo.Units["UNIT_SETTLER"].ID, -1, 0, false, false);
--local city = pPlayer:InitCity(start_plot:GetX(73), start_plot:GetY(68));
--city:SetPopulation(5, true);
--SetInitialCityBuilds();

--function OnFirstCity(iPlayer, x, y)
--Dprint ("-------------------------------------")
--Dprint ("New city founded...")
--local player = Players[iPlayer]
----local city = GetPlot(x,y):GetPlotCity()
--local pCity = Map.GetPlot(29,59):GetPlotCity();
--if (player:GetNumCities() == 1 and not player:IsMinorCiv()) then
--Dprint ("-------------------------------------")
--Dprint ("Initializing first city for " .. tostring(player:GetName()))
--if Game.GetElapsedGameTurns() > ELAPSED_TURNS_FOR_BALANCE then
-- SpawnInitialCity(city)
--end
--end
--end
-- GameEvents.PlayerCityFounded.Add(OnFirstCity) -- in main Lua

-- function CreateCities ()
-- for lnum=0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
-- local player=Players [lnum];
-- if player:IsAlive () and player:IsMinorCiv () then
-- the conditions for adding a city are set here
-- if player:GetExcessHappiness () >= 5 and player:GetNumCities () > 0 and player:GetNumCities () < 2 then
-- local iW, iH = Map.GetGridSize ();
-- local max = 0;
-- local max_x = -73;
-- local max_y = -68;

-- for y = 0, iH - 1 do
-- for x = 0, iW - 1 do
-- local v = player:AI_foundValue (x,y);
-- if v > max then
-- max = v;
-- max_x = x;
-- max_y = y;
-- end
-- end
-- end

-- if max_x > -1 then
-- player:Found (max_x,max_y);
-- end
-- end
-- end
-- end
-- end
--Events.ActivePlayerTurnStart.Add (CreateCities);

if (pPlayer:IsHuman()) then
local BritishUnits = "British Units Added!"
Events.GameplayAlertMessage(BritishUnits)
end

print("Swedish South Company colonization of the Americas ")
elseif Game.GetGameTurn() == 2 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 160, 66, 0, 0, "Swedish South Company", "PROMOTION_MORALE")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 160, 66, 0, 0, "Swedish South Company", "PROMOTION_MORALE")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SWEDISH_GALLEON"], 159, 65, 0, 0, "Swedish South Company", "PROMOTION_MORALE")
print("No Tokyo Express Units Added")

print("British Units Added")
elseif Game.GetGameTurn() == 9 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 160, 66, 0, 0)
print("British Infantry Added")
--1643 Sweden and Netherlands declar war on Denmark
local pPlayer = Players[6];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[9];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
local pPlayer = Players[8];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[9];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
end
print("British Units Added")
elseif Game.GetGameTurn() == 12 then
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 23, 27, 0, 0)
print("British Infantry Added")
--1645 Ottoman declare war on Venetia and France - Papestate
local pPlayer = Players[12];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[11];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
local pPlayer = Players[12];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[1];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pTeam:DeclareWar( iOtherTeam, true );
--1645 Sweden and Netherlands peach with Denmark
local pPlayer = Players[6];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[9];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );
local pPlayer = Players[8];
local iTeam = pPlayer:GetTeam();
local pTeam = Teams[iTeam];
local pOtherPlayer = Players[9];
local iOtherTeam = pOtherPlayer:GetTeam();
local pOtherTeam = Teams[iOtherTeam];
pTeam:Meet( iOtherTeam, true );
pOtherTeam:Meet( iTeam, true );
pOtherTeam:MakePeace( iTeam, true );
pTeam:MakePeace( iOtherTeam, true );

end
--CODE FOR AMERICA
end

GameEvents.PlayerDoTurn.Add(TokyoExpress)

print("Sample Main Lua Loaded")
</code>
 
Top Bottom