How to store and unstore a unit?

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.

How to store and unstore a unit?

Postby white » December 11th, 2016, 2:41 am

Well I got another problem:
At one point I want the player to be able to select a unit by opening a menu item in the context menu, which will bring up a message with options. Next to the selected unit should be a boat. One of the options should include storing the unit inside a variable of the boat. How can I do that?
Code: Select all
[option]
    message= _ "Store unit in boat"
    [show_if]
        [have_unit]
            x,y=$x1,$y1
            side=$side_number
            [filter_adjacent]
                type=Boat
                is_enemy=no
            [/filter_adjacent]
        [/have_unit]
    [/show_if]
    [command]
        [store_unit]
            [filter]
                x,y=$x1,$y1
                [filter_adjacent]
                    type=Boat
                    count=1
                    is_enemy=no
                [/filter_adjacent]
            [/filter]
            variable=ttt
        [/store_unit]
    [/command]
[/option]

this will store the unit (not the boat) in the variable ttt though... I would like the unit stored inside boat.variables.ttt though. Can anyone give me a clue how to do it or best case a working code?

Also I don't get why my unit isn't unstored in the following code:
Code: Select all
[store_unit]
    [filter]
        x,y=$x1,$y1
    [/filter]
    variable=stored_unit
[/store_unit]
[set_variable]
    name=stored_unit[0].variables.buildingCastle
    value=5
[/set_variable]
[unstore_unit]
    name=$stored_unit[0]
    text= _ "unstored!"
    x,y=$x1,$y1
[/unstore_unit]
[clear_variable]
    name=stored_unit
[/clear_variable]
white
 
Posts: 33
Joined: December 8th, 2012, 7:20 pm

Re: How to store and unstore a unit?

Postby The_Gnat » December 11th, 2016, 8:16 pm

In response to your first question instead of storing the unit inside the boat variable you could just store the unit kill=yes and the he would dissappear as if in the boat. But since he is stored you can recreate him when your boat lands at its destination.

For example:
Code: Select all
[store_unit]
    [filter]
          x, y=$x1,$y1
    [/filter]
    kill=yes
    variable=in_boat
[/store_unit]


As for your second question I do not use the [0] usually, also you could try removing the $ infront of your variable in the [unstore_unit] tag. That is moat likely your problem because the $ will make the variable load its value.
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am

Re: How to store and unstore a unit?

Postby white » December 11th, 2016, 9:31 pm

sounds good, but how do I know in which boat the unit is, when there is more than one?
white
 
Posts: 33
Joined: December 8th, 2012, 7:20 pm

Re: How to store and unstore a unit?

Postby The_Gnat » December 12th, 2016, 3:14 am

white wrote:sounds good, but how do I know in which boat the unit is, when there is more than one?


Just store a different variable for each boat. Either you could create an event for each boat that could be adjacent using id=YOUR_BOATS_ID or if you don't know all your boats id's you could create a event that stores the id when you move next to it like this:

Code: Select all
[event]
     name=moveto
     first_time_only=no

    # this event will happen when ever your unit moves next to a friendly boat
    [filter]
        [filter_adjacent]
                type=Boat
                is_enemy=no
        [/filter_adjacent]
    [/filter]

    # the narrator then will ask wether you want to enter the boat
    [message]
           speaker=narrator
           message= _ "Enter the Boat?"

           [option]
                message=_"Yes"

               # if the answer is yes then it will run this command
               [command]
                   # it will then store the boat
                   [store_unit]
                        [filter]
                           [filter_adjacent]
                                type=Boat
                                is_enemy=no
                           [/filter_adjacent]
                       [/filter]
                       variable=the_boat
                   [/store_unit]

                   # then it will store your unit as in_boat_x and it will then kill him
                   [store_unit]
                        [filter]
                            x, y=$x1,$y1
                        [/filter]
                        kill=yes
                        mode=append         # then it will add this unit to the store rather than overwriting the variable in_boat_x
                        variable=in_boat_$the_boat.id
                   [/store_unit]
 
                   [unstore_unit]
                         variable=the_boat
                   [/unstore_unit]
               [/command]
          [/option]
           [option]
                message=_"No"
          [/option]
[/event]


Then obviously you need an event to let the units back out of the boat, i personally would create a menu item and on click it would release the units - this might cause problems though if the boat is surrounded by water when they are released but if you filter adjacent for some tile you want to land on:

Code: Select all
                [filter_adjacent]
                    [not]
                         [filter_location]
                                terrain=YOUR_TERRAIN
                         [/filter_location]
                         count=6
                    [/not]
                   
                [/filter_adjacent]


