Results 1 to 10 of 10

Thread: Moneybag14's Naval Invasions Tutorial

  1. #1
    Moneybags14's Avatar Ordinarius
    Join Date
    May 2010
    Location
    United States
    Posts
    709

    Default Moneybag14's Naval Invasions Tutorial

    Moneybags14's Naval Invasions Tutorial

    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

  2. #2
    King William the Conqueror's Avatar Campidoctor
    Join Date
    Jun 2011
    Location
    At my Computer
    Posts
    1,553

    Default Re: Moneybag14's Naval Invasions Tutorial

    wow! nice discovery. I can't wait to try it
    I hold the blitz record for Medieval II (106 region in 7 turns) set in January 2024.

    Check out my Youtube Channel: CosmicConqueror
    Proud Member of TWC since 2011!

  3. #3
    Moneybags14's Avatar Ordinarius
    Join Date
    May 2010
    Location
    United States
    Posts
    709

    Default Re: Moneybag14's Naval Invasions Tutorial

    Thanks! If you run into any problems just ask me about them

  4. #4

    Default Re: Moneybag14's Naval Invasions Tutorial

    Thanks a lot for this Moneybags! Your discoveries are really great and you just saved me a lot of time and nerves aswell!

    Winner of 'Favorite M2TW Mod' and 'Favorite M2TW Modder' Award 2007 & 2008

  5. #5
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,126
    Blog Entries
    35

    Default Re: Moneybag14's Naval Invasions Tutorial

    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).

    Nicely done!










  6. #6
    Moneybags14's Avatar Ordinarius
    Join Date
    May 2010
    Location
    United States
    Posts
    709

    Default Re: Moneybag14's Naval Invasions Tutorial

    Thanks!

    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

    http://www.twcenter.net/forums/showthread.php?t=480122

  7. #7
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Moneybag14's Naval Invasions Tutorial

    I just found a potential pitfall...

    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.

  8. #8
    Moneybags14's Avatar Ordinarius
    Join Date
    May 2010
    Location
    United States
    Posts
    709

    Default Re: Moneybag14's Naval Invasions Tutorial

    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.

  9. #9
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Moneybag14's Naval Invasions Tutorial

    I didn't try FactionTurnStart. This is just something to watch out for, for anybody who is trying to do it with the player faction.

  10. #10
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Moneybag14's Naval Invasions Tutorial

    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).

Posting Permissions

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