Author Topic: *Scripting Thread*  (Read 87694 times)

0 Members and 1 Guest are viewing this topic.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #240 on: December 18, 2018, 03:03:12 pm »
Spoiler
Hello all, I'm trying to disable bots spawning as cavalry units on certain maps of team deathmatch mode. 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

I created new topic, but maybe here someone will see and help me (and, I guess, help many other modders), so sorry for double-posting.

I made many attempts to find a solution. I was advised to look into this module_mission_templates code,

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),
      (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]

As I think, disable cavalry for certain scenes could be made by adding list of scenes as condition and excluding cavalry units from available for spawning after oriiginal line

Code
	   (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),

First of all I tried to add lines like (neg|troop_is_guarantee_horse, ":cur_ai_troop") or (neg|troop_select_type_cavalry, ":cur_ai_troop") and couple of other variants, but they didn't work, bots were dead in list of players.

In the end I 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 bots are dead when I start team deathmach with bots.
And maybe I wrote something wrong? Maybe overall it's the right way, but I just wrote something wrong?
I really hope someone will help me.

[close]

Bumping this question. How to disable cavalry bots fof team deathmatch?
Again, in siege mode in NW there are no cavalry bots, at least in one team, so cavalry bots definately can be disabled for other gamemodes.

Offline Grozni

  • Second Lieutenant
  • *
  • Posts: 308
    • View Profile
  • Nick: RRA_10thRH_SoH_Grozni
  • Side: Neutral
Re: *Scripting Thread*
« Reply #241 on: December 18, 2018, 03:43:49 pm »
Scrap all the changes you made.

In script multiplayer_find_bot_troop_and_group_for_spawn find the line (store_random_in_range, ":random_troop_index", 0, ":available_troops_to_spawn"), and replace with your own logic (if team deathmach game mode, otherwise let the old line run instead). You'll want to think of a way to randomize resulting bot type while excluding cavalry bots.

Another way would be to look at my previous answer and modify bots upon spawning.

Offline Grozni

  • Second Lieutenant
  • *
  • Posts: 308
    • View Profile
  • Nick: RRA_10thRH_SoH_Grozni
  • Side: Neutral