When releasing the units from the boats you could then would search the variable of in_boat_WHAT_EVER_YOUR_BOAT_IS and then search through the variable:

(for this example i will pretend your boat's id was 'klaben'

Code: Select all
{FOREACH in_boat_klaben i}
       #create a unit
       [unstore_unit]
            x,y=$klaben.x,$klaben.y
            variable=$in_boat_klaben[$i]
       [/unstore_unit]
{NEXT i}

{CLEAR_VARIABLE in_boat_klaben}


NOTE: In the previous segment i have written $klaben.x and $klaben.y this obviously will only work if you have previously stored the boats location somehow in the event to release units off the boat. Also all the code here is untested and so i can not confirm it will work but it gives a good idea of what you can do, here is a page with more about filtering.
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am

Re: How to store and unstore a unit?

Postby white » December 12th, 2016, 5:23 pm

Thanks for taking your time to explain me that. Sounds good and I will test to do that soon.
white
 
Posts: 33
Joined: December 8th, 2012, 7:20 pm

Re: How to store and unstore a unit?

Postby The_Gnat » December 13th, 2016, 12:23 am

white wrote:Thanks for taking your time to explain me that. Sounds good and I will test to do that soon.


Great hopefully this helps! :D
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am

Re: How to store and unstore a unit?

Postby white » December 15th, 2016, 12:07 pm

The_Gnat wrote:Just store a different variable for each boat. Either you could create an event for each boat that could be adjacent using id=YOUR_BOATS_ID or if you don't know all your boats id's you could create a event that stores the id when you move next to it like this:

Code: Select all
[event]
     name=moveto
     first_time_only=no

    # this event will happen when ever your unit moves next to a friendly boat
    [filter]
        [filter_adjacent]
                type=Boat
                is_enemy=no
        [/filter_adjacent]
    [/filter]

    # the narrator then will ask wether you want to enter the boat
    [message]
           speaker=narrator
           message= _ "Enter the Boat?"

           [option]
                message=_"Yes"

               # if the answer is yes then it will run this command
               [command]
                   # it will then store the boat
                   [store_unit]
                        [filter]
                           [filter_adjacent]
                                type=Boat
                                is_enemy=no
                           [/filter_adjacent]
                       [/filter]
                       variable=the_boat
                   [/store_unit]

                   # then it will store your unit as in_boat_x and it will then kill him
                   [store_unit]
                        [filter]
                            x, y=$x1,$y1
                        [/filter]
                        kill=yes
                        mode=append         # then it will add this unit to the store rather than overwriting the variable in_boat_x
                        variable=in_boat_$the_boat.id
                   [/store_unit]
 
                   [unstore_unit]
                         variable=the_boat
                   [/unstore_unit]
               [/command]
          [/option]
           [option]
                message=_"No"
          [/option]
[/event]



Sorry it took me so long, but I just tested that part and found out it doesn't work. I added an [/message] because you were missing that as well, but when executing this code the unit entering the boat doesn't get deleted from the map. Your code also doesn't work when moving next to two or more boats at the same time. If you enter the boat then (which one anyway? xD) then it will store three boats when there are actually only two. The inspector shows, that the third boat generated will be the unit that tried to enter. Do you have any clue why it behaves that way? Well why it doesn't kill the unit even though there is kill=yes in the code... and how to fix the multiple boats issue as well?
white
 
Posts: 33
Joined: December 8th, 2012, 7:20 pm

Re: How to store and unstore a unit?

Postby The_Gnat » December 15th, 2016, 6:56 pm

white wrote:Sorry it took me so long, but I just tested that part and found out it doesn't work. I added an [/message] because you were missing that as well, but when executing this code the unit entering the boat doesn't get deleted from the map. Your code also doesn't work when moving next to two or more boats at the same time. If you enter the boat then (which one anyway? xD) then it will store three boats when there are actually only two. The inspector shows, that the third boat generated will be the unit that tried to enter. Do you have any clue why it behaves that way? Well why it doesn't kill the unit even though there is kill=yes in the code... and how to fix the multiple boats issue as well?


I will have a further look into this and see if i can solve the problem! :D

EDIT: this is actually really complicated and will take a little longer than i thought
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am

Re: How to store and unstore a unit?

Postby The_Gnat » December 22nd, 2016, 1:32 am

Hello, i have fixed the problem!

With the help of a bunch of dev's and after borrowing some code from SoBe i have created this:

Basically just replace "Elvish Fighter" with the type of boat or caravan you want to have units get onto and this event creates a message option each time you move next to a boat. If you choose to get on the boat then their is a new menu option when you right-click that allows you to unload the boat.

Code: Select all
#define BOAT_STUFF

    # first event --
    # when you move next to a boat thats on your side this event triggers
    # this event brings up a message to get on the boat or not
    [event]
        name=moveto
        first_time_only=no

        [filter]
            [filter_adjacent]
                side=$unit.side
      type="Elvish Fighter"
            [/filter_adjacent]
      [not]
        type=Elvish Fighter
      [/not]
        [/filter]

   [message]
      speaker=narrator
      message=_"Embark on this ship?"

        [option]
      message=_"No"
        [/option]
        [option]
      message=_"Yes"

      [command]

        [store_unit]
       [filter]
               side=$unit.side
      type="Elvish Fighter"
               [filter_adjacent]
            id=$unit.id
               [/filter_adjacent]
       [/filter]

            kill=no
            variable=transport
        [/store_unit]

        [store_unit]
            [filter]
      id=$unit.id
            [/filter]

            kill=no
       mode=append
            variable=transport[0].variables.landing_party
        [/store_unit]

   # this calculates how many units are on the boat
   {VARIABLE unitnum $transport[0].variables.landing_party.length}
   {VARIABLE_OP unitnum add -1}

   # if your leader (or any leader) is getting on the boat then the boat becomes a leader
   [if]
     [variable]
      name=transport[0].variables.landing_party[$unitnum].canrecruit
      equals=yes
     [/variable]
   [then]
      {VARIABLE_OP transport.canrecruit value yes}
   [/then]
   [/if]

   # this modifies your unit to make it identifiable
   [modify_unit]
      [filter]
      id=$unit.id
      [/filter]
           [variables]
                    name=boarding_transport
          value=yes
                [/variables]
   [/modify_unit]

   # your unit is then killed from the map
            [kill]
                x=$transport[0].variables.landing_party[$unitnum].x
                y=$transport[0].variables.landing_party[$unitnum].y
                fire_event=no
            [/kill]

   # and a fake unit is moved onto the boat
            [move_unit_fake]
                x=$transport[0].variables.landing_party[$unitnum].x,$transport.x
                y=$transport[0].variables.landing_party[$unitnum].y,$transport.y
                type=$transport[0].variables.landing_party[$unitnum].type
                gender=$transport[0].variables.landing_party[$unitnum].gender
                side=$unit.id
            [/move_unit_fake]

   # the unit is now set to 0 movement
            {VARIABLE transport[0].variables.landing_party[$unitnum].moves 0}
            {VARIABLE transport[0].variables.landing_party[$unitnum].attacks_left 0}
            {CLEAR_VARIABLE transport[0].variables.landing_party[$unitnum].variables.boarding_transport}

   # the boat is unstored (thereby making it so it can recruit)
        [unstore_unit]
            variable=transport
            find_vacant=no
        [/unstore_unit]      

   # the unnecessary variables are cleared
        {CLEAR_VARIABLE transport}
   {CLEAR_VARIABLE unitnum}

      [/command]
       [/option]
   [/message]

    [/event]

[event]
    name=side turn
    first_time_only=no

   # second event:
   # The second event creates a menu button in your menu to allow you to disembark your units from the boat
    [set_menu_item]
        id=assign_hero_menu_item
        description="Disembark units from this ship"
   image="misc/ums.png"
        [show_if]
      # the event is shown if there are units on the boat
      [not]
        [variable]
         name=$unit.variables.landing_party.length
         equals=0
        [/variable]
      [/not]
      # the event is shown if you have a boat in the location you have click and it is not surrounded by water
      [and]
      # if this is a boat on your team
                [have_unit]
                    x,y=$x1,$y1
                    side=$side_number
          type="Elvish Fighter"
         [filter_location]
                   [filter_adjacent_location]
                       [not]
                           [filter]
                           [/filter]
                       [/not]
   
                       terrain=!,W*
                       count=1-6
                   [/filter_adjacent_location]
   
                   [and]
                       [filter_adjacent_location]
                           [not]
                               [filter]
                               [/filter]
                           [/not]
   
                           terrain=!,Wo
                           count=3-6
                       [/filter_adjacent_location]
                   [/and]
               [/filter_location]
                [/have_unit]
      [/and]
        [/show_if]
        [command]

   # then for every unit on the boat
        {FOREACH unit.variables.landing_party i}

   # a location that is not any water is choosen to get off
            [store_locations]
                terrain=!,W*

                [filter_adjacent_location]
                    x,y=$x1,$y1
                [/filter_adjacent_location]

                [not]
                    [filter]
                    [/filter]
                [/not]

                variable=disembark_loc
            [/store_locations]

   # if their is a not location that is not any type of water then it choosen a location that is not deep water
            [if]
                [variable]
                    name=disembark_loc.length
                    less_than=1
                [/variable]

                [then]
                    [store_locations]
                        terrain=!,Wo

                        [filter_adjacent_location]
                            x,y=$x1,$y1
                        [/filter_adjacent_location]

                        [not]
                            [filter]
                            [/filter]
                        [/not]

                        variable=disembark_loc
                    [/store_locations]
                [/then]
            [/if]

   # then it moves a fake unit of your unit onto the land
            [move_unit_fake]
                x=$unit.x,$disembark_loc.x
                y=$unit.y,$disembark_loc.y
                type=$unit.variables.landing_party[$i].type
                gender=$unit.variables.landing_party[$i].gender
                side=4
            [/move_unit_fake]

   # if the unit moving off is a leader then it stops the boat from being a leader
       [if]
      [variable]
          name=unit.canrecruit
          equals=yes
      [/variable]
      [then]
          {VARIABLE_OP unit.canrecruit value no}
      [/then]
       [/if]   

   # then it unstores the unit, putting it on the hex it has choosen
            [unstore_unit]
                variable=unit.variables.landing_party[$i]
                x,y=$disembark_loc.x,$disembark_loc.y
            [/unstore_unit]
        {NEXT i}

        {CLEAR_VARIABLE unit.variables.landing_party,disembark_loc}

        {VARIABLE unit.moves 0}

   # then it unstores the boat
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [/command]
    [/set_menu_item]
[/event]
#enddef


Hopefully this helps! If you have any other questions just ask!
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am

Re: How to store and unstore a unit?

Postby Dariagan » August 4th, 2017, 4:09 pm

The_Gnat wrote:Hello, i have fixed the problem!

With the help of a bunch of dev's and after borrowing some code from SoBe i have created this:

Basically just replace "Elvish Fighter" with the type of boat or caravan you want to have units get onto and this event creates a message option each time you move next to a boat. If you choose to get on the boat then their is a new menu option when you right-click that allows you to unload the boat.

Code: Select all
#define BOAT_STUFF

    # first event --
    # when you move next to a boat thats on your side this event triggers
    # this event brings up a message to get on the boat or not
    [event]
        name=moveto
        first_time_only=no

        [filter]
            [filter_adjacent]
                side=$unit.side
      type="Elvish Fighter"
            [/filter_adjacent]
      [not]
        type=Elvish Fighter
      [/not]
        [/filter]

   [message]
      speaker=narrator
      message=_"Embark on this ship?"

        [option]
      message=_"No"
        [/option]
        [option]
      message=_"Yes"

      [command]

        [store_unit]
       [filter]
               side=$unit.side
      type="Elvish Fighter"
               [filter_adjacent]
            id=$unit.id
               [/filter_adjacent]
       [/filter]

            kill=no
            variable=transport
        [/store_unit]

        [store_unit]
            [filter]
      id=$unit.id
            [/filter]

            kill=no
       mode=append
            variable=transport[0].variables.landing_party
        [/store_unit]

   # this calculates how many units are on the boat
   {VARIABLE unitnum $transport[0].variables.landing_party.length}
   {VARIABLE_OP unitnum add -1}

   # if your leader (or any leader) is getting on the boat then the boat becomes a leader
   [if]
     [variable]
      name=transport[0].variables.landing_party[$unitnum].canrecruit
      equals=yes
     [/variable]
   [then]
      {VARIABLE_OP transport.canrecruit value yes}
   [/then]
   [/if]

   # this modifies your unit to make it identifiable
   [modify_unit]
      [filter]
      id=$unit.id
      [/filter]
           [variables]
                    name=boarding_transport
          value=yes
                [/variables]
   [/modify_unit]

   # your unit is then killed from the map
            [kill]
                x=$transport[0].variables.landing_party[$unitnum].x
                y=$transport[0].variables.landing_party[$unitnum].y
                fire_event=no
            [/kill]

   # and a fake unit is moved onto the boat
            [move_unit_fake]
                x=$transport[0].variables.landing_party[$unitnum].x,$transport.x
                y=$transport[0].variables.landing_party[$unitnum].y,$transport.y
                type=$transport[0].variables.landing_party[$unitnum].type
                gender=$transport[0].variables.landing_party[$unitnum].gender
                side=$unit.id
            [/move_unit_fake]

   # the unit is now set to 0 movement
            {VARIABLE transport[0].variables.landing_party[$unitnum].moves 0}
            {VARIABLE transport[0].variables.landing_party[$unitnum].attacks_left 0}
            {CLEAR_VARIABLE transport[0].variables.landing_party[$unitnum].variables.boarding_transport}

   # the boat is unstored (thereby making it so it can recruit)
        [unstore_unit]
            variable=transport
            find_vacant=no
        [/unstore_unit]      

   # the unnecessary variables are cleared
        {CLEAR_VARIABLE transport}
   {CLEAR_VARIABLE unitnum}

      [/command]
       [/option]
   [/message]

    [/event]

[event]
    name=side turn
    first_time_only=no

   # second event:
   # The second event creates a menu button in your menu to allow you to disembark your units from the boat
    [set_menu_item]
        id=assign_hero_menu_item
        description="Disembark units from this ship"
   image="misc/ums.png"
        [show_if]
      # the event is shown if there are units on the boat
      [not]
        [variable]
         name=$unit.variables.landing_party.length
         equals=0
        [/variable]
      [/not]
      # the event is shown if you have a boat in the location you have click and it is not surrounded by water
      [and]
      # if this is a boat on your team
                [have_unit]
                    x,y=$x1,$y1
                    side=$side_number
          type="Elvish Fighter"
         [filter_location]
                   [filter_adjacent_location]
                       [not]
                           [filter]
                           [/filter]
                       [/not]
   
                       terrain=!,W*
                       count=1-6
                   [/filter_adjacent_location]
   
                   [and]
                       [filter_adjacent_location]
                           [not]
                               [filter]
                               [/filter]
                           [/not]
   
                           terrain=!,Wo
                           count=3-6
                       [/filter_adjacent_location]
                   [/and]
               [/filter_location]
                [/have_unit]
      [/and]
        [/show_if]
        [command]

   # then for every unit on the boat
        {FOREACH unit.variables.landing_party i}

   # a location that is not any water is choosen to get off
            [store_locations]
                terrain=!,W*

                [filter_adjacent_location]
                    x,y=$x1,$y1
                [/filter_adjacent_location]

                [not]
                    [filter]
                    [/filter]
                [/not]

                variable=disembark_loc
            [/store_locations]

   # if their is a not location that is not any type of water then it choosen a location that is not deep water
            [if]
                [variable]
                    name=disembark_loc.length
                    less_than=1
                [/variable]

                [then]
                    [store_locations]
                        terrain=!,Wo

                        [filter_adjacent_location]
                            x,y=$x1,$y1
                        [/filter_adjacent_location]

                        [not]
                            [filter]
                            [/filter]
                        [/not]

                        variable=disembark_loc
                    [/store_locations]
                [/then]
            [/if]

   # then it moves a fake unit of your unit onto the land
            [move_unit_fake]
                x=$unit.x,$disembark_loc.x
                y=$unit.y,$disembark_loc.y
                type=$unit.variables.landing_party[$i].type
                gender=$unit.variables.landing_party[$i].gender
                side=4
            [/move_unit_fake]

   # if the unit moving off is a leader then it stops the boat from being a leader
       [if]
      [variable]
          name=unit.canrecruit
          equals=yes
      [/variable]
      [then]
          {VARIABLE_OP unit.canrecruit value no}
      [/then]
       [/if]   

   # then it unstores the unit, putting it on the hex it has choosen
            [unstore_unit]
                variable=unit.variables.landing_party[$i]
                x,y=$disembark_loc.x,$disembark_loc.y
            [/unstore_unit]
        {NEXT i}

        {CLEAR_VARIABLE unit.variables.landing_party,disembark_loc}

        {VARIABLE unit.moves 0}

   # then it unstores the boat
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]

        [/command]
    [/set_menu_item]
