[BNW] Declare war lue code

Bernard Vink

Chieftain
Joined
Nov 9, 2016
Messages
10
I would like see a working code for declare war code (lue) with many major civs for scenario plan. For now have i this problem with existing code, that its only works when (Ai) Player 1 declare war on player 0 (Ai).
When i change this code for player 3 (Ai) declare war on player 4 (Ai), will it not work. Can somebody my help to solves this problem I think that for other modders interesting declare war code can by.

This is the orginal code that works

Code:
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AMERICA"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 1st Division", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 31, 0, 0, "US 5th Division")

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

            print("American Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 12, 31, 0, 0)
            print("American Infantry Added")
            local player1 = Players[0];
local playerteam_ID = player1:GetTeam();
local playerteam = Teams[playerteam_ID];
local playerAI = Players[4];
local otherplayerteam_ID = playerAI:GetTeam();
local otherplayerteam = Teams[otherplayerteam_ID];
otherplayerteam:Meet( playerteam, true );
playerteam:Meet( otherplayerteam, true );
otherplayerteam:DeclareWar( playerteam, true );


        elseif Game.GetGameTurn() == 3 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("American Infantry Added2")
        end
    end
This code what not work when player 3 declare war on player 4
---------------------------------------------------------------------------------------------------------
Code:
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AMERICA"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 1st Division", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 31, 0, 0, "US 5th Division")

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

            print("American Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 12, 31, 0, 0)
            print("American Infantry Added")
            local player3 = Players[3];
local playerteam_ID = player3:GetTeam();
local playerteam = Teams[playerteam_ID];
local playerAI = Players[4];
local otherplayerteam_ID = playerAI:GetTeam();
local otherplayerteam = Teams[otherplayerteam_ID];
otherplayerteam:Meet( playerteam, true );
playerteam:Meet( otherplayerteam, true );
otherplayerteam:DeclareWar( playerteam, true );


        elseif Game.GetGameTurn() == 3 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("American Infantry Added2")
        end
    end
 
Last edited:
First of all, I'd recommend you use [CODE] and [/CODE]-blocks around your code. It preserves spaces and makes it easier to read for others :)

Now for your actual problem, :Meet and :DeclareWar require the Team ID as a parameter, not the Team Pointer.
So, to fix your problem, change otherplayerteam:Meet(playerteam,true) to otherplayerteam:Meet(playerteam_ID,true), change otherplayerteam:DeclareWar(playerteam,true) to otherplayerteam:DeclareWar(playerteam_ID,true) , etc.
(The game tries to use the pointer, then fails (because it expects an ID), and then uses 0 (which happens to be the human player!) instead. Yes, I've ran into this issue myself as well and was wondering why my stuff wasn't working :lol:

In short, use the functions as follows:
pTeam:Meet(iTeam,true);
pTeam:DeclareWar(iTeam,true);
 
Hello user Troller0001

Thanks for your feedback and suggestions. I have tried the code that your giving to me and have use your code together whit my code, what only works declare war on player (0) and (1). I have also my code adapted to your code, even that did not work.
This the adapted code of entire file from this mod Unit Spawn Handler (v 3) file: ExampleMainLua.lue
Code:
-- ExampleMainLua
-- Author: LeeS
-- DateCreated: 5/11/2015 7:44:55 AM
--------------------------------------------------------------
-- function UpdateData()

    -- local iPlayerID = Game.GetActivePlayer();

    -- if( iPlayerID >= 0 ) then
        -- local pPlayer = Players[iPlayerID];
        -- local pTeam = Teams[pPlayer:GetTeam()];
        -- local pCity = UI.GetHeadSelectedCity();
    -- end
-- end

for i=0, 22 do
   
    player = Players[i];
   
    function GetCivID(civType)
        local civ = GameInfo.Civilizations[civType];
        if(civ) then
            return civ.ID;
        else
            return -1;
        end
    end

    print("Player " .. tostring(i) .. " is " .. player:GetCivilizationType());
    local playerCiv = player:GetCivilizationType();
    if(playerCiv == GetCivID("CIVILIZATION_ENGLAND")) then
        England_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_FRANCE")) then
        France_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SPAIN")) then
        Spain_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_GERMANY")) then
        Germany_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_AUSTRIA")) then
        Austria_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_NETHERLANDS")) then
        Netherlands_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_PORTUGAL")) then
        Portugal_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SWEDEN")) then
        Sweden_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_DENMARK")) then
        Denmark_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_VENICE")) then
        Venice_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_OTTOMAN")) then
        Ottoman_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_CHINA")) then
        China_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_JAPAN")) then
        Japan_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_PERSIA")) then
        Persia_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_INDIA")) then
        India_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_ARABIA")) then
        Arabia_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SIAM")) then
        Siam_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_AMERICA")) then
        America_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_BRAZIL")) then
        Brazil_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_JFD_BELGIUM")) then
        Belgium_PlayerID = i;
    end
end

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_INFANTRY"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")

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

            print("No Tokyo Express Units Added")
        elseif Game.GetGameTurn() == 5 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 45, 12, 0, 0, "NO_NAME", "NO_PROMOTION")
            print("No Tokyo Express Units Added")
        end
    end
    ---------------------------------------------------------------------------------------------------------
    --CODE FOR AMERICA
    ---------------------------------------------------------------------------------------------------------
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AMERICA"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 1st Division", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 31, 0, 0, "US 5th Division")

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

            print("American Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 12, 31, 0, 0)
            print("American Infantry Added")
local player1 = Players[2];
local iTeam_ID = player1:GetTeam();
local iTeam = Teams[iTeam_ID];
local pTeam = Players[4];
local pTeam_ID = pTeam:GetTeam();
local pTeam = Teams[pTeam_ID];
pTeam:Meet( iTeam, true );
iTeam:Meet( pTeam, true );
pTeam:DeclareWar( iTeam, true );



        elseif Game.GetGameTurn() == 3 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("American Infantry Added2")
        end
    end
    end
    --CODE FOR ENGLAND
   

GameEvents.PlayerDoTurn.Add(TokyoExpress)

print("Sample Main Lua Loaded")
-----------------------------------------------------
 
Can you this code adjust, so that it work.
That would be fantastic, when the code works also for other modders.
 
Can you this code adjust, so that it work.
That would be fantastic, when the code works also for other modders.
It seems that you misunderstood me/not fully understood what I was trying to say. Let me elaborate a bit! ;)

