[OSP][Code] Custom Player Kingdom Vassal Titles (Open Source)

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
Lord/Lady is a fairly bland title of nobility for a player running the "Czardom of the Glorious Revolution" or some such. This bit of code will add an option to the Camp Action menu much akin to the Rename Kingdom option. Within this, the player can set a title for their male nobility as well as for their female vassals. The change in the character's name and their party (if they lead one) will be instantaneous, however notes referring to the lord will not be updated until there is reason to update them (to prevent cheating by re-titling characters).

Similarly, defecting Lords should receive the appropriate, custom title of nobility when they arrive at the player's hall.

Without further ado, the code:

Add this any where in module_presentations. The end, before the final ] works just fine.
Code:
## Player Faction begin
# Set your vassals' titles - made by Caba'drin
("set_vassal_title",0,mesh_load_window,[
      (ti_on_presentation_load,
       [(set_fixed_point_multiplier, 1000),
        (str_clear, s1),
        (str_clear, s2),
       
        (create_text_overlay, reg0, "@How will your male vassals be known?", tf_center_justify),
        (position_set_x, pos1, 500),
        (position_set_y, pos1, 600),
        (overlay_set_position, reg0, pos1),
        (create_text_overlay, reg0, "@How will your female vassals be known?", tf_center_justify),
        (position_set_x, pos1, 500),
        (position_set_y, pos1, 400),
        (overlay_set_position, reg0, pos1),
        
        (create_simple_text_box_overlay, "$g_presentation_obj_name_kingdom_1"),
        (position_set_x, pos1, 400),
        (position_set_y, pos1, 500),
        (overlay_set_position, "$g_presentation_obj_name_kingdom_1", pos1),
        (try_begin),
          (troop_slot_eq, "trp_heroes_end", 0, 1), #Pick a slot
          (str_store_troop_name, s0, "trp_heroes_end"),
        (else_try),
          (str_store_string, s0, "@{!}"),
          (str_store_string, s0, "str_faction_title_male_player"),
        (try_end),
        (overlay_set_text, "$g_presentation_obj_name_kingdom_1", s0),
        
        (create_simple_text_box_overlay, reg0),
        (position_set_x, pos1, 400),
        (position_set_y, pos1, 300),
        (overlay_set_position, reg0, pos1),
        (try_begin),
          (troop_slot_eq, "trp_heroes_end", 1, 1), #Pick a slot
          (str_store_troop_name_plural, s0, "trp_heroes_end"),
        (else_try),
          (str_store_string, s0, "@{!}"),
          (str_store_string, s0, "str_faction_title_female_player"),
        (try_end),
        (overlay_set_text, reg0, s0),
          
        (create_button_overlay, reg0, "@Use the Titles Entered Above.", tf_center_justify),
        (position_set_x, pos1, 600),
        (position_set_y, pos1, 150),
        (overlay_set_position, reg0, pos1),
        
        (create_button_overlay, reg0, "@Use Default Titles (Lord/Lady).", tf_center_justify),
        (position_set_x, pos1, 600),
        (position_set_y, pos1, 100),
        (overlay_set_position, reg0, pos1),
        
        (presentation_set_duration, 999999),
        ]),
      (ti_on_presentation_event_state_change,
       [(store_trigger_param_1, ":object"),
        (try_begin),
          (eq, ":object", "$g_presentation_obj_name_kingdom_1"),
          (str_store_string, s1, s0), #Male Title
        (else_try),
          (store_add, ":overlay", "$g_presentation_obj_name_kingdom_1", 1),
          (eq, ":object", ":overlay"), 
          (str_store_string, s2, s0), ##Female Title          
        (else_try),
          (val_add, ":overlay", 1), 
          (eq, ":object", ":overlay"), #Custom
          (try_begin),
            (neg|str_is_empty, s1),
            (troop_set_name, "trp_heroes_end", s1),
            (troop_set_slot, "trp_heroes_end", 0, 1),
            (try_for_range, ":lord_lady", lords_begin, lords_end),
                (store_troop_faction, ":faction", ":lord_lady"),
                (eq, ":faction", "fac_player_supporters_faction"),
                (call_script, "script_troop_set_title_according_to_faction", ":lord_lady", ":faction"),
            (try_end),
          (try_end),
          (try_begin),
            (neg|str_is_empty, s2),
            (troop_set_plural_name, "trp_heroes_end", s2),
            (troop_set_slot, "trp_heroes_end", 1, 1),
            (try_for_range, ":lord_lady", kingdom_ladies_begin, kingdom_ladies_end),
                (store_troop_faction, ":faction", ":lord_lady"),
                (eq, ":faction", "fac_player_supporters_faction"),
                (call_script, "script_troop_set_title_according_to_faction", ":lord_lady", ":faction"),
            (try_end),
          (try_end),
          (try_begin),
            (this_or_next|neg|str_is_empty, s1),
            (neg|str_is_empty, s2),
            (try_for_range, ":lord_lady", companions_begin, companions_end),
                (store_troop_faction, ":faction", ":lord_lady"),
                (eq, ":faction", "fac_player_supporters_faction"),
                (troop_slot_eq, ":lord_lady", slot_troop_occupation, slto_kingdom_hero),
                (call_script, "script_troop_set_title_according_to_faction", ":lord_lady", ":faction"),
            (try_end),
          (try_end),          
          (presentation_set_duration, 0),
        (else_try),
          (val_add, ":overlay", 1), 
          (eq, ":object", ":overlay"), #Default
          (troop_set_slot, "trp_heroes_end", 0, 0),
          (troop_set_slot, "trp_heroes_end", 1, 0),
          (try_for_range, ":lord_lady", lords_begin, kingdom_ladies_end),
            (neg|is_between, ":lord_lady", pretenders_begin, pretenders_end),
            (store_troop_faction, ":faction", ":lord_lady"),
            (eq, ":faction", "fac_player_supporters_faction"),
            (call_script, "script_troop_set_title_according_to_faction", ":lord_lady", ":faction"),
          (try_end),
          (try_for_range, ":lord_lady", companions_begin, companions_end),
            (store_troop_faction, ":faction", ":lord_lady"),
            (eq, ":faction", "fac_player_supporters_faction"),
            (troop_slot_eq, ":lord_lady", slot_troop_occupation, slto_kingdom_hero),
            (call_script, "script_troop_set_title_according_to_faction", ":lord_lady", ":faction"),
          (try_end),
          (presentation_set_duration, 0),
        (try_end),
        ]),
      ]),