[/event]
#enddef


Hopefully this helps! If you have any other questions just ask!


Hey man, I come here a little bit late but I am trying to use your code for a weird 8 player multiplayer scenario I am making with boats and stuff and I copy pasted your code and changed all Elven Fighters to Pirate Galleons inside a [multiplayer] tag but when I tested it by moving any unit adjacent to a boat no message appears.
Code: Select all
[multiplayer]
  id=Earth
  name= _ "Earth"
  map_data="{~add-ons/Earth/maps/Earth.map}"
  force_use_map_settings=true
  allow_era="era_khalifate"
   
[side]
    side=1
    controller=human
    team_name=1
    user_team_name= _ "Argentina"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Horseman, Pirate Galleon, Sergeant, Bowman, Mage, Spearman, Cavalryman, Heavy Infantryman
    name= _ "Argentina (Humans)"
    type=Iron Mauler
    id=Roca
[unit]
      canrecruit=yes
      extra_recruit=""
      id="Lieutenant-69"
      name="Aethunry"
      type="Lieutenant"
      unrenamable=no
      x=43
      y=60
   [/unit]
   [unit]
      canrecruit=yes
      extra_recruit=""
      id="Lieutenant-70"
      name="Soran"
      type="Lieutenant"
      unrenamable=no
      x=42
      y=58
   [/unit]
   [unit]
      canrecruit=yes
      extra_recruit=""
      id="Lieutenant-71"
      name="Laregwynyn"
      type="Lieutenant"
      unrenamable=no
      x=41
      y=59
   [/unit]
   [unit]
      canrecruit=yes
      extra_recruit=""
      id="Lieutenant-72"
      name="Deoddyn"
      type="Lieutenant"
      unrenamable=no
      x=42
      y=62
   [/unit]
   [unit]
      canrecruit=yes
      extra_recruit=""
      id="Lieutenant-73"
      name="Rydoc"
      type="Lieutenant"
      unrenamable=no
      x=42
      y=60
   [/unit]

  [/side]
