Results 1 to 4 of 4

Thread: An easy way to have nations annex other nations

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default An easy way to have nations annex other nations

    I will explain a simple way to have one nation annex another nation by editing the scripting.lua. There are two ways to do this: 1.) On a certain turn number 2.) On the turn following capturing certain defined regions (same as the standard spain:newspain, french:louisiana, britain:thirteen colonies). I am by no means an expert, it is just my intention to maybe give an unthought of idea to the modding community.

    1.) Here goes the simple run through:
    Spoiler Alert, click show to read: 
    This code in the scripting.lua will simply have britain annex france as both when being played by a human and when being played by the AI. The function FactionTurnStart is already a part of the main campaign. If you wish to edit another of the campaigns you will need this code at the bottom next to the rest of the event CallBacks. This will enable the turn increments which will be explained.


    Code:
    scripting.AddEventCallBack("FactionTurnStart", OnFactionTurnStart)
    and here is the britain annexes france code

    Code:
    local function OnFactionTurnStart(context)	if conditions.FactionName("britain", context) and conditions.FactionIsHuman("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "france", 0, 0, context)
            end
    	if conditions.FactionName("britain", context) and not conditions.FactionIsHuman("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "france", 0, 0, context)
            end
            end
    Simple enough. Britain will annex france on turn 0, meaning as soon as it reaches their turn before they hit the next turn button. By editing the first 0 after france you can define the first turn the annex may take place, by editing the second 0 you can define the maximum amount of turns before the annex takes place. For Instance if you wanted britain to annex france on exactly turn 2 (the turn following their first turn) then the code would be 2, 2. if you wanted britain to annex france between their 4th and 6th turn then 4, 6. They could annex them on the 4th or 5th, and will definitely annex them by the end of their 6th turn in this case.


    Now Let's do a more complex Annex where multiple nations will annex other nations on set turns.

    Here:

    Spoiler Alert, click show to read: 
    For this one we will have britain annex portugal, france annex spain on turn 5, and russia annex sweden between their 4th and 10th turns.

    Code:
    local function OnFactionTurnStart(context)	if conditions.FactionName("britain", context) and conditions.FactionIsHuman("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "portugal", 0, 0, context)
    	elseif conditions.FactionName("france", context) and conditions.FactionIsHuman("france", context) then
    		scripting.game_interface:grant_faction_handover("france", "spain", 5, 5, context)
    	elseif conditions.FactionName("russia", context) and conditions.FactionIsHuman("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "sweden", 4, 10, context)
    	end
    	if conditions.FactionName("britain", context) and not conditions.FactionIsHuman("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "portugal", 0, 0, context)
    	elseif conditions.FactionName("france", context) and not conditions.FactionIsHuman("france", context) then
    		scripting.game_interface:grant_faction_handover("france", "spain", 5, 5, context)
    	elseif conditions.FactionName("russia", context) and not conditions.FactionIsHuman("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "sweden", 4, 10, context)
    
    	end
            end
    The code can be just like so, having as many nations as you want annexed, or as few as 1. The first If function defines when the country is a human, the second If function defines when the country is being played by AI. If you only wanted a player to be able to annex the countries, and not the AI's then you would merely delete the elseif function where the conditions FactionIsHuman("nation tag") has the not in front of it.


    Now Let's do where nations annex multiple nations on set turns.

    Here:

    Spoiler Alert, click show to read: 
    This time let's have Savoy annex Perisa, Italian States, and Genoa on their 1st turn. Then let's have the Huron natives annex the iroquois between their 1st and 2nd turn and the cherokee on their 3rd turn. And Let's make this function NEVER happen when the nations are played by the AI.

    Code:
    local function OnFactionTurnStart(context)	if conditions.FactionName("piedmont_savoy", context) and conditions.FactionIsHuman("piedmont_savoy", context) then
    		scripting.game_interface:grant_faction_handover("piedmont_savoy", "safavids", 0, 0, context)
    	elseif conditions.FactionName("huron", context) and conditions.FactionIsHuman("huron", context) then
    		scripting.game_interface:grant_faction_handover("huron", "iroquoi", 1, 2, context)
    	end
            if conditions.FactionName("piedmont_savoy", context) and conditions.FactionIsHuman("piedmont_savoy", context) then
    		scripting.game_interface:grant_faction_handover("piedmont_savoy", "papal_states", 0, 0, context)
    	elseif conditions.FactionName("huron", context) and conditions.FactionIsHuman("huron", context) then
    		scripting.game_interface:grant_faction_handover("huron", "cherokee", 3, 3, context)
    
            end
            if conditions.FactionName("piedmont_savoy", context) and conditions.FactionIsHuman("piedmont_savoy", context) then
    		scripting.game_interface:grant_faction_handover("piedmont_savoy", "genoa", 1, 1, context)
            end
            end
    What you should have noticed here are that nation tags are sometimes not as simple as you would think. For instance Persia = safavids and Iroquois = Iroquoi. I will include a list of all nation tags at the bottom of this post for ease as I had to hunt them down by opening the startingpos.esf file with an editor. You should have also noticed that multiple nation annexes cannot exist in the same If function and that they can stand all by themselves as is the case where Savoy annexes Genoa. All If functions must end. If condition blah then blah end. The double end you see at the bottom: the first end finishes the If function and the second end finishes the function FactionTurnStart at the very top. It seems complex but it is really rather simple. You're just telling the game to stop and head onto the next task. The final end at the bottom is telling the game there will be no more actions. The necessity for having the EventCallBack as mentioned in the first spoiler is to have the game redo these tasks each turn.
    Now let's do one final function where if Ireland were EVER to exist during the game then it would immediately annex what is left of Britain. A weird circumstance, yes, but hopefully will show some of you guys some extra potential for this event.

    Here:

    Spoiler Alert, click show to read: 
    If Ireland ever exists then it will annex Britain by this code. And as under NORMAL circumstances Ireland cannot be played by a human and so we will do this just for the AI.

    Code:
    local function OnFactionTurnStart(context)	if conditions.FactionName("ireland", context) and not conditions.FactionIsHuman("ireland", context) then
    		scripting.game_interface:grant_faction_handover("ireland", "britain", 0, 0, context)
            end
            end
    Anytime in the game now if Ireland ever has a turn it will immediately annex all of Britain. Again the necessity to this happening exists in the EventCallBack function at the bottom as mentioned in the first spoiler.



    2.) I have decided since the game calls for complex programming skills and editing skills, explaining this section will be near useless as the people who understand how it works will probably have a better understanding than I. And Annexing a nation by capturing certain regions, seems to be only accomplish-able by Britain, Spain, and France. Maybe Cherokee too.





    And here is a list of the country tags:

    Spoiler Alert, click show to read: 
    Europe and Asia and India:
    Great Britain = britain
    France = france
    United Provinces = netherlands
    Spain = spain
    Wurttemberg = wurttemberg
    Westphalia = westphalia
    Bavaria = bavaria
    Saxony = saxony
    Prussia = prussia
    Poland-Lithuania = poland_lithuania
    Russia = russia
    Crimean Khanate = crimean_khanate
    Sweden = sweden
    Denmark = denmark
    Savoy = piedmont_savoy
    Genoa = genoa
    Venice = venice
    Italian States = papal_states
    Knights of St. John = knights_stjohn
    Portugal = portugal
    Morocco = morocco
    Barbary States = barbary_states
    Ottoman Empire = ottomans
    Persia = safavids
    Georgia = georgia
    Dagestan = chechenya_dagestan
    Mughal Empire = mughal (this nation cannot be annexed by a human or the camera freezes, but they can be annexed by the AI)
    Mysore = mysore
    Maratha Confederacy = maratha (this nation cannot be annexed by a human or the camera freezes, but they can be annexed by the AI)

    Americas:

    Thirteen Colonies = thirteencolonies
    New Spain = new_spain
    Louisiana = louisiana
    Iroquois = iroquoi
    Cherokee = cherokee
    Huron = huron
    Plains Nations = plains
    Pueblo Nations = pueblo
    Pirates = pirates

    Emergent Factions:

    Ireland = ireland
    Scotland = scotland
    Colombia = colombia
    Mexico = mexico
    Quebec = quebec
    Hessen = hessen
    Greece = greece
    Naples-Sicily = naples_sicily
    Hungary = hungary
    Afghanistan = afghanistan
    Norway = norway
    Mamelukes = mamelukes
    Punjab = punjab
    United States = united_states



    I did my best to explain it where nearly anyone could understand. If I messed up on a part or something, I am sorry. Figured we might see a couple new mods, or some new actions in mods if I posted this. Anyways, Good luck, this little event modifier brought back what was nearly a dead game to me into a constantly changing one. Peace .

  2. #2

    Default Re: An easy way to have nations annex other nations

    Yea, all the coding I put up there is useful too, but I realized something...if you want the nation annexed by both you and the AI then it can be done much easier with less processes lol. the nations tag for the Thirteen Colonies is also "thirteen_colonies". A mistake a made in the previous post.


    Here:

    This code will have britain annex the thirteen colonies on turn 1. Both by the AI and a human player. no need for double lines of codes. I included the enable_auto_generated_mission in the coding too as I am sure most everyone would not want the AI to be even dumber than they already are lol. Not sure exactly what nations are included in the vanilla coding but I know for a fact this line of code gives Britain, France, and Spain a few attacking objectives. Not sure how the syntax of the coding is though for the objectives, it won't hurt including it though. IE: Britain will invade morocco via one of the missions, but if morocco is annexed by another nation the syntax of the code may cause Britain to not invade.

    Spoiler Alert, click show to read: 
    Code:
    local function OnFactionTurnStart(context)
    	
            if conditions.TurnNumber(context) == 1 then
    		scripting.game_interface:enable_auto_generated_missions(true)
    	end
    	if conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "thirteen_colonies", 0, 0, context)
            end
    end
    The elseif functions would be done the exact same way. Just remove the section of code identifying the condition of whether the nation is a human or not. Here is a complicated code I used for a mod. It annexes nearly every nation in the game and by viewing it one can easily see how it's done.

    Code:
    local function OnFactionTurnStart(context)
    
    	if conditions.TurnNumber(context) == 1 then
    		scripting.game_interface:enable_auto_generated_missions(true)
    	end
    	if conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "thirteen_colonies", 0, 0, context)
    	elseif conditions.FactionName("spain", context) then
    		scripting.game_interface:grant_faction_handover("spain", "new_spain", 0, 0, context)
    	elseif conditions.FactionName("france", context) then
    		scripting.game_interface:grant_faction_handover("france", "louisiana", 0, 0, context)
    	elseif conditions.FactionName("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "poland_lithuania", 0, 0, context)
    	elseif conditions.FactionName("ottomans", context) then
    		scripting.game_interface:grant_faction_handover("ottomans", "barbary_states", 0, 0, context)
    	elseif conditions.FactionName("sweden", context) then
    		scripting.game_interface:grant_faction_handover("sweden", "denmark", 0, 0, context)
    	elseif conditions.FactionName("austria", context) then
    		scripting.game_interface:grant_faction_handover("austria", "genoa", 0, 0, context)
    	elseif conditions.FactionName("prussia", context) then
    		scripting.game_interface:grant_faction_handover("prussia", "hannover", 0, 0, context)
    	elseif conditions.FactionName("portugal", context) then
    		scripting.game_interface:grant_faction_handover("portugal", "morocco", 0, 0, context)
    	elseif conditions.FactionName("netherlands", context) then
    		scripting.game_interface:grant_faction_handover("netherlands", "knights_stjohn", 0, 0, context)
    	elseif conditions.FactionName("safavids", context) then
    		scripting.game_interface:grant_faction_handover("safavids", "georgia", 0, 0, context)
    	end
            if conditions.FactionName("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "courland", 0, 0, context)
    	elseif conditions.FactionName("france", context) then
    		scripting.game_interface:grant_faction_handover("france", "iroquoi", 0, 0, context)
    	elseif conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "huron", 0, 0, context)
    	elseif conditions.FactionName("spain", context) then
    		scripting.game_interface:grant_faction_handover("spain", "pueblo", 0, 0, context)
    	elseif conditions.FactionName("prussia", context) then
    		scripting.game_interface:grant_faction_handover("prussia", "westphalia", 0, 0, context)
    	elseif conditions.FactionName("austria", context) then
    		scripting.game_interface:grant_faction_handover("austria", "papal_states", 0, 0, context)
    	elseif conditions.FactionName("netherlands", context) then
    		scripting.game_interface:grant_faction_handover("netherlands", "pirates", 0, 0, context)
    	elseif conditions.FactionName("portugal", context) then
    		scripting.game_interface:grant_faction_handover("portugal", "maratha", 0, 0, context)
            end
    	if conditions.FactionName("austria", context) then
    		scripting.game_interface:grant_faction_handover("austria", "piedmont_savoy", 0, 0, context)
    	elseif conditions.FactionName("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "chechenya_dagestan", 0, 0, context)
    	elseif conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "cherokee", 0, 0, context)
    	elseif conditions.FactionName("prussia", context) then
    		scripting.game_interface:grant_faction_handover("prussia", "wurttemberg", 0, 0, context)
    	elseif conditions.FactionName("portugal", context) then
    		scripting.game_interface:grant_faction_handover("portugal", "mughal", 0, 0, context)
            end
    	if conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "inuit", 0, 0, context)
    	elseif conditions.FactionName("austria", context) then
    		scripting.game_interface:grant_faction_handover("austria", "venice", 0, 0, context)
    	elseif conditions.FactionName("prussia", context) then
    		scripting.game_interface:grant_faction_handover("prussia", "bavaria", 0, 0, context)
            end
    	if conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "plains", 0, 0, context)
    	elseif conditions.FactionName("prussia", context) then
    		scripting.game_interface:grant_faction_handover("prussia", "saxony", 0, 0, context)
    	elseif conditions.FactionName("russia", context) then
    		scripting.game_interface:grant_faction_handover("russia", "crimean_khanate", 0, 0, context)
            end
    	if conditions.FactionName("britain", context) then
    		scripting.game_interface:grant_faction_handover("britain", "mysore", 0, 0, context)
            end
            end

    Alternately, if a player wants to take an easy way out, just change the nation tags around in this big line of code. Removing not needed ones, adding, changing, etc. This way is a lot simpler than defining both as a human and as an AI player, but still knowing how to do the coding in the previous post is helpful as well. Code is read simply if nation = "nation tag" then "nation tag" annexes " annexed nation tag" on "turn number", "max turn number"


    Enjoy

  3. #3
    Alwyn's Avatar Frothy Goodness
    Content Director Patrician Citizen

    Join Date
    Feb 2014
    Location
    United Kingdom
    Posts
    11,886

    Default Re: An easy way to have nations annex other nations

    Thank you, magusx - as you said, this looks like a useful way to change the way that world events unfold. I can imagine this technique being used to set up challenging scenarios. For instance, I recently looked at an impressive Napoleon Total War AAR, Liberation, which starts with France in possession of much of Europe - this method could be used to set up situations like that.

  4. #4

    Default Re: An easy way to have nations annex other nations

    Yea, I thought of creating a scenario very similar to just that. It would be better accomplished by editing the America campaign though. I might end up doing just that. It of course won't be as good or historically accurate as some people will make it, but if you're like me and just want some different things happening in the world besides the vanilla then yea it works. I only wish I knew how to make the AI smarter: 1.) making the unit builds and placements smarter 2.) giving them objectives for attack and defense 3.) fixing diplomacy where nations don't see "attacks of opportunity" so much. A game where the advanced setting = smarter AI not let's attack any human we border that won't vastly overpower us! lol. I also wish the event could be used to capture just regions and not entire nations, but meh, I'll take what I can get. Editing the startpos.esf is just a huge pain in the ***. Filled with far too much syntax for anything but an overhaul of the game.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •