Author Topic: How to make only certain units available for map?  (Read 3423 times)

0 Members and 1 Guest are viewing this topic.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
How to make only certain units available for map?
« on: May 08, 2018, 03:02:04 pm »
Hi all, is it possible to make certain units available for certain map? As example, I want for winter maps make available only winter uniforms

Offline profy

  • Sergeant Major
  • *
  • Posts: 51
    • View Profile
  • Nick: Le_Profyteur
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #1 on: May 08, 2018, 03:32:31 pm »
No unfortunately, there are limitations like spawn with cannon horses or not, 100% infantry / cavalry, explosives disabled and two other three things ... but to have winter skins, you have to put a skinpack client side


2011-->2017 IVe Corps :heart:

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #2 on: May 08, 2018, 06:44:08 pm »
Ok, thank you:)

By the way - I wonder how can I completely disable cavalry on the map? I found out that adding flag sf_no_horses simply disables horses for players, but cavalry is available and bots ride horses.

Offline Aternox

  • Second Lieutenant
  • *
  • Posts: 45
  • A prayer's as good as a bayonet on a day like this
    • View Profile
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #3 on: May 08, 2018, 11:08:28 pm »
Ok, thank you:)

By the way - I wonder how can I completely disable cavalry on the map? I found out that adding flag sf_no_horses simply disables horses for players, but cavalry is available and bots ride horses.

For Cavalry I think use the mm_spawn_restrictions to block player cav and if bots still play as cav edit this part of multiplayer_server_spawn_bots in mission templates to to look once for 'mm_spawn_restriction = 1 (no cav)' and therefore inf only units and second for 'Cav allowed' which below code is kept same (you might be able to use $g_horses_are_avaliable instead not sure)

Code
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),

And for winter uniforms, I think if you make a new in game prop similar to mm_spawn_restrictions except it uses a variable for winter (eg variable 0 is not winter, 1 is winter), keep the m_troops to have both regular and winter uniform props on one soldier, and then in module scripts edit the item assign scripts to be 'if winter = 1, give winter tunic, else give regular tunic'.

My answer isn't very specific with the code, if you need me to be specific with the code edits I can help you, and my method may not be the best way, just what I can come up with right now
« Last Edit: May 09, 2018, 03:24:19 pm by Aternox »

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #4 on: May 09, 2018, 03:32:16 am »
Thank you, Aternox, I'll be looking into it :)

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #5 on: December 09, 2018, 08:18:16 pm »

For Cavalry I think use the mm_spawn_restrictions to block player cav and if bots still play as cav edit this part of multiplayer_server_spawn_bots in mission templates to to look once for 'mm_spawn_restriction = 1 (no cav)' and therefore inf only units and second for 'Cav allowed' which below code is kept same (you might be able to use $g_horses_are_avaliable instead not sure)

Code
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),


Finally I have more time for looking into this problem. I've added spr_mm_spawn_restrictions to my scene with var1=1 - but bots still spawn as infantry and cavalry (the same happens if var1=2, but in the same time it affects me as player, in second case I can't spawn as infantry). I tried to figure out what should I change in mission_templates so bots won't spawn as cavalry. I need to disable cavalry on this map only, so I don't want to change list of available bots. I guess it can be done by adding code which will say something like this:
Code
     (try_begin),
        CURRENT MAP IS INFANTRY_MAP_1
        (try_for_range, ":cur_ai_troop", LIST OF INFANTRY UINITS),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),
     (else_try),
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),

But I don't know how to say in MBScript "CURRENT MAP IS ...". Can someone help me with this? Also, I guess it will be interesting for many modders, because bots spawn as cavalry even on NW maps where they are not supposed to.
« Last Edit: December 09, 2018, 08:22:11 pm by Ivkolya »