[side]
    side=2
    controller=ai
    team_name=2
    user_team_name= _ "England"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Horseman, Transport Galleon, Pirate Galleon, Sergeant, Longbowman, Mage, Spearman, Heavy Infantryman
    name= _ "England (Humans)"
    type=Iron Mauler
    id=king

  [/side]
[side]
    side=3
    controller=ai
    team_name=3
    user_team_name= _ "Zulus"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Orcish Archer, Orcish Assassin, Orcish Grunt, Troll Whelp, Goblin Spearman, Wolf Rider, Naga Fighter
    name= _ "Zulus (Northerns)"
    type=Orcish Sovereign
    id=shaka
  [/side]
[side]
    side=4
    controller=ai
    team_name=4
    user_team_name= _ "Egyptians"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Arif, Khaiyal, Naffat, Faris, Pirate Galleon, Hakim
    name= _ "Egiptians (Khalifate -liminal)"
    type=Rasikh
    id=caliph
  [/side]
[side]
    side=5
    controller=ai
    team_name=5
    user_team_name= _ "Slavs"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Poacher, Dwarvish Thunderer, Dwarvish Ulfserker, Dwarvish Scout, Dwarvish Fighter, Dwarvish Stalwart, Footpad, Thief, Pirate Galleon
    name= _ "Slavs (Dwarves)"
    type=Dwarvish Sentinel, Dwarvish Stalwart
    id=tsar
  [/side]
