SP Tutorial Presentation Adding Troop Tree button to party managment screen from Viking Conquest

Currently Viewing (Users: 0, Guests: 1)

Vetrogor

Sergeant
Best answers
0
What is for: Mount&Blade Warband
Recuriment: presentation for troop tree provided by rubic or dunde (this are links)
Or you can use troop tree presentation from Viking Conquest provided in spoiler. Add constants in file module_constants.py used in VC presentation from the end of the spoiler.

Code:
#chief presentacion game_troop_tree moto
#INPUT: reg0 selected troop
("game_troop_tree", 0, 0, [
    (ti_on_presentation_load, [
        (presentation_set_duration, 999999),
        (set_fixed_point_multiplier, 1000),
        (assign, ":troop", reg0),
    
        ###mesh de fondo MOTO must do it this way or won't allow party screen to reappear
        (create_mesh_overlay, reg0, "mesh_load_window"),
        (position_set_x, pos1, -1),
        (position_set_y, pos1, -1),
        (overlay_set_position, reg0, pos1),
        (position_set_x, pos1, 1002),
        (position_set_y, pos1, 1002),
        (overlay_set_size, reg0, pos1),
        #Message first part
    
        #screen top
        (create_text_overlay, reg1, "@Troop Tree", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Title_Height),
        (overlay_set_position, reg1, pos1),
    
        #write the trees
        (call_script, "script_troop_tree_precurse", ":troop", 1, 1),
        (store_div, "$troop_tree_pic_width", Troop_Tree_Area_Width, reg0),
        (store_div, "$troop_tree_pic_height", Troop_Tree_Area_Height, reg1),
    
        (store_div, ":x_pos", "$troop_tree_pic_width", 2),
        (val_add, ":x_pos", Screen_Border_Width),
        (store_mul, ":y_pos", "$troop_tree_pic_height", -1),
        (val_add, ":y_pos", Screen_Title_Height-2*Screen_Text_Height),
        (call_script, "script_troop_tree_recurse", ":troop", ":x_pos", ":y_pos"),
    
        #screen bottom
        (create_game_button_overlay, "$presentation_leave_button", "@Done", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Border_Width),
        (overlay_set_position, "$presentation_leave_button", pos1),
    ]),

    (ti_on_presentation_run, [
        (try_begin),
          (this_or_next|key_clicked, key_escape),
          (key_clicked, key_xbox_start),
          (presentation_set_duration, 0),
        (try_end),
    ]),

    (ti_on_presentation_event_state_change, [
        (store_trigger_param_1, ":object"),
        (eq, ":object", "$presentation_leave_button"),
        (presentation_set_duration, 0),
    ]),
]), #end troop tree

# declare constants in module_constants.py
Screen_Width = 1024-Screen_Border_Width
Troop_Tree_Num_Levels = 6
Troop_Tree_Max_Per_Level = 5  #2^(Troop_Tree_Num_Levels-1) opt for counting most upgrade2 over all factions
Troop_Tree_Area_Height = Screen_Title_Height-4*Screen_Text_Height
Troop_Tree_Area_Width = Screen_Width-2*Screen_Border_Width
Troop_Tree_Line_Color = 0x001380
Troop_Tree_Tableau_Height = 800
Troop_Tree_Tableau_Width = Troop_Tree_Tableau_Height*Screen_Undistort_Width_Num/Screen_Undistort_Width_Den

1) File module_scripts.py add script
Code for Viking Conquest troop tree (easiest)
Code:
  #script_game_troop_upgrades_button_clicked
  # This script is called from the game engine when the player clicks on said button from the party screen
  # INPUT: arg1 = troop_id
  ("game_troop_upgrades_button_clicked", [
      (store_script_param, reg0, 1),
      (start_presentation, "prsnt_game_troop_tree"),
  ]),
Code for rubic's troop treee
Code:
  #script_game_troop_upgrades_button_clicked
  # This script is called from the game engine when the player clicks on said button from the party screen
  # INPUT: arg1 = troop_id
  ("game_troop_upgrades_button_clicked",
    [
      (store_script_param, reg0, 1),
      (assign, "$g_selected_troop", reg0),
      (call_script, "script_get_page_no_of_troop_tree_for_troop_on", "$g_selected_troop"),
      (assign, "$g_selected_page", reg0),
      (start_presentation, "prsnt_faction_troop_trees"),
    ]),
2) Open file game_variables.txt in compiled module folder
Code:
After
party_t_upgrade_text_color = 0xFF991100
Add
party_b_troop_upgrades_position_x = 0.09 #upgrade advise.
party_b_troop_upgrades_position_y = 0.25 #upgrade advise.#before 0.22

After
party_b_move_down_h = 0.03
Add
party_b_troop_upgrades_h = 0.033

3) Open file module.ini and add:
Code:
show_troop_upgrades_button = 1
4) Open file languages\en\ui.csv in compiled module folder or in "Mount&Blade Warband" game installed folder and add:
Code:
ui_troop_upgrades| Troop Tree
Add space before and after "Troop Tree" so the text will fit in the button. Add an empty line after so last character will display.
 
Last edited:

Eärendil the Mariner

Subforum Moderator
WBWF&SM&B
Best answers
64
I think you mean module_scripts.py and not scripts.txt. Also use the code environment for script snippets :wink:

An easier method for people who are not using rubik's or dunde's troop tree presentations (which you should link if they are needed for your code to work) would be
Code:
  #script_game_troop_upgrades_button_clicked
  # This script is called from the game engine when the player clicks on said button from the party screen
  # INPUT: arg1 = troop_id
  ("game_troop_upgrades_button_clicked", [
      (store_script_param, reg0, 1),
      (start_presentation, "prsnt_game_troop_tree"),
  ]),
and afterwards doing the steps 2) to 4) which you mention.
 

Vetrogor

Sergeant
Best answers
0
Thanks for tips. I provided links to rubic and dunde troop tree presentations. Those orange names are links.
game_troop_tree - there is no such presentation in native.

Finally
Code:
 works as it should!
 

Eärendil the Mariner

Subforum Moderator
WBWF&SM&B
Best answers
64
Ah, yes. It's something which has been introduced with Viking Conquest, so the presentation code can be found in the module system there, forgot about that. Here an example of TLD, not sure if @Khamukkamu made some edits compared to the VC troop tree presentation, I haven't the MS downloaded for comparision.
Code:
# Kham - VC Troop Tree Presentations
#chief presentacion game_troop_tree moto
#INPUT: reg0 selected troop
("game_troop_tree", 0, 0, [
    (ti_on_presentation_load, [
        (presentation_set_duration, 999999),
        (set_fixed_point_multiplier, 1000),
        (assign, ":troop", reg0),
        
        ###mesh de fondo MOTO must do it this way or won't allow party screen to reappear
        (create_mesh_overlay, reg0, "mesh_town_goodcamp"),
        (position_set_x, pos1, -1),
        (position_set_y, pos1, -1),
        (overlay_set_position, reg0, pos1),
        (position_set_x, pos1, 1002),
        (position_set_y, pos1, 1002),
        (overlay_set_size, reg0, pos1),
        #Message first part
        
        #screen top
        (create_text_overlay, reg1, "@Troop Tree", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Title_Height),
        (overlay_set_position, reg1, pos1),
        
        #write the trees
        (call_script, "script_troop_tree_precurse", ":troop", 1, 1),
        (store_div, "$troop_tree_pic_width", Troop_Tree_Area_Width, reg0),
        (store_div, "$troop_tree_pic_height", Troop_Tree_Area_Height, reg1),
        
        (store_div, ":x_pos", "$troop_tree_pic_width", 2),
        (val_add, ":x_pos", Screen_Border_Width),
        (store_mul, ":y_pos", "$troop_tree_pic_height", -1),
        (val_add, ":y_pos", Screen_Title_Height-2*Screen_Text_Height),
        (call_script, "script_troop_tree_recurse", ":troop", ":x_pos", ":y_pos"),
        
        #screen bottom
        (create_game_button_overlay, "$presentation_leave_button", "@Done", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Border_Width),
        (overlay_set_position, "$presentation_leave_button", pos1),
    ]),
    
    (ti_on_presentation_run, [
        (try_begin),
          (this_or_next|key_clicked, key_escape),
          (key_clicked, key_xbox_start),
          (presentation_set_duration, 0),
        (try_end),
    ]),
    
    (ti_on_presentation_event_state_change, [
        (store_trigger_param_1, ":object"),
        (eq, ":object", "$presentation_leave_button"),
        (presentation_set_duration, 0),
    ]),
]), #end troop tree
 

Eärendil the Mariner

Subforum Moderator
WBWF&SM&B
Best answers
64
If people are using the presentation of yours but are not modding VC they need to declare some constants first. From VC module_constants:
Code:
Screen_Width = 1024-Screen_Border_Width
Troop_Tree_Num_Levels = 6
Troop_Tree_Max_Per_Level = 5  #2^(Troop_Tree_Num_Levels-1) opt for counting most upgrade2 over all factions
Troop_Tree_Area_Height = Screen_Title_Height-4*Screen_Text_Height
Troop_Tree_Area_Width = Screen_Width-2*Screen_Border_Width
Troop_Tree_Line_Color = 0x001380
Troop_Tree_Tableau_Height = 800
Troop_Tree_Tableau_Width = Troop_Tree_Tableau_Height*Screen_Undistort_Width_Num/Screen_Undistort_Width_Den
 

mauromagno

Knight at Arms
WBNW
Best answers
7
why is key_xbox_start in the code if in the VC code is key_pad_start?
although it also gave me an error ...
can this be used in warband?
 

Eärendil the Mariner

Subforum Moderator
WBWF&SM&B
Best answers
64
why is key_xbox_start in the code if in the VC code is key_pad_start?
although it also gave me an error ...
can this be used in warband?
key_pad_start is not a known xbox button for me, not sure if VC has redefined the names. Since it's for Warband it makes however sense to refer to the ones defined there. Look at Xbox controller support here:
 

Vetrogor

Sergeant
Best answers
0
why is key_xbox_start in the code if in the VC code is key_pad_start?
although it also gave me an error ...
can this be used in warband?
The game engine works only with numbers. But in module system you must use what is declared.

key_pad_start = 0xf8
key_xbox_start = 0xf8

So you can add in file header_triggers.py and use both.

key_xbox_start = key_pad_start
 

mauromagno

Knight at Arms
WBNW
Best answers
7
Well friends, I did the whole tutorial and added these lines to header_triggers:
key_pad_start = 0xf8
key_xbox_start = 0xf8
but I also had to add a code to module_script (troop_tree_recurse) and another to module_tableau_materials (troop_tree_pic) and also I had to add more constants to module_constant ..... everything compiled fine, no errors, but when pressing the button, nothing appeared, so since I already had Dunde's faction_troop_tree added, I just modified the script leaving it as follows: (and everything went well)
Code:
   ("game_troop_upgrades_button_clicked", [
       (store_script_param, reg0, 1),
#        (start_presentation, "prsnt_game_troop_tree"),
       (start_presentation, "prsnt_faction_troop_tree"),
   ]),
 

mauromagno

Knight at Arms
WBNW
Best answers
7
I think he didn't add game_troop_tree presentation from viking conquest. But after all works now.
I asked if it could be used in Warband ... well, I tried to do it because I thought that the viking presentation could be better than the one I already had in my mod ...
Add everything described above, but some things were missing and I had to add them from the Viking MSys, but it did not work, so I used the button to redirect to the presentation that I already had of the troops tree ...

Did you now try out the variant in the first post of Vetrogor or mine in the second post?
the first
 
Last edited:

mauromagno