Re: *Scripting Thread*
« Reply #242 on: December 18, 2018, 03:59:36 pm »
Actually I think you're better off altering the available_troops_to_spawn variable defined above. Like, stop adding to it after the number of infantry regiments for that faction has been reached. For start you can try just setting the available_troops_to_spawn to 1 or something to test this out, it should spawn only first two types of infantry.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #243 on: December 18, 2018, 09:58:59 pm »
Thank you, I see the logic here, I will try it

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #244 on: December 18, 2018, 10:56:37 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"),
    (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
(try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
          (neg|tf_mounted, ":troop_no"),
          (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]

There is an issue though - bots spawn as first infantry unit in the list of faction's infantry bots. I even like it, it adds more reality, but I think it would be better to have variety of bots. So, my next question is - how to make bots spawn as different infantry units?
« Last Edit: December 18, 2018, 11:01:42 pm by Ivkolya »

Offline Grozni

  • Second Lieutenant
  • *
  • Posts: 308
    • View Profile
  • Nick: RRA_10thRH_SoH_Grozni
  • Side: Neutral
Re: *Scripting Thread*
« Reply #245 on: December 19, 2018, 01:50:42 pm »
You can't just do (neg|tf_mounted, ":troop_no"), as if tf_mounted is an operation, tf_mounted is a flag used for troops.

For a list of operations which you can use like that check out header_operations.py a lot of them have some sort of description as well.

The only reason this compiles without an error is because almost everything in M&B module system is a constant number, and since the compiler expects the tf_mounted, in the way you used it, to be an operation, the game will perform an operation which has the same ID number as tf_mounted flag. So it will actually do (neg|some_operation_definitely_not_what_you_expected, ":troop_no"). If curious you can see each operation ID number in header_operations.

To check if it will be mounted troop you can compare if the troop is one of the first cavalry troop per each faction, or loop through troop template inventory in look for a horse, or simply assign a correct number depending on faction (number of AI troops before cavalry start) idk there is many ways really, but I think you should start by making the code more elegant, that giant if else which repeats almost the entire script is an accident waiting to happen.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #246 on: December 20, 2018, 03:27:06 pm »
Thank you, Grozni, right now I have no time to make this script better and for now I'm more than happy with this result. Besides, I am no coder, so I understand how to make it better, but I don't know how to write it in MBScript.

Offline Swordsman

  • Second Lieutenant
  • *
  • Posts: 161
  • General de la Junta Suprema Central
    • View Profile
    • Nova Simulatio
  • Nick: JSC_Swordsman
  • Side: Confederacy
Re: *Scripting Thread*
« Reply #247 on: December 22, 2018, 03:02:58 pm »
Hello guys, thanks for the help. Finally i made it, here's a screenshoot of the result. I was testing with my server and all is ok. Now i have another question, is it posible to make an object like a snowy barrel give you an item? i copy the code of ze_treasure in scene_props to the snow_barrel, and do the same in scripts changing the text but it doesnt work, any idea?

Spoiler
[close]

Offline Grozni

  • Second Lieutenant
  • *
  • Posts: 308
    • View Profile
  • Nick: RRA_10thRH_SoH_Grozni
  • Side: Neutral
Re: *Scripting Thread*
« Reply #248 on: December 22, 2018, 03:08:40 pm »
You can't turn barrel into usable object server side. But you can add custom buttons which were added in the new patch. It is an invisible button with custom text that you can have perform some code.

No one wrote a good tutorial about using them yet, but things are  self explanatory if you look around scripts and troops code. I don't have time atm for detailed explanations. Some clues you can find here https://www.fsegames.eu/forum/index.php?topic=38427.msg1677692#msg1677692

Offline Swordsman

  • Second Lieutenant
  • *
  • Posts: 161
  • General de la Junta Suprema Central
    • View Profile
    • Nova Simulatio
  • Nick: JSC_Swordsman
  • Side: Confederacy
Re: *Scripting Thread*
« Reply #249 on: December 22, 2018, 03:22:17 pm »
You can't turn barrel into usable object server side. But you can add custom buttons which were added in the new patch. It is an invisible button with custom text that you can have perform some code.

No one wrote a good tutorial about using them yet, but things are  self explanatory if you look around scripts and troops code. I don't have time atm for detailed explanations. Some clues you can find here https://www.fsegames.eu/forum/index.php?topic=38427.msg1677692#msg1677692

Thanks Grozni, so i can make the same but with a custom button anyway. I think it may be worth.

Offline pete99

  • First Sergeant
  • *
  • Posts: 71
  • Gang Warily
    • View Profile
  • Nick: Drummond
  • Side: Confederacy
Re: *Scripting Thread*
« Reply #250 on: December 23, 2018, 12:20:40 am »
You can also add a particular use text for the buttons too, e.g “Get Santa Hat.” Basically just have to enable a certain number of custom strings in scripts file, change the name of one of the “custom string” troops in module troops. And then change the var1 number as I remember on the prop when you place it to the number of string you changed. E.g changed custom string 1, change prop var1 also to 1.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #251 on: December 24, 2018, 02:18:32 am »
You can't just do (neg|tf_mounted, ":troop_no"), as if tf_mounted is an operation, tf_mounted is a flag used for troops.

For a list of operations which you can use like that check out header_operations.py a lot of them have some sort of description as well.

The only reason this compiles without an error is because almost everything in M&B module system is a constant number, and since the compiler expects the tf_mounted, in the way you used it, to be an operation, the game will perform an operation which has the same ID number as tf_mounted flag. So it will actually do (neg|some_operation_definitely_not_what_you_expected, ":troop_no"). If curious you can see each operation ID number in header_operations.

To check if it will be mounted troop you can compare if the troop is one of the first cavalry troop per each faction, or loop through troop template inventory in look for a horse, or simply assign a correct number depending on faction (number of AI troops before cavalry start) idk there is many ways really, but I think you should start by making the code more elegant, that giant if else which repeats almost the entire script is an accident waiting to happen.

Oddly enough, if I delete this line
Code
           (neg|tf_mounted, ":troop_no"),
Bots still spawn as first infantry unit with no variety and no cavalry. So, basically, if I just specify gamemode and map and leave code untouched - it still spawns bots only as first infantry. Which is strange, as code is without changing.

Offline Grozni

  • Second Lieutenant
  • *
  • Posts: 308
    • View Profile
  • Nick: RRA_10thRH_SoH_Grozni
  • Side: Neutral
Re: *Scripting Thread*
« Reply #252 on: December 24, 2018, 11:00:43 am »
Not very odd as that line wasn't doing anything in the first place. Lack of variety is due to some mistake you made somewhere else, I would advice you to start over with new module system.

Offline Ivkolya

  • Sergeant Major
  • *
  • Posts: 333
    • View Profile
  • Nick: Ivkolya
  • Side: Neutral
Re: *Scripting Thread*
« Reply #253 on: January 02, 2019, 06:45:26 pm »
I have a new question - how to make a troop to change it's uniform depending on current multiplayer map (or, for example, if it is winter in singleplayer)?
I'm trying to write this code as I understand it, but there are many errors in compilator, mainly something about errors in dialog lines and unused global variables. Here's my code

Spoiler
Code
#Multiplayer ai troops
  # MM
  (try_begin),
    (store_current_scene, ":cur_scene"),
    (eq, ":cur_scene", "scn_assault_on_malakoff_test"),
    ["british_infantry_ai","Line Infantry","19th Regiment of Foot",tf_guarantee_all,0,0,fac_britain,
     [itm_brit_93rd,itm_brit_19th_hat,itm_british_brown_bess,itm_bullets],
     def_attrib|level(20),wpex(50,5,130,5,120,5),knows_common|knows_ironflesh_3|knows_power_strike_3|knows_athletics_3,russian_face_middle_1, russian_face_old_2],
  (else_try),
    ["british_infantry_ai","Line Infantry","19th Regiment of Foot",tf_guarantee_all,0,0,fac_britain,
     [itm_brit_19th,itm_brit_19th_hat,itm_british_brown_bess,itm_bullets],
     def_attrib|level(20),wpex(50,5,130,5,120,5),knows_common|knows_ironflesh_3|knows_power_strike_3|knows_athletics_3,russian_face_middle_1, russian_face_old_2],
  (try_end),
[close]

Offline Glenn.

  • Colonel
  • *
  • Posts: 254
    • View Profile
  • Side: Union
Re: *Scripting Thread*
« Reply #254 on: February 07, 2019, 12:43:57 am »
Does any one know how to script for the Anglo Zulu War mod? Things like welcome messages for users joining and leaving. Server announcements every so often. Admin ID Whitelisting and the ability to prevent more than 2 people spawning as a Zulu player. Also to stop players being able to vote bots into the British Faction? If so please contact me, this would come in quite handy and I know they all work in NW just sadly AZW hasn't been updated to the latest NW Patch...