[side]
    side=6
    controller=ai
    team_name=6
    user_team_name= _ "Native Americans"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Elvish Archer, Mage, Elvish Shaman, Elvish Scout, Wose, Elvish Fighter, Merman Hunter
    name= _ "Native Americans (Elves)"
  [/side]
[side]
    side=7
    controller=ai
    team_name=7
    user_team_name= _ "Mongolians"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Poacher, Khaiyal, Goblin Spearman, Goblin Impaler, Goblin Rouser, Goblin Pillager, Rami
    name= _ "Mongolians (many cav+cheap inf)"
  [/side]
[side]
    side=8
    controller=ai
    team_name=8
    user_team_name= _ "Undead"
    fog=yes
    canrecruit=yes
    gold=100
    income=0
    recruit=Ghost, Dark Adept, Ghoul, Skeleton, Skeleton Archer, Walking Corpse, Chocobone
    name= _ "Undead -Bats"
  [/side]
    #define BOAT_STUFF

        # first event --
        # when you move next to a boat thats on your side this event triggers
        # this event brings up a message to get on the boat or not
        [event]
            name=moveto
            first_time_only=no

            [filter]
                [filter_adjacent]
                    side=$unit.side
          type="Pirate Galleon"
                [/filter_adjacent]
          [not]
            type=Pirate Galleon
          [/not]
            [/filter]

       [message]
          speaker=Narrator
          message=_"Embark on this ship?"

            [option]
          message=_"No"
            [/option]
            [option]
          message=_"Yes"

          [command]

            [store_unit]
           [filter]
                   side=$unit.side
          type="Pirate Galleon"
                   [filter_adjacent]
                id=$unit.id
                   [/filter_adjacent]
           [/filter]

                kill=no
                variable=transport
            [/store_unit]

            [store_unit]
                [filter]
          id=$unit.id
                [/filter]

                kill=no
           mode=append
                variable=transport[0].variables.landing_party
            [/store_unit]

       # this calculates how many units are on the boat
       {VARIABLE unitnum $transport[0].variables.landing_party.length}
       {VARIABLE_OP unitnum add -1}

       # if your leader (or any leader) is getting on the boat then the boat becomes a leader
       [if]
         [variable]
          name=transport[0].variables.landing_party[$unitnum].canrecruit
          equals=yes
         [/variable]
       [then]
          {VARIABLE_OP transport.canrecruit value yes}
       [/then]
       [/if]

       # this modifies your unit to make it identifiable
       [modify_unit]
          [filter]
          id=$unit.id
          [/filter]
               [variables]
                        name=boarding_transport
              value=yes
                    [/variables]
       [/modify_unit]

       # your unit is then killed from the map
                [kill]
                    x=$transport[0].variables.landing_party[$unitnum].x
                    y=$transport[0].variables.landing_party[$unitnum].y
                    fire_event=no
                [/kill]

       # and a fake unit is moved onto the boat
                [move_unit_fake]
                    x=$transport[0].variables.landing_party[$unitnum].x,$transport.x
                    y=$transport[0].variables.landing_party[$unitnum].y,$transport.y
                    type=$transport[0].variables.landing_party[$unitnum].type
                    gender=$transport[0].variables.landing_party[$unitnum].gender
                    side=$unit.id
                [/move_unit_fake]

       # the unit is now set to 0 movement
                {VARIABLE transport[0].variables.landing_party[$unitnum].moves 0}
                {VARIABLE transport[0].variables.landing_party[$unitnum].attacks_left 0}
                {CLEAR_VARIABLE transport[0].variables.landing_party[$unitnum].variables.boarding_transport}

       # the boat is unstored (thereby making it so it can recruit)
            [unstore_unit]
                variable=transport
                find_vacant=no
            [/unstore_unit]     

       # the unnecessary variables are cleared
            {CLEAR_VARIABLE transport}
       {CLEAR_VARIABLE unitnum}

          [/command]
           [/option]
       [/message]

        [/event]

    [event]
        name=side turn
        first_time_only=no

       # second event:
       # The second event creates a menu button in your menu to allow you to disembark your units from the boat
        [set_menu_item]
            id=assign_hero_menu_item
            description="Disembark units from this ship"
       image="misc/ums.png"
            [show_if]
          # the event is shown if there are units on the boat
          [not]
            [variable]
             name=$unit.variables.landing_party.length
             equals=0
            [/variable]
          [/not]
          # the event is shown if you have a boat in the location you have click and it is not surrounded by water
          [and]
          # if this is a boat on your team
                    [have_unit]
                        x,y=$x1,$y1
                        side=$side_number
              type="Pirate Galleon"
             [filter_location]
                       [filter_adjacent_location]
                           [not]
                               [filter]
                               [/filter]
                           [/not]
       
                           terrain=!,W*
                           count=1-6
                       [/filter_adjacent_location]
       
                       [and]
                           [filter_adjacent_location]
                               [not]
                                   [filter]
                                   [/filter]
                               [/not]
       
                               terrain=!,Wo
                               count=3-6
                           [/filter_adjacent_location]
                       [/and]
                   [/filter_location]
                    [/have_unit]
          [/and]
            [/show_if]
            [command]

       # then for every unit on the boat
            {FOREACH unit.variables.landing_party i}

       # a location that is not any water is choosen to get off
                [store_locations]
                    terrain=!,W*

                    [filter_adjacent_location]
                        x,y=$x1,$y1
                    [/filter_adjacent_location]

                    [not]
                        [filter]
                        [/filter]
                    [/not]

                    variable=disembark_loc
                [/store_locations]

       # if their is a not location that is not any type of water then it choosen a location that is not deep water
                [if]
                    [variable]
                        name=disembark_loc.length
                        less_than=1
                    [/variable]

                    [then]
                        [store_locations]
                            terrain=!,Wo

                            [filter_adjacent_location]
                                x,y=$x1,$y1
                            [/filter_adjacent_location]

                            [not]
                                [filter]
                                [/filter]
                            [/not]

                            variable=disembark_loc
                        [/store_locations]
                    [/then]
                [/if]

       # then it moves a fake unit of your unit onto the land
                [move_unit_fake]
                    x=$unit.x,$disembark_loc.x
                    y=$unit.y,$disembark_loc.y
                    type=$unit.variables.landing_party[$i].type
                    gender=$unit.variables.landing_party[$i].gender
                    side=4
                [/move_unit_fake]

       # if the unit moving off is a leader then it stops the boat from being a leader
           [if]
          [variable]
              name=unit.canrecruit
              equals=yes
          [/variable]
          [then]
              {VARIABLE_OP unit.canrecruit value no}
          [/then]
           [/if]   

       # then it unstores the unit, putting it on the hex it has choosen
                [unstore_unit]
                    variable=unit.variables.landing_party[$i]
                    x,y=$disembark_loc.x,$disembark_loc.y
                [/unstore_unit]
            {NEXT i}

            {CLEAR_VARIABLE unit.variables.landing_party,disembark_loc}

            {VARIABLE unit.moves 0}

       # then it unstores the boat
            [unstore_unit]
                variable=unit
                find_vacant=no
            [/unstore_unit]

            [/command]
        [/set_menu_item]
    [/event]
    #enddef