Knight at Arms
WBNW
Best answers
7
Ah, yes. It's something which has been introduced with Viking Conquest, so the presentation code can be found in the module system there, forgot about that. Here an example of TLD, not sure if @Khamukkamu made some edits compared to the VC troop tree presentation, I haven't the MS downloaded for comparision.
Code:
# Kham - VC Troop Tree Presentations
#chief presentacion game_troop_tree moto
#INPUT: reg0 selected troop
("game_troop_tree", 0, 0, [
    (ti_on_presentation_load, [
        (presentation_set_duration, 999999),
        (set_fixed_point_multiplier, 1000),
        (assign, ":troop", reg0),
       
        ###mesh de fondo MOTO must do it this way or won't allow party screen to reappear
        (create_mesh_overlay, reg0, "mesh_town_goodcamp"),
        (position_set_x, pos1, -1),
        (position_set_y, pos1, -1),
        (overlay_set_position, reg0, pos1),
        (position_set_x, pos1, 1002),
        (position_set_y, pos1, 1002),
        (overlay_set_size, reg0, pos1),
        #Message first part
       
        #screen top
        (create_text_overlay, reg1, "@Troop Tree", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Title_Height),
        (overlay_set_position, reg1, pos1),
       
        #write the trees
        (call_script, "script_troop_tree_precurse", ":troop", 1, 1),
        (store_div, "$troop_tree_pic_width", Troop_Tree_Area_Width, reg0),
        (store_div, "$troop_tree_pic_height", Troop_Tree_Area_Height, reg1),
       
        (store_div, ":x_pos", "$troop_tree_pic_width", 2),
        (val_add, ":x_pos", Screen_Border_Width),
        (store_mul, ":y_pos", "$troop_tree_pic_height", -1),
        (val_add, ":y_pos", Screen_Title_Height-2*Screen_Text_Height),
        (call_script, "script_troop_tree_recurse", ":troop", ":x_pos", ":y_pos"),
       
        #screen bottom
        (create_game_button_overlay, "$presentation_leave_button", "@Done", tf_center_justify),
        (position_set_x, pos1, Screen_Width/2),
        (position_set_y, pos1, Screen_Border_Width),
        (overlay_set_position, "$presentation_leave_button", pos1),
    ]),
   
    (ti_on_presentation_run, [
        (try_begin),
          (this_or_next|key_clicked, key_escape),
          (key_clicked, key_xbox_start),
          (presentation_set_duration, 0),
        (try_end),
    ]),
   
    (ti_on_presentation_event_state_change, [
        (store_trigger_param_1, ":object"),
        (eq, ":object", "$presentation_leave_button"),
        (presentation_set_duration, 0),
    ]),
]), #end troop tree
I tried this presentation and it worked, but I realized a mistake made ... it is still good, but I would like to put another button to the other presentation, since Dunde's, you can see the qualities of each troop and the items that uses....
Would this be possible?
 

Eärendil the Mariner

Subforum Moderator
WBWF&SM&B
Best answers
64
You can of course edit the presentation of the troop tree how you like it to be, not the otherwise hardcoded one though (the one at which the button has been added). It's possible but tricky, so make sure that you merge them in a fitting way, will be a bit trial and error from your side.
 

Vetrogor

Sergeant
Best answers
0
It is not possible to add a new button. It is hardcoded. But you can add hook when pressed alt+left_mouse_button_click in the script. It will be like this:

("game_troop_upgrades_button_clicked", [
(store_script_param, reg0, 1),
(try_begin),
(key_is_down, key_left_alt),
(start_presentation, "prsnt_game_troop_tree"),
(else_try),
(start_presentation, "prsnt_faction_troop_tree"),
(try_end),
]),
 

mauromagno

Knight at Arms
WBNW
Best answers
7
It is not possible to add a new button. It is hardcoded. But you can add hook when pressed alt+left_mouse_button_click in the script. It will be like this:

("game_troop_upgrades_button_clicked", [
(store_script_param, reg0, 1),
(try_begin),
(key_is_down, key_left_alt),
(start_presentation, "prsnt_game_troop_tree"),
(else_try),
(start_presentation, "prsnt_faction_troop_tree"),
(try_end),
]),
It works ... but why can't you put another button that is not included in your presentation? ... that is a button only to redirect to faction_troop_tree if there are a lot of buttons there?