Offline Aternox

  • Second Lieutenant
  • *
  • Posts: 45
  • A prayer's as good as a bayonet on a day like this
    • View Profile
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #6 on: December 09, 2018, 09:45:19 pm »
Code
     (try_begin),
        CURRENT MAP IS INFANTRY_MAP_1
        (try_for_range, ":cur_ai_troop", LIST OF INFANTRY UINITS),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
     (else_try),
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),

I'm lucky I just your post now lol

My recommendation (unless someone comes up with a better one), is that you use the mm_spawn_restrictions map prop variable that already works for players - IE where players can't take cav, bots will not be able to pick cav too, because of the same variable. So something more like this:

  (try_begin),
        mm_spawn_restrictions = inf only
        (try_for_range, ":cur_ai_troop", LIST OF INFANTRY UINITS),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),
     (else_try),
      mm_spawn_restrictions = cav only
      (try_for_range, ":cur_ai_troop", LIST OF CAV UNITS),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),

Haven't added proper code to make quick answer sorry. *I'm going to check the code to see if that section is still right or not though

EDIT: I have realised the changes needed to the scripts are more complex than this, hopefully I will get back to you
« Last Edit: December 09, 2018, 10:57:29 pm by Aternox »

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #7 on: December 10, 2018, 10:50:40 am »
Thank you very much, Aternox! :)
Yesterday I tried to change mission templates like you recommended earlier, but with no luck. I like your idea about changing properties of mm_spawn_restrictions, it could work :)

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #8 on: December 10, 2018, 10:56:15 pm »
Meanwhile I tried to find solution by changing mission templates (I added import from module_scenes at the beginning of file to have ability to specify scene)