First of all, the letters in front of the variable names (E.g. iTeam, pTeam, sTeam, tTeam, etc.) reference Hungarian Notation, which show us what kind of data that variable stores. For example, iTeam stores an integer (which in many cases will be an ID (which is an integer as well)), pTeam stores the pointer of a specific team (a pointer allows us to use functions such as pTeam:Meet(....) and pTeam:DeclareWar(.....)), sTeam would store a string (so for example the Name of the Team), and lastly tTeam would store a table of Teams.
The main reason for using this is so that the code is clear to others (and to yourself when you look back on your code later)

local player1 = Players[2];
local iTeam_ID = player1:GetTeam();
local iTeam = Teams[iTeam_ID];
local pTeam = Players[4];
local pTeam_ID = pTeam:GetTeam();
local pTeam = Teams[pTeam_ID];
pTeam:Meet( iTeam, true );
iTeam:Meet( pTeam, true );
pTeam:DeclareWar( iTeam, true );
Now, what you did in the code above was change the variable names, which practically makes no difference if you replace very variable name with another name.
Furthermore, you used Hungarian Notation in a wrong way:
local iTeam = Teams[iTeam_ID];
iTeam stores a pointer in this case, so we should name it pTeam!
local pTeam_ID = pTeam:GetTeam();
pTeam_ID stores an integer (or more specifically, an ID), so we should name it iTeam or iTeam_ID

-----------------

This is what you should get in the end:
Code:
local pPlayer = Players[2];
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 );
In the code above, all variables with an i in front of them (E.g. iTeam) store integers (or more specifically, IDs), and all variables with a p in front of them (E.g. pOtherTeam) store pointers.

(NOTE: I was using [QUOTE]-tags so that I could give some of the text colours)
 
Your code adjustment works now perfectly for my scenarios mod and great thanks for making this solution Trollor0001. I have this code not found on civfanatics before this weekend and I think that this code adjustment for other scenarios makers very interesting is. What there is now a opportunity to make a code of historical war timeline, when AI players have declare war on each other and to same with the code for Unit spawn handler V3 from Author: LeeS
for other readers of this post the working code is the see to here below:
Code:
-- ExampleMainLua
-- Author: LeeS
-- Remix of code from Author: Trollor0001
-- Composite code from Author: Bernard Vink
-- DateCreated: 14/11/2016 21:01:55 AM
--------------------------------------------------------------
for i=0, 22 do
  
    player = Players[i];
  
    function GetCivID(civType)
        local civ = GameInfo.Civilizations[civType];
        if(civ) then
            return civ.ID;
        else
            return -1;
        end
    end

    print("Player " .. tostring(i) .. " is " .. player:GetCivilizationType());
    local playerCiv = player:GetCivilizationType();
    if(playerCiv == GetCivID("CIVILIZATION_ENGLAND")) then
        England_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_FRANCE")) then
        France_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SPAIN")) then
        Spain_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_GERMANY")) then
        Germany_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_AUSTRIA")) then
        Austria_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_NETHERLANDS")) then
        Netherlands_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_PORTUGAL")) then
        Portugal_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SWEDEN")) then
        Sweden_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_DENMARK")) then
        Denmark_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_VENICE")) then
        Venice_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_OTTOMAN")) then
        Ottoman_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_CHINA")) then
        China_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_JAPAN")) then
        Japan_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_PERSIA")) then
        Persia_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_INDIA")) then
        India_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_ARABIA")) then
        Arabia_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_SIAM")) then
        Siam_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_AMERICA")) then
        America_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_BRAZIL")) then
        Brazil_PlayerID = i;
    elseif(playerCiv == GetCivID("CIVILIZATION_JFD_BELGIUM")) then
        Belgium_PlayerID = i;
    end