[/multiplayer]

What is wrong?
Dariagan
 
Posts: 3
Joined: August 1st, 2017, 1:28 pm

Re: How to store and unstore a unit?

Postby Ceres » August 4th, 2017, 5:57 pm

WML inside a #define is not executed by itself. Instead, you're defining a symbol/phrase (in this case "BOAT_STUFF") which stands in for all that code. In order to have it be executable, you'll need call the definition you've made, like this: {BOAT_STUFF}. That expression with then effectively be resubstituted with all the code from the defintion before the execution of the scenario starts. It's basically the same as a macro but without any arguments in this case.

So you could either 1) call it like that, or 2) remove the #define and #enddef lines.
Option 1 would be the preferred approach once you start using the same code between multiple scenarios/situations, because you can just call your definition twice instead of re-typing everything. But if this is just once for one multiplayer scenario, you can probably go with option 2 for now.
Ceres
Forum Regular
 
Posts: 618
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: How to store and unstore a unit?

Postby Dariagan » August 4th, 2017, 7:43 pm

Ceres wrote:WML inside a #define is not executed by itself. Instead, you're defining a symbol/phrase (in this case "BOAT_STUFF") which stands in for all that code. In order to have it be executable, you'll need call the definition you've made, like this: {BOAT_STUFF}. That expression with then effectively be resubstituted with all the code from the defintion before the execution of the scenario starts. It's basically the same as a macro but without any arguments in this case.