Code
      (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":selected_team", ":look_only_actives"),
      (assign, ":selected_troop", reg0),
      (assign, ":selected_group", reg1),

      (team_get_faction, ":team_faction", ":selected_team"),
      (assign, ":num_ai_troops", 0),
  (store_current_scene, ":cur_scene"),  #my new script

      (try_begin),                                                                                                               
   (eq, ":cur_scene", "scn_assault_on_malakoff_test"), #if map is my new map
   (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),#and gamemode is deathmatch
       (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),#troops which can be spawned
   (neg|tf_mounted, ":cur_ai_troop"),     #but not troops with flag "tf_mounted"
         (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
         (eq, ":ai_troop_faction", ":team_faction"),
         (val_add, ":num_ai_troops", 1),
  (try_end),
 
      (else_try),
   (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end), [color=green]#original script[/color]
         (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
         (eq, ":ai_troop_faction", ":team_faction"),
         (val_add, ":num_ai_troops", 1),
      (try_end),

this is final variant for now, but all variants are leading to bots not spawn at all (they are in the list of players on server, but they all are dead). What can be wrong with this code?

UPD. I've changed code a bit
Spoiler
Code
      (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":selected_team", ":look_only_actives"),
      (assign, ":selected_troop", reg0),
      (assign, ":selected_group", reg1),

      (team_get_faction, ":team_faction", ":selected_team"),
      (assign, ":num_ai_troops", 0),
  (store_current_scene, ":cur_scene"),
      (try_begin),
   (eq, ":cur_scene", "scn_assault_on_malakoff_test"),
   (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
       (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
   (neg|troop_select_type_cavalry, ":cur_ai_troop"),        #exclude troop type cavalry
         (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
         (eq, ":ai_troop_faction", ":team_faction"),
         (val_add, ":num_ai_troops", 1),
  (try_end),
 
      (else_try),
   (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
         (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
         (eq, ":ai_troop_faction", ":team_faction"),
         (val_add, ":num_ai_troops", 1),
      (try_end),
[close]

But now when I add bots to the game in team deathmatch mode on my map - game crashes with error "Invalide opcode -2147483646"

So this code works, but now I need right code, how to exclude AI cavalry from spawning
« Last Edit: December 10, 2018, 11:31:57 pm by Ivkolya »

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #9 on: December 11, 2018, 06:53:48 am »
So I tried again, changed module_constants (added infantry of all factions) after multiplayer_ai_troops_end (as this variable is referenced in original script)

Spoiler
Code
multiplayer_ai_troops_begin = "trp_british_infantry_ai"
multiplayer_ai_troops_end = multiplayer_troops_begin

multiplayer_ai_british_infantry_begin = "trp_british_infantry_ai"
multiplayer_ai_british_infantry_end = "trp_british_hussar_ai"

multiplayer_ai_french_infantry_begin = "trp_french_infantry_ai"
multiplayer_ai_french_infantry_end = "trp_french_hussar_ai"

multiplayer_ai_prussian_infantry_begin = "trp_prussian_infantry_ai"
multiplayer_ai_prussian_infantry_end = "trp_prussian_dragoon_ai"

multiplayer_ai_russian_infantry_begin = "trp_russian_foot_guard_ai"
multiplayer_ai_russian_infantry_end = "trp_russian_hussar_ai"

multiplayer_ai_austrian_infantry_begin = "trp_austrian_infantry_ai"
multiplayer_ai_austrian_infantry_end = "trp_austrian_hussar_ai"

multiplayer_ai_rhine_infantry_begin = "trp_rhine_infantry_bavaria_ai"
multiplayer_ai_rhine_infantry_end = "trp_rhine_mounted_jaeger_ai"
[close]

So my code looks like this now

Code
      (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":selected_team", ":look_only_actives"),
      (assign, ":selected_troop", reg0),
      (assign, ":selected_group", reg1),

      (team_get_faction, ":team_faction", ":selected_team"),
      (assign, ":num_ai_troops", 0),
  (store_current_scene, ":cur_scene"),
      (try_begin),
   (eq, ":cur_scene", "scn_assault_on_malakoff_test"),
   (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_british_infantry_begin, multiplayer_ai_british_infantry_end),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_french_infantry_begin, multiplayer_ai_french_infantry_end),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_russian_infantry_begin, multiplayer_ai_russian_infantry_end),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_prussian_infantry_begin, multiplayer_ai_prussian_infantry_end),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_austrian_infantry_begin, multiplayer_ai_austrian_infantry_end),
           (try_for_range, ":cur_ai_troop", multiplayer_ai_rhine_infantry_begin, multiplayer_ai_rhine_infantry_end),
     (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
             (eq, ":ai_troop_faction", ":team_faction"),
             (val_add, ":num_ai_troops", 1),
  (try_end),
 
      (else_try),
   (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
             (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
             (eq, ":ai_troop_faction", ":team_faction"),
             (val_add, ":num_ai_troops", 1),
      (try_end),

But still bots are dead when I start team deathmach with bots.
And maybe I wrote something wrong? Maybe it is not correct - to have so many lines with try_for_range ?

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #10 on: December 11, 2018, 07:46:53 am »
By the way - in siege mode in NW there is working restriction for bots spawning as cavalry, at least in defending team, but I didn't find script for that. Maybe someone can point me where it is? I think it can be a start for disabling AI cavalry in other modes

Also I've noticed that on my new scene attacking team has no horses (but all bots are of the same unit), and defending team has cavalry, which is strange
« Last Edit: December 11, 2018, 08:00:06 am by Ivkolya »

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #11 on: December 18, 2018, 11:04:54 pm »
Finally!

Thank you very much, Grozni!

So I've managed to alter available bots for team deathmatch mode and for specific map.  Here's the code, I guess there is simplier way than alter whole script, but it works. I simply excluded units with flag tf_mounted from available bots.

Spoiler
Code
  # script_multiplayer_find_bot_troop_and_group_for_spawn
  # Input: arg1 = team_no
  # Output: reg0 = troop_id, reg1 = group_id
  ("multiplayer_find_bot_troop_and_group_for_spawn",
    [
      (store_script_param, ":team_no", 1),
      (store_script_param, ":look_only_actives", 2),

      (call_script, "script_multiplayer_find_player_leader_for_bot", ":team_no", ":look_only_actives"),
      (assign, ":leader_player", reg0),

      (assign, ":available_troops_in_faction", 0),
      (assign, ":available_troops_to_spawn", 0),
      (team_get_faction, ":team_faction_no", ":team_no"),
      (store_current_scene, ":cur_scene"),

      (try_begin),
    (eq, ":cur_scene", "scn_assault_on_malakoff_test"),     #place here list of maps where you want infantry-only combat.
    (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch), #place here names of gamemodes
(try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
          (neg|tf_mounted, ":troop_no"),         #condition - no mounted units
          (store_troop_faction, ":troop_faction", ":troop_no"),
          (eq, ":troop_faction", ":team_faction_no"),
          (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
          (val_add, ":available_troops_in_faction", 1),
          (try_begin),
            (this_or_next|lt, ":leader_player", 0),
            (player_slot_ge, ":leader_player", ":wanted_slot", 1),
            (val_add, ":available_troops_to_spawn", 1),
          (try_end),
        (try_end),

        (assign, ":available_troops_in_faction", 0),

        (store_random_in_range, ":random_troop_index", 0, ":available_troops_to_spawn"),
        (assign, ":end_cond", multiplayer_ai_troops_end),
        (try_for_range, ":troop_no", multiplayer_ai_troops_begin, ":end_cond"),
          (store_troop_faction, ":troop_faction", ":troop_no"),
          (eq, ":troop_faction", ":team_faction_no"),
          (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
          (val_add, ":available_troops_in_faction", 1),
          (this_or_next|lt, ":leader_player", 0),
          (player_slot_ge, ":leader_player", ":wanted_slot", 1),
          (val_sub, ":random_troop_index", 1),
          (lt, ":random_troop_index", 0),
          (assign, ":end_cond", 0),
          (assign, ":selected_troop", ":troop_no"),
        (try_end),
        (assign, reg0, ":selected_troop"),
        (assign, reg1, ":leader_player"),

      (else_try),
    (try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
          (store_troop_faction, ":troop_faction", ":troop_no"),
          (eq, ":troop_faction", ":team_faction_no"),
          (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
          (val_add, ":available_troops_in_faction", 1),
          (try_begin),
            (this_or_next|lt, ":leader_player", 0),
            (player_slot_ge, ":leader_player", ":wanted_slot", 1),
            (val_add, ":available_troops_to_spawn", 1),
          (try_end),
        (try_end),

        (assign, ":available_troops_in_faction", 0),

        (store_random_in_range, ":random_troop_index", 0, ":available_troops_to_spawn"),
        (assign, ":end_cond", multiplayer_ai_troops_end),
        (try_for_range, ":troop_no", multiplayer_ai_troops_begin, ":end_cond"),
          (store_troop_faction, ":troop_faction", ":troop_no"),
          (eq, ":troop_faction", ":team_faction_no"),
          (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
          (val_add, ":available_troops_in_faction", 1),
          (this_or_next|lt, ":leader_player", 0),
          (player_slot_ge, ":leader_player", ":wanted_slot", 1),
          (val_sub, ":random_troop_index", 1),
          (lt, ":random_troop_index", 0),
          (assign, ":end_cond", 0),
          (assign, ":selected_troop", ":troop_no"),
        (try_end),
        (assign, reg0, ":selected_troop"),
        (assign, reg1, ":leader_player"),
      (try_end),
 
      ]),

[close]

So, anyone who is tired of annoying cavalry on maps, which were made for infantry - feel free to use this code :)

Offline Wsam5286

  • Volunteer
  • *
  • Posts: 5
    • View Profile
  • Side: Neutral
Re: How to make only certain units available for map?
« Reply #12 on: May 08, 2020, 11:41:12 am »
Quick question were would you enter the code?