end

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_INFANTRY"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 69, 21, 0, 0, "NO_NAME", "NO_PROMOTION")

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

            print("No Tokyo Express Units Added")
        elseif Game.GetGameTurn() == 5 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 45, 12, 0, 0, "NO_NAME", "NO_PROMOTION")
            print("No Tokyo Express Units Added")
        end
    end
    ---------------------------------------------------------------------------------------------------------
    --CODE FOR AMERICA
    ---------------------------------------------------------------------------------------------------------
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AMERICA"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 1st Division", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 28, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 10, 32, 0, 0, "US 5th Division")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 31, 0, 0, "US 5th Division")

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

            print("American Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 12, 31, 0, 0)
            print("American Infantry Added")
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[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 );

        elseif Game.GetGameTurn() == 3 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("American Infantry Added2")
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 );
        end
    end
    --CODE FOR ENGLAND
    ---------------------------------------------------------------------------------------------------------
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ENGLAND"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 29, 0, 0, "British 1", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 12, 29, 0, 0, "British 2")

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

            print("British Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("British Infantry Added")

        elseif Game.GetGameTurn() == 6 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("British Infantry Added")
local pPlayer = Players[0];
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[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 );

        end
    end
    --CODE FOR AMERICA
    ---------------------------------------------------------------------------------------------------------
    if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_BELGIUM"] then
        if Game.GetGameTurn() == 1 then
            --here is where we would create the units

            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 32, 30, 0, 0, "French Revolutionary ", "PROMOTION_MORALE")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 32, 30, 0, 0, "French Revolutionary")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 31, 30, 0, 0, "French Revolutionary")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 31, 29, 0, 0, "French Revolutionary")
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 31, 29, 0, 0, "French Revolutionary")

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

            print("American Units Added")
        elseif Game.GetGameTurn() == 2 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 12, 31, 0, 0)
            print("American Infantry Added")

        elseif Game.GetGameTurn() == 3 then
            SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_INFANTRY"], 23, 27, 0, 0)
            print("American Infantry Added")
        end
        elseif Game.GetGameTurn() == 4 then
           local pPlayer = Players[21];
            for pUnit in pPlayer:Units() do
           pUnit:Kill();
            print("American Infantry Added")
        end
    end
    --CODE FOR ENGLAND
end

GameEvents.PlayerDoTurn.Add(TokyoExpress)

print("Sample Main Lua Loaded")

-----------------------------------------------------
 
Hello Throller
I have a quistion: Do you know to make a code,
that settlers will plot on a tile and directly build a new city in a next turn.
When i use your adjusted code ''Unit spawn Handler'', and the settler spawn on the map in a certain turn, than goas the settler unit to run 3/4 plots, and that is not what i will. I hope that you can make a code for civ modders and my, that give the option to spawn cities on the map in a certain turn via settlers mission maybe (Push mission) or directly spawn cities on the map without a settler

This code is what i have adapted of you version to plot units on the map.

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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/tongue.gif[/IMG]ushMission( MissionTypes.MISSION_FOUND )
--return
--pUnit[IMG]https://forums.civfanatics.com/images/smilies/tongue.gif[/IMG]ushOrder (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[IMG]https://forums.civfanatics.com/images/smilies/tongue.gif[/IMG]ushMission( MissionTypes.MISSION_FOUND )
--return
--pUnit[IMG]https://forums.civfanatics.com/images/smilies/tongue.gif[/IMG]ushOrder (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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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[IMG]https://forums.civfanatics.com/images/smilies/biggrin.gif[/IMG]eclareWar( 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")
 
pPlayer:InitCity(iX,iY) should spawn a city on a given plot, so you can 'fake' the settlement of a city by just removing the settler afterwards. It also returns the City Pointer of the newly found city. (I've never used it myself before though, but from a quick google search I didn't really see any issues with it)
 
Thx Troller
With your hint, your helping my to find a working code.
This is the code that cities plot on a map in a certain turn.
Great hint Troller!

Code:
include("UnitSpawnHandler.lua")

function TokyoExpress(iPlayer)
    local pPlayer = Players[iPlayer]
    if not pPlayer:IsAlive() then return end
--CODE FOR AMERICA

        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"], 146, 56, 0, 0, "French East Indie Company1")
SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 73, 68, 0, 0, "Swedish South Company3", "PROMOTION_MORALE")
pPlayer:InitCity(18, 69, 0, 0)

            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() == 2 then
        SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "Swedish South Company1")
        SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_SETTLER"], 73, 68, 0, 0, "Swedish South Company3", "PROMOTION_MORALE")
pPlayer:InitCity(11, 71, 0, 0)
            print("No Tokyo Express Units Added")
        elseif Game.GetGameTurn() == 3 then
        SpawnAtPlot(pPlayer, GameInfoTypes["UNIT_MUSKETMAN"], 162, 64, 0, 0, "Swedish South Company1")
        print("No Tokyo Express Units Added")
    end
    --CODE FOR AMERICA
end

GameEvents.PlayerDoTurn.Add(TokyoExpress)

print("Sample Main Lua Loaded")
-----------------------------------------------------
 
Top Bottom