So you could either 1) call it like that, or 2) remove the #define and #enddef lines.
Option 1 would be the preferred approach once you start using the same code between multiple scenarios/situations, because you can just call your definition twice instead of re-typing everything. But if this is just once for one multiplayer scenario, you can probably go with option 2 for now.


Thank you very much :D
Dariagan
 
Posts: 3
Joined: August 1st, 2017, 1:28 pm

Re: How to store and unstore a unit?

Postby Dariagan » August 7th, 2017, 5:05 pm

Ceres wrote:WML inside a #define is not executed by itself. Instead, you're defining a symbol/phrase (in this case "BOAT_STUFF") which stands in for all that code. In order to have it be executable, you'll need call the definition you've made, like this: {BOAT_STUFF}. That expression with then effectively be resubstituted with all the code from the defintion before the execution of the scenario starts. It's basically the same as a macro but without any arguments in this case.

So you could either 1) call it like that, or 2) remove the #define and #enddef lines.
Option 1 would be the preferred approach once you start using the same code between multiple scenarios/situations, because you can just call your definition twice instead of re-typing everything. But if this is just once for one multiplayer scenario, you can probably go with option 2 for now.


One more question, how do i set a limit to how many units can be in a ship at the same time?
Dariagan
 
Posts: 3
Joined: August 1st, 2017, 1:28 pm

Re: How to store and unstore a unit?

Postby Tad_Carlucci » August 7th, 2017, 6:20 pm

Keep a count or count the stored units every time you need to know
I forked real life and now I'm getting merge conflicts.
Tad_Carlucci
Developer
 
Posts: 184
Joined: April 24th, 2016, 4:18 pm

Re: How to store and unstore a unit?

Postby The_Gnat » September 2nd, 2017, 7:19 am

Tad_Carlucci wrote:Keep a count or count the stored units every time you need to know


Yes that would work, i would suggest using the [show_if] tag in the [message] that allows you to embark. Only show the message if the boats current unit count is not too many. :D
User avatar
The_Gnat
 
Posts: 1257
Joined: October 10th, 2016, 3:06 am


Return to WML Workshop

Who is online

Users browsing this forum: Google [Bot], Yandex [Bot] and 1 guest