Add this within the "camp_action" menu, before or after "action_rename_kingdom".
Code:
("action_change_vassal_title",
       [
         (eq, "$players_kingdom_name_set", 1),
         (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
         (faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
         ],"Change your vassals' title of nobility.",
       [(start_presentation, "prsnt_set_vassal_title"),
        ]
       ),
Replace this Native script wholesale. There are only minor changes to it, but replacing it is far easier than inserting lines, etc.
Code:
  # script_troop_set_title_according_to_faction
  # Input: arg1 = troop_no, arg2 = faction_no
  # EDITED FROM NATIVE TO ALLOW CUSTOM PLAYER KINGDOM TITLES
  ("troop_set_title_according_to_faction",
    [
      (store_script_param, ":troop_no", 1),
      (store_script_param, ":faction_no", 2),
      
      (assign, ":custom_name", 0),
      (try_begin),
        (try_begin),
            (eq, ":faction_no", "fac_player_supporters_faction"),
            (troop_get_type, ":gender", ":troop_no"),
            (try_begin),
              (eq, ":gender", 0), #male
              (troop_slot_eq, "trp_heroes_end", 0, 1),
              (str_store_troop_name, s0, "trp_heroes_end"),
              (str_store_troop_name_plural, s1, ":troop_no"),
              (str_store_string, s1, "str_s0_s1"),
              (assign, ":custom_name", 1),              
            (else_try),
              (troop_slot_eq, "trp_heroes_end", 1, 1),
              (str_store_troop_name_plural, s0, "trp_heroes_end"),
              (str_store_troop_name_plural, s1, ":troop_no"),
              (str_store_string, s1, "str_s0_s1"),
              (assign, ":custom_name", 1),              
            (try_end),
            (eq, ":custom_name", 1), #So if it fails, will rename normally
        (else_try),
            (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
            (str_store_troop_name_plural, s0, ":troop_no"),
            (troop_get_type, ":gender", ":troop_no"),
            (store_sub, ":title_index", ":faction_no", kingdoms_begin),
            (try_begin),
              (eq, ":gender", 0), #male
              (val_add, ":title_index", kingdom_titles_male_begin),
            (else_try),
              (val_add, ":title_index", kingdom_titles_female_begin),
            (try_end),
            (str_store_string, s1, ":title_index"),
        (try_end),
        (troop_set_name, ":troop_no", s1),
        (troop_get_slot, ":troop_party", ":troop_no", slot_troop_leaded_party),
        (gt, ":troop_party", 0),
        (str_store_troop_name, s5, ":troop_no"),
        (party_set_name, ":troop_party", "str_s5_s_party"),
      (try_end),
      ]),
You'll be adding a single line to the dialog where you grant a fief to your companions, which begins as follows:
Code:
  [anyone,"member_fief_grant_3", [
//...yadda yadda...//
     (else_try),	
         (str_store_string, s14, "str_lord_s12"),
     (try_end),
     (troop_set_name, "$g_talk_troop", s14),
     (call_script, "script_troop_set_title_according_to_faction", "$g_talk_troop", "fac_player_supporters_faction"), #INSERT THIS LINE
     (unlock_achievement, ACHIEVEMENT_I_DUB_THEE),
//...yadda yadda yadda...//

Since there isn't a way to edit the strings stored in strings.txt or quick_strings.txt, I use the troop name and plural name for one of the "fake" troops -- "trp_quick_battle_troops_end" "trp_heroes_end" -- that is used by the engine as a looping device rather than an actual agent-template. I haven't seen any ill effects for editing its names this way, nor for using two slots assigned to it. (One must use a troop that is flagged as a hero tf_hero for this, or the change in names is not stored in the savegame.)
 

FrisianDude

Archduke
M&BWB
Best answers
0
Caba, I'm becoming more and more convinced that you're a bit of a saint. This sounds lovely and very useful, and so the village raid OSP you posted as well, and all your other previous WB, SP, Codes! :grin:
 

Paradoxis

Knight
WBWF&S
Best answers
0
I have never tried to alter the codings although i do want to put this custom titles into my game. Is there an idiot-proof, step-by-step guide to doing this?

What you just presented is unable to be deciphered by my comprehension level.

(e.g. where do i find module_presentation?)
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
You find the various module_*.py files in the Module System, or the source code. You can download Warband's Native Module System from the Taleworlds website, or use the source code from another mod, such as Diplomacy. You'll want to take a look at Getting Started to get the ModSys set up with Python installed (to turn these .py files into the .txts that the game reads) etc.

Once that is taken care of, each of those spoilers above is in reference to a specific module_*.py file. Open the file up and follow the given instructions in the spoiler. So for the presentation, just scroll to the very bottom of the module_presentations.py file and copy-paste the above before the last character, which is a ] closed bracket.

For game_menus, you want to search for:  ("camp_action"  and then find the code that looks similar to what is in the spoiler here, but references changing the kingdom's name. Paste the code from the spoiler all before the ("action_rename_kingdom" 

For scripts, search for "troop_set_title_according_to_faction" and then copy-paste what is in the spoiler on top of everything contained there, replacing it.

For the dialogs, search for the code in the spoiler, find that spot, and then copy-paste that one line into the correct position.
 

Marcolino

Knight
M&BWB
Best answers
0
Hi. I added this script to my mod and it is working - thanks! :grin:
But I have a simple question. How do I add a title to my character? I wanted him to be "King", "Kaiser", whatever, when I decide to create my own kingdom. Is there a script for that?

Thanks
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
Marcolino said:
But I have a simple question. How do I add a title to my character? I wanted him to be "King", "Kaiser", whatever, when I decide to create my own kingdom. Is there a script for that?
Easiest way to do that is just go into your Character page and click in your name. You are free to edit it at any time :wink:
 

Marcolino

Knight
M&BWB
Best answers
0
Thanks - This is what I have been using.

However, I just wanted to know if that was a way to mod that as well (more elegant solution)?

Thanks
 

Hatonastick

Hahaha!  Brilliant mate!  I think I'm going to give this coding thing away and just throw a bunch of your scripts into my mod and call it a day. :smile:
 

del

Master Knight
Best answers
0
On something the same as this Caba`drin one of the biggest problems mount and blade has is if you add a new race or body type in module skins and header_troops the game considers them all to be female and calls them so in the mod ?

Is their any chance you could do a code in which you can set the tf_ troop header to be male or female so the game considers them to be as such ?

Love the work you have done for mount and blade warbands Caba`drin and you are definately one of the best coders of mount and blade on the forums  :cool:
 

Marcolino

Knight
M&BWB
Best answers
0
This is a pretty good script. Now I checked around and found the "Expanded Nobility Title System kit (v0.33)" by jrider. His script include automating the player's character titles in case he/she becomes a vassal to one of the existing kings or if he/she decides to become a king/queen in his/hers own right
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
Code fixed above. I overlooked the fact that non tf_hero troops do not have name changes stored in savegames, so the troop I use to store strings in has been changed to trp_heroes_end. Now changes in titles will actually be persistent with saving/loading the game.

Also added a "revert to default titles" button in the presentation.
 

13exa

Knight at Arms
Best answers
0
Are you make other [WB, SP, Code] now?? You are very great Coder Caba' drin
 

13exa

Knight at Arms
Best answers
0
Caba`drin said:
You'll be adding a single line to the dialog where you grant a fief to your companions, which begins as follows:
Code:
  [anyone,"member_fief_grant_3", [
//...yadda yadda...//
     (else_try),	
         (str_store_string, s14, "str_lord_s12"),
     (try_end),
     (troop_set_name, "$g_talk_troop", s14),
     (call_script, "script_troop_set_title_according_to_faction", "$g_talk_troop", "fac_player_supporters_faction"), #INSERT THIS LINE
     (unlock_achievement, ACHIEVEMENT_I_DUB_THEE),
//...yadda yadda yadda...//
Im sorry, When i add this to dialog and replace "member_fief_grant_3", it was getting error.
 

Lumos

Section Moderator
M&BWBWF&SNWVC
Best answers
0
Your comments must begin with #s, not //s. If you really have comments beginning with //, fix them.
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
13exa said:
Im sorry, When i add this to dialog and replace "member_fief_grant_3", it was getting error.
In the spoiler for dialogs "member_fief_grant_3" bit, you'd note there is only a single line being added. All of the rest is only to help positioning the one line that needs to be added.  I use those //... ...// marks simply as way to indicate there's a chunk of text missing. "yadda yadda" isn't particularly a helpful comment to have in the text, after all, so it should not appear in the code itself. Just drop that single line into the place I've indicated.
 

Ikaguia

Grandmaster Knight
WBWF&SNW
Best answers
0
is it at FEMP?
i think it is, but just to make sure, because I don't want to have this in two diferent places in my mod...
 

Weston

Recruit
Best answers
0
1. Wtf
2. Don't understand any of that
3. Would like help putting this in my files.
4. Where are these files that i need to find?
 
Top