[Kingdoms only]
WARNING: see "Limitations" below regarding a CTD!
There is no command to give a settlement of Faction A to Faction B, unless Faction B happens to be the player (capture_settlement).
You could spawn a rebel army to siege...auto_win...attack it and then spawn a Faction B army to do the same. But this has some potentially nasty consequences, including: all characters and units in the settlement are killed.
Here is another solution...
It isn't foolproof and it isn't necessarily easy. But it won't kill anybody: everyone currently in the settlement peacefully leaves, as though a diplomacy Give Region was performed.
You will need a 'hidden' faction. In the example I am using "spawnpool" from this tutorial. Essentially it is just an unplayable faction that not even the AI uses.
- UPDATE: see the end of the post regarding an alternative that does not require a hidden faction.
WARNING: Make sure that this 'hidden' faction is not used for any culture/faction tag in descr_regions.txt. If it is then - when the faction_emerge part of the switch happens and that tag region has low public order - the region might also be taken over (emerged into) by the 'hidden' faction and subsequently given to the switch's to-faction.
- UPDATE: Pretty sure that's incorrect. Normally that would be true but the PO bonus from the building that this technique provides seems to make rioting settlements safe from faction_emerge.
Some terms:
- PO - Public Order
- Target Settlement - the settlement we're trying to give away
- Original Faction - the one that currently owns the settlement
- Target Faction - the one that we want to give the settlement to
- Hidden Faction - "spawnpool" in this example
The idea of this method is:
- Give all settlements except the Target Settlement super-high public order
- Use faction_emerge so that the Hidden Faction takes ownership of the Original Faction settlement with the lowest PO - this should be the Target Settlement
- Use give_everything_to_faction to transfer everything from Hidden Faction to Target Faction, i.e. just the Target Settlement as this is all they own
The script can be run multiple times, in quick succession if need be. If you need to transfer 3 settlements then run this entire script 3 times using the appropriate factions and settlements. But don't change the script to somehow make it do 3 settlements at once: the ownership tests - and their give_everything's - at the end are working on the assumption of one settlement only.
Limitations
Under SiegeThe script will do nothing if the target settlement is under siege, via the "and not I_SettlementUnderSiege" test. If you take that line out then the process could fail: transferring another settlement instead. faction_emerge seems to ignore besieged settlements.
i.e. This is a limitation of this technique: you can't transfer a beseiged settlement.
Public Order : Wrong SettlementIf, despite all of the PO adjustments from the buildings, another settlement has a lower PO than our target settlement then that settlement will be transferred instead. The script handles that outcome - giving it back to the original owner - but its characters and units will now be standing outside. Not a game-breaking result but another faction could then walk in and take it before the player/AI can move them back in.
The likely cause of this is PO due to garrison. There is no way to counter this PO bonus with negative building bonuses.
A way to further reduce the target settlement's PO is via a governor trait that adds things like Squalor, Unrest, and perhaps negative LocalPopularity and Health. However, giving him the trait at the desired time could be tricky and it's possible that the settlement has no governor.
UPDATE: some ideas on garrison and governor are in post 58.
Crusade-related CTDIf the region is the target of the current crusade, and the give-to faction is catholic, then a crash-to-desktop occurs. This is a bug with give_everything_to_faction as reported here.
Post 2 shows a way around this.
Incidentally, the GiveSettlement event fires during this transfer. BUT: it only fires during the faction_emerge, not the give_everything_to_faction. Meaning that TargetFactionType will be "spawnpool" in this example, not "france".
Something worth noting: if this is used to transfer a region to the faction that already owns it then they keep the region but all of their characters and units will exit the settlement. Other-faction spies remain inside. This could be a useful way to empty a settlement, for whatever reason. But this is really just a shortcut: the same result would be had by giving the region to another faction then back to the first.
~~~~~~
Hopefully this will be of use to somebody. If anyone has any ideas on how to further increase or decrease PO via buildings or script then please say so: the bigger the gap between the target settlement's PO and all other settlements, the more reliable this will be. e.g. Is there any way to increase Squalor or Unrest (other than by traits) or to reduce Garrison bonus?