Hello all, I'm not sure if this has been possible before my discovery but you can now script actual naval invasions where the troops on the ship actually land on shore and continue on their marry way towards victory!
First off, let me show you how to spawn armies on ships at sea if you didn't already know how to do that. You have to first spawn the ships via scripting like so
Spoiler Alert, click show to read:
Code:
spawn_army
faction spain
character random_name, admiral, age 49, x 205, y 27, label Boat
unit Boats exp 1 armour 0 weapon_lvl 0
unit Boats exp 0 armour 0 weapon_lvl 0
end
remember that you need to make the character type "admiral" which is the spot before the age.
Next you spawn the army on the EXACT coordinates as the ships or else you won't get the results you seek.
Spoiler Alert, click show to read:
Code:
spawn_army
faction spain
character random_name, named character, age 26, x 205, y 27, label Army
traits GoodCommander 1
unit Bodyguard exp 2 armour 0 weapon_lvl 0
unit Soldier exp 2 armour 0 weapon_lvl 0
unit Soldier exp 0 armour 0 weapon_lvl 0
end
Now that we have the beginning steps that were already know to the community out of the way, it's onto the new stuff!
Go ahead and create a counter because it's important
Code:
declare_counter NavalTest
Here is the coding that is required for your troops to land on shore. I will explain in more detail after the code.
Spoiler Alert, click show to read:
Code:
monitor_event FactionTurnStart FactionType spain
and not FactionIsLocal
if I_CharacterExists Boat
if ! I_FactionNearTile spain 0 155,109 ; This is the shore Tile
move Boat, 155, 109 ; This is the shore Tile
end_if
if I_FactionNearTile spain 0 155,109
set_counter NavalTest 1
end_if
if I_CompareCounter NavalTest = 1
destroy_units spain, Boats ; You can also name attributes to specify which units
end_if
end_if
if I_CharacterExists Army
if I_CompareCounter NavalTest = 3
siege_settlement Army, TWC, attack
end_if
if I_CompareCounter NavalTest = 2
siege_settlement Army, TWC, maintain
set_counter NavalTest 3
end_if
if I_CompareCounter NavalTest = 1
move Army, 145, 110 ; This is just to move the army away from shore.
set_counter NavalTest 2
end_if
end_if
end_monitor
*IMPORTANT* Your arrival destination for your scripted boat has to be on a "Shore" tile, you can see this ingame by right clicking. If you don't land on a shore tile the army will disappear along with the ship.
Here is how the code allows this to happen. The "if ! I_FactionNearTile spain 0 155, 109" condition keeps the ship moving towards the shoreline until it reaches the tile specified. When the ship reaches the tile, a condition is triggered that sets the counter to "1". If the counter is equal to "1" then a command is used to destroy the units or in this case the ships and ONLY the ships.
This is the breakthrough part and it can kind of be tricky to work with, once the boat is destroyed the army will leave the boat and walk onto the shore. Here is where some problems arise. If you do not give the army a move command right away your script can get kind of messed up if you have a "siege_settlement" command right after landing.
There are also other special problems that I will address later after further testing. I will also add onto this with pictures and more indepth examples.
Pictures:
Spoiler Alert, click show to read:
*Notice the green arrow, the beginning of it is where the army was destroyed(landed) on the tile. However, these are PERMANENT so you will need a campaign_wait command to keep them from appearing.*
Hopefully someone will find this useful as I have! Happy scripting!
Last edited by Moneybags14; November 19, 2011 at 06:30 PM.
Reason: Added Pictures
I like the game play angle, now it's just a matter of how to script the revealing of the involved tiles so that the player can actually see the arriving boat and the units moving towards the siege. flash_character doesn't work so well, I had problems with switching it off after the character moved (and the pointer stayed behind).
And this link has alot more information(if you want it) then the original post contains. It is where I started working on how to do this. I am just too lazy to copy/paste some of the info over
If the navy is the player's faction and is currently selected, and the destroy_units is done during PreFactionTurnStart then a 'ghost' character leaves the ship instead of the real character/army. i.e. A General without a banner who can't do anything except move around. If the ship is then disbanded (by the player) then the real army does leave the ship even though it was no longer visible under the ship's "Army" tab.
FactionTurnEnd appears to work okay. I didn't test any other events. And AI factions are probably fine because they can't select things.
Well that's a good find. Does it do it during FactionTurnStart? Also I didn't intend to make this a use for the human controlled boats. Because they can do naval invasions by themselves.
It seems that only one "landing" can be done at a time. I had two fleets each with an army on board. When script moved the second fleet to the coast tile and destroyed the ships then its army did not appear - they just vanished along with the fleet.
The first fleet was still at sea. Not that you'd want to destroy the ships in that situation because that army will drown. But it might be the case that if both fleets were moved to a coast tile before the destroy_units then only one army will disembark and the other will vanish (I didn't test that).