SP Tutorial Module System How to make troops recruitable from castle/towns.

Users who are viewing this thread

In placing all the scripts, I would prefer to simple copy paste de codes after whatever script they tell me, just like the first post, but with the god damn working scripts cause I dont know what I'm doing wrong :C
 
Hey, so I tried implementing this code but keep recieving a surprising error while compiling: a synthax error... for the last " ), " ?

Really don't know what's wrong here.


Nevermind, I just deleted it and now it works :party:

However, I still have a weird annoying error with the mercenary script:

MODULE scripts SYNTAX ERROR:
failed to parse element #392
72 is not a legal identifier at position #0 in (72, 'list[len=10]')
 
Last edited:
It seems that more and more people face troubles with getting this to work nowdays. And to no surprise - as a somewhat experienced modder I find the instructions not noob-friendly enough, of course one can follow them if they know what they are doing, but most people who are still new to modding and just want the feature in question likely wouldn't keep up just yet. Which led me to thought I could rephrase the opening post to make it more straightforward and actually point on the things which are getting added (right now it all blends in one big mess). The code we add will be green, and the whilte lines are the ones which are already there, you can use them for searching the right spot and comparing the result to what's under my spoilers.

Okay, so what this does? It adds the native mechanic of village volunteers to castles and towns and comes with 2 mutually exclusive options:
1) Without separation - both castles and towns will offer the slot_faction_tier_5_troop of the owner faction.
1. Open module_scripts.py, and make the following additions:
#script_cf_town_castle_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_town_castle_recruit_volunteers_cond",
[(store_faction_of_party, ":town_faction", "$current_town"),
(party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
(store_relation, ":town_faction_relation", ":town_faction", "fac_player_faction"),
(ge, ":center_relation", 0),
(this_or_next|ge, ":center_relation", 5),
(this_or_next|eq, ":town_faction", "$players_kingdom"),
(this_or_next|ge, ":town_faction_relation", 0),
(this_or_next|eq, ":town_faction", "$supported_pretender_old_faction"),
(eq, "$players_kingdom", 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(ge, ":free_capacity", 1),
]),


#script_cf_village_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_village_recruit_volunteers_cond",
[

(try_begin),
(eq, "$cheat_mode", 1),
..................

#script_town_castle_recruit_nobles_recruit
# INPUT: none
# OUTPUT: none
("town_castle_recruit_nobles_recruit",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(val_min, ":volunteer_amount", ":free_capacity"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 200),#200 denars per man
(val_min, ":volunteer_amount", ":gold_capacity"),
(party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(store_mul, ":cost", ":volunteer_amount", 200),#200 denars per man
(troop_remove_gold, "trp_player", ":cost"),
]),


#script_village_recruit_volunteers_recruit
# INPUT: none
# OUTPUT: none
("village_recruit_volunteers_recruit",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_2_troop),
2. Open module_game_menus.py, and make the following additions:
("recruit_nobles",[(call_script, "script_cf_town_castle_recruit_volunteers_cond"),]
,"Recruit Nobles.",
[
(try_begin),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(jump_to_menu, "mnu_recruit_nobles"),
(try_end),
]),


("join_tournament", [(neg|is_currently_night),(party_slot_ge, "$current_town", slot_town_has_tournament, 1),]
,"Join the tournament.",
[
(call_script, "script_fill_tournament_participants_troop", "$current_town", 1),
..................

("recruit_nobles",0,
"{s18}",
"none",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 40),#40 denars per man
(assign, ":party_capacity", ":free_capacity"),
(val_min, ":party_capacity", ":gold_capacity"),
(try_begin),
(gt, ":party_capacity", 0),
(val_min, ":volunteer_amount", ":party_capacity"),
(try_end),
(assign, reg5, ":volunteer_amount"),
(assign, reg7, 0),
(try_begin),
(gt, ":volunteer_amount", ":gold_capacity"),
(assign, reg7, 1), #not enough money
(try_end),
(try_begin),
(eq, ":volunteer_amount", 0),
(str_store_string, s18, "@ Nobody here seems to be willing to join your party."),
(else_try),
(store_mul, reg6, ":volunteer_amount", 40),#40 denars per man
(str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
(try_begin),
(eq, reg5, 1),
(str_store_string, s18, "@One {s3} volunteers to follow you."),
(else_try),
(str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
(try_end),
(set_background_mesh, "mesh_pic_recruits"),
(try_end),
],
[
("continue_not_enough_gold",
[
(eq, reg7, 1),
],
"I don't have enough money...",
[
(jump_to_menu, "mnu_town"),
]),

("continue",
[
(eq, reg7, 0),
(eq, reg5, 0),
], #noone willing to join
"Continue...",
[
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(jump_to_menu, "mnu_town"),
]),

("recruit_them",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Recruit them ({reg6} denars).",
[
(call_script, "script_town_recruit_nobles_recruit"),

(jump_to_menu, "mnu_town"),
]),

("forget_it",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Forget it.",
[
(jump_to_menu, "mnu_town"),
]),
]),


("notification_relieved_as_marshal", mnf_disable_all_keys,
"{s4} wishes to inform you that your services as marshal are no longer required. In honor of valiant efforts on behalf of the realm over the last {reg4} days, however, {reg8?she:he} offers you a purse of {reg5} denars.",
"none",
[
(assign, reg4, "$g_player_days_as_marshal"),
3. Open module_simple_triggers.py, find this trigger and replace villages begin/end with centers begin/end
# Adding mercenary troops to the towns
(72,
[
(call_script, "script_update_mercenary_units_of_towns"),
#NPC changes begin
# removes (call_script, "script_update_companion_candidates_in_taverns"),
#NPC changes end
(call_script, "script_update_ransom_brokers"),
(call_script, "script_update_tavern_travellers"),
(call_script, "script_update_tavern_minstrels"),
(call_script, "script_update_booksellers"),
(call_script, "script_update_villages_infested_by_bandits"),
(try_for_range, ":village_no", centers_begin, centers_end),
(call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
(try_end),
]),
2) With separation - castles will still offer you the slot_faction_tier_5_troop, but towns will have only the slot_faction_tier_1_troop, basically the same as villages.
1. Open module_scripts.py, and make the following additions:
#script_cf_town_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_town_recruit_volunteers_cond",
[(store_faction_of_party, ":town_faction", "$current_town"),
(party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
(store_relation, ":town_faction_relation", ":town_faction", "fac_player_faction"),
(ge, ":center_relation", 0),
(this_or_next|ge, ":center_relation", 5),
(this_or_next|eq, ":town_faction", "$players_kingdom"),
(this_or_next|ge, ":town_faction_relation", 0),
(this_or_next|eq, ":town_faction", "$supported_pretender_old_faction"),
(eq, "$players_kingdom", 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(ge, ":free_capacity", 1),
]),


#script_cf_village_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_village_recruit_volunteers_cond",
[

(try_begin),
(eq, "$cheat_mode", 1),
..................

#script_town_recruit_nobles_recruit
# INPUT: none
# OUTPUT: none
("town_recruit_nobles_recruit", #renamed
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_1_troop), #changed tier so it wouldnt recruit nobles.
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(val_min, ":volunteer_amount", ":free_capacity"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 200),#200 denars per man
(val_min, ":volunteer_amount", ":gold_capacity"),
(party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(store_mul, ":cost", ":volunteer_amount", 200),#200 denars per man
(troop_remove_gold, "trp_player", ":cost"),
]),


#script_village_recruit_volunteers_recruit
# INPUT: none
# OUTPUT: none
("village_recruit_volunteers_recruit",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_2_troop),
2. Open module_game_menus.py, and make the following additions:

("recruit_nobles",[(is_between, "$current_town",
castles_begin, castles_end), (call_script,
"script_cf_town_castle_recruit_volunteers_cond"),]
,"Recruit Nobles.",
[
(try_begin),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(jump_to_menu, "mnu_recruit_nobles"),
(try_end),
]),

("recruit_normals",[(is_between, "$current_town",
towns_begin, towns_end), (call_script,
"script_cf_town_recruit_volunteers_cond"),]
,"Recruit Volunteers.",
[
(try_begin),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(jump_to_menu, "mnu_recruit_normales"),
(try_end),
]),


("join_tournament", [(neg|is_currently_night),(party_slot_ge, "$current_town", slot_town_has_tournament, 1),]
,"Join the tournament.",
[
(call_script, "script_fill_tournament_participants_troop", "$current_town", 1),
..................

("recruit_nobles",0,
"{s18}",
"none",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 40),#40 denars per man
(assign, ":party_capacity", ":free_capacity"),
(val_min, ":party_capacity", ":gold_capacity"),
(try_begin),
(gt, ":party_capacity", 0),
(val_min, ":volunteer_amount", ":party_capacity"),
(try_end),
(assign, reg5, ":volunteer_amount"),
(assign, reg7, 0),
(try_begin),
(gt, ":volunteer_amount", ":gold_capacity"),
(assign, reg7, 1), #not enough money
(try_end),
(try_begin),
(eq, ":volunteer_amount", 0),
(str_store_string, s18, "@ Nobody here seems to be willing to join your party."),
(else_try),
(store_mul, reg6, ":volunteer_amount", 40),#40 denars per man
(str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
(try_begin),
(eq, reg5, 1),
(str_store_string, s18, "@One {s3} volunteers to follow you."),
(else_try),
(str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
(try_end),
(set_background_mesh, "mesh_pic_recruits"),
(try_end),
],
[
("continue_not_enough_gold",
[
(eq, reg7, 1),
],
"I don't have enough money...",
[
(jump_to_menu, "mnu_town"),
]),

("continue",
[
(eq, reg7, 0),
(eq, reg5, 0),
], #noone willing to join
"Continue...",
[
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(jump_to_menu, "mnu_town"),
]),

("recruit_them",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Recruit them ({reg6} denars).",
[
(call_script, "script_town_recruit_nobles_recruit"),

(jump_to_menu, "mnu_town"),
]),

("forget_it",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Forget it.",
[
(jump_to_menu, "mnu_town"),
]),
]),


("recruit_normales",0,
"{s18}",
"none",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_1_troop), #Notice the changed tier
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 40),#40 denars per man
(assign, ":party_capacity", ":free_capacity"),
(val_min, ":party_capacity", ":gold_capacity"),
(try_begin),
(gt, ":party_capacity", 0),
(val_min, ":volunteer_amount", ":party_capacity"),
(try_end),
(assign, reg5, ":volunteer_amount"),
(assign, reg7, 0),
(try_begin),
(gt, ":volunteer_amount", ":gold_capacity"),
(assign, reg7, 1), #not enough money
(try_end),
(try_begin),
(eq, ":volunteer_amount", 0),
(str_store_string, s18, "@ Nobody here seems to be willing to join your party."),
(else_try),
(store_mul, reg6, ":volunteer_amount", 40),#40 denars per man
(str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
(try_begin),
(eq, reg5, 1),
(str_store_string, s18, "@One {s3} volunteers to follow you."),
(else_try),
(str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
(try_end),
(set_background_mesh, "mesh_pic_recruits"),
(try_end),
],
[
("continue_not_enough_gold",
[
(eq, reg7, 1),
],
"I don't have enough money...",
[
(jump_to_menu, "mnu_town"),
]),

("continue",
[
(eq, reg7, 0),
(eq, reg5, 0),
], #noone willing to join
"Continue...",
[
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(jump_to_menu, "mnu_town"),
]),

("recruit_them",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Recruit them ({reg6} denars).",
[
(call_script, "script_town_recruit_nobles_recruit"),

(jump_to_menu, "mnu_town"),
]),

("forget_it",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Forget it.",
[
(jump_to_menu, "mnu_town"),
]),
]),


("notification_relieved_as_marshal", mnf_disable_all_keys,
"{s4} wishes to inform you that your services as marshal are no longer required. In honor of valiant efforts on behalf of the realm over the last {reg4} days, however, {reg8?she:he} offers you a purse of {reg5} denars.",
"none",
[
(assign, reg4, "$g_player_days_as_marshal"),
3. Open module_simple_triggers.py, find this trigger and replace villages begin/end with centers begin/end
# Adding mercenary troops to the towns
(72,
[
(call_script, "script_update_mercenary_units_of_towns"),
#NPC changes begin
# removes (call_script, "script_update_companion_candidates_in_taverns"),
#NPC changes end
(call_script, "script_update_ransom_brokers"),
(call_script, "script_update_tavern_travellers"),
(call_script, "script_update_tavern_minstrels"),
(call_script, "script_update_booksellers"),
(call_script, "script_update_villages_infested_by_bandits"),
(try_for_range, ":village_no", centers_begin, centers_end),
(call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
(try_end),
]),
That's all. To see the recruiting option you must have at least 1 free place in your party and the fief should have any volunteers available (they get some every 3 days normally). If the fief is not owned by the faction you joined, you must also have 5 or more positive relation with it to see the option.
1. If you want to skip the required 3 days of waiting find this in game_start script:
Code:
(try_for_range, ":village_no", villages_begin, villages_end),
        (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(try_end),
and replace villages_begin with centers_begin and villages_end with centers_end, then just start new game and given you meet the other requirements the option should appear.
2. If you want to change the troops getting offered, either change at the respective places the slot name from slot_faction_tier_1_troop to slot_faction_tier_3_troop for example or just straight up change the troop stored there - search in game_start script for lines like
Code:
(faction_set_slot, "fac_culture_1",  slot_faction_tier_3_troop,
(it should be close to the top).
 
Alright, so now it compiles properly, all thanks to Dalion!

However... when I click on *Recruit Them* in the town menu, nothing happens, and the castle menu always displays -1 Rhodok Frontliner volunteer to join you. But no button to accept or return like in the town menu...

This is the module_scripts part, additions in green:


Code:
  #script_cf_town_recruit_volunteers_cond
  # INPUT: none
  # OUTPUT: none
  ("cf_town_recruit_professionals_cond",
   [(store_faction_of_party, ":town_faction", "$current_town"),
   (party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
   (store_relation, ":town_faction_relation", ":town_faction", "fac_player_faction"),
   (ge, ":center_relation", 10),
   (this_or_next|ge, ":center_relation", 0),
   (this_or_next|eq, ":town_faction", "$players_kingdom"),
   (this_or_next|ge, ":town_faction_relation", 0),
   (this_or_next|eq, ":town_faction", "$supported_pretender_old_faction"),
   (eq, "$players_kingdom", 0),
   (party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
   (party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
   (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
   (ge, ":free_capacity", 1),
   ]),

  #script_cf_village_recruit_volunteers_cond
  # INPUT: none
  # OUTPUT: none
  ("cf_village_recruit_volunteers_cond",
    [

     (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "str_checking_volunteer_availability_script"),
     (try_end),

     (neg|party_slot_eq, "$current_town", slot_village_state, svs_looted),
     (neg|party_slot_eq, "$current_town", slot_village_state, svs_being_raided),
     (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
     (store_faction_of_party, ":village_faction", "$current_town"),
     (party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
     (store_relation, ":village_faction_relation", ":village_faction", "fac_player_faction"),

     (ge, ":center_relation", 0),
     (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "str_center_relation_at_least_zero"),
     (try_end),




     (this_or_next|ge, ":center_relation", 5),
     (this_or_next|eq, ":village_faction", "$players_kingdom"),
     (this_or_next|ge, ":village_faction_relation", 0),
     (this_or_next|eq, ":village_faction", "$supported_pretender_old_faction"),
        (eq, "$players_kingdom", 0),

     (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "str_relationfaction_conditions_met"),
     (try_end),


     (party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
     (party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),

     (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "str_troops_available"),
     (try_end),


     (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
     (ge, ":free_capacity", 1),

     (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "str_party_has_capacity"),
     (try_end),


     ]),


  #script_casle_recruit_nobles_recruit
  # INPUT: none
  # OUTPUT: none
  ("cf_castle_recruit_nobles_cond", #renamed
   [(store_faction_of_party, ":cur_faction", "$current_town"),
   (faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop), #changed tier so it wouldnt recruit nobles.
   (party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
   (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
   (val_min, ":volunteer_amount", ":free_capacity"),
   (store_troop_gold, ":gold", "trp_player"),
   (store_div, ":gold_capacity", ":gold", 200),#200 denars per man
   (party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
   (party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
   (store_mul, ":cost", ":volunteer_amount", 200),#200 denars per man
   (troop_remove_gold, "trp_player", ":cost"),
   ]),

  #script_village_recruit_volunteers_recruit
  # INPUT: none
  # OUTPUT: none



And this is the module_game_menus part:

Code:
        ], "Door to the castle."),

   ###Town/Castle Recruitment Part 1
   ("recruit_nobles",[(is_between, "$current_town",
     castles_begin, castles_end), (call_script,
    "script_cf_castle_recruit_nobles_cond"),]
    ,"Recruit Nobles.",
    [
     (try_begin),
      (call_script, "script_cf_enter_center_location_bandit_check"),
     (else_try),
      (jump_to_menu, "mnu_recruit_nobles"),
     (try_end),
     ]),

   ("recruit_professionals",[(is_between, "$current_town",
     towns_begin, towns_end), (call_script,
    "script_cf_town_recruit_professionals_cond"),]
    ,"Recruit Professionals.",
    [
     (try_begin),
      (call_script, "script_cf_enter_center_location_bandit_check"),
     (else_try),
      (jump_to_menu, "mnu_recruit_professionals"),
     (try_end),
     ]),


      ("join_tournament", [(neg|is_currently_night),(party_slot_ge, "$current_town", slot_town_has_tournament, 1),]
       ,"Join the tournament.",

Code:
###Town/Castle Recruitment Part 2
  ("recruit_nobles",0,
    "{s18}",
    "none",
    [(store_faction_of_party, ":cur_faction", "$current_town"),
    (faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
    (party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
    (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
    (store_troop_gold, ":gold", "trp_player"),
    (store_div, ":gold_capacity", ":gold", 200),#200 denars per noble
    (assign, ":party_capacity", ":free_capacity"),
    (val_min, ":party_capacity", ":gold_capacity"),
    (try_begin),
      (gt, ":party_capacity", 0),
      (val_min, ":volunteer_amount", ":party_capacity"),
    (try_end),
    (assign, reg5, ":volunteer_amount"),
    (assign, reg7, 0),
    (try_begin),
      (gt, ":volunteer_amount", ":gold_capacity"),
      (assign, reg7, 1), #not enough money
    (try_end),
    (try_begin),
      (eq, ":volunteer_amount", 0),
      (str_store_string, s18, "@No one here seems to be willing to join your party."),
    (else_try),
      (store_mul, reg6, ":volunteer_amount", 200),#200 denars per noble
      (str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
      (try_begin),
        (eq, reg5, 1),
        (str_store_string, s18, "@One {s3} volunteers to follow you."),
      (else_try),
        (str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
      (try_end),
      (set_background_mesh, "mesh_pic_recruits"),
    (try_end),
    ],
    [
      ("continue_not_enough_gold",
      [
        (eq, reg7, 1),
      ],
      "I don't have enough money...",
      [
      (jump_to_menu, "mnu_town"),
      ]),
 
      ("continue",
      [
        (eq, reg7, 0),
        (eq, reg5, 0),
      ], #noone willing to join              
      "Continue...",
      [
        (party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
        (jump_to_menu, "mnu_town"),
      ]),
 
      ("recruit_them",
      [
        (eq, reg7, 0),
        (gt, reg5, 0),
      ],
      "Recruit them ({reg6} denars).",
      [
        (call_script, "script_cf_castle_recruit_nobles_cond"),
                   
        (jump_to_menu, "mnu_town"),
      ]),
 
      ("forget_it",
      [
        (eq, reg7, 0),
        (gt, reg5, 0),
      ],
      "Forget it.",
      [
      (jump_to_menu, "mnu_town"),
      ]),
    ],
  ),
  ("recruit_professionals",0,
    "{s18}",
    "none",
    [(store_faction_of_party, ":cur_faction", "$current_town"),
    (faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_3_troop),  #Notice the changed tier
    (party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
    (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
    (store_troop_gold, ":gold", "trp_player"),
    (store_div, ":gold_capacity", ":gold", 50),#40 denars per man
    (assign, ":party_capacity", ":free_capacity"),
    (val_min, ":party_capacity", ":gold_capacity"),
    (try_begin),
      (gt, ":party_capacity", 0),
      (val_min, ":volunteer_amount", ":party_capacity"),
    (try_end),
    (assign, reg5, ":volunteer_amount"),
    (assign, reg7, 0),
    (try_begin),
      (gt, ":volunteer_amount", ":gold_capacity"),
      (assign, reg7, 1), #not enough money
    (try_end),
    (try_begin),
      (eq, ":volunteer_amount", 0),
      (str_store_string, s18, "@No one here seems to be willing to join your party."),
    (else_try),
      (store_mul, reg6, ":volunteer_amount", 50),#40 denars per man
      (str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
      (try_begin),
        (eq, reg5, 1),
        (str_store_string, s18, "@One {s3} volunteers to follow you."),
      (else_try),
        (str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
      (try_end),
      (set_background_mesh, "mesh_pic_recruits"),
    (try_end),
    ],
    [
      ("continue_not_enough_gold",
      [
        (eq, reg7, 1),
      ],
      "I don't have enough money...",
      [
  (jump_to_menu, "mnu_town"),
      ]),
 
      ("continue",
      [
        (eq, reg7, 0),
        (eq, reg5, 0),
      ], #noone willing to join              
      "Continue...",
      [
        (party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
  (jump_to_menu, "mnu_town"),
      ]),
 
      ("recruit_them",
      [
        (eq, reg7, 0),
        (gt, reg5, 0),
      ],
      "Recruit them ({reg6} denars).",
      [
        (call_script, "script_cf_town_recruit_professionals_cond"),
                   
  (jump_to_menu, "mnu_town"),
      ]),
 
      ("forget_it",
      [
        (eq, reg7, 0),
        (gt, reg5, 0),
      ],
      "Forget it.",
      [
  (jump_to_menu, "mnu_town"),
      ]),
    ]),
  ),

  ("notification_relieved_as_marshal", mnf_disable_all_keys,
    "{s4} wishes to inform you that your services as marshal are no longer required. In honor of valiant efforts on behalf of the realm over the last

The trigger is included, and the menus show up (for the most part), but one doesn't have any effect and the other is bugged :/


I tried moving things around, copying existing scripts but nothing seems to be working :neutral:
 
Oh. My. Bloody. God. Finally got this to work. I have spent way too much time on this, but at least it works now, and uh, yeah, the initial tutorial is unfortunately very confusing, so...


For any newcomer who would like to use this OSP code but isn't good at navigating the module system, here is what you have to do:

Hint: When I say Ctrl+f "something" you should hold Ctrl + f and then paste the text in bold.

Alright, let's get started.

Open module_scripts and Ctrl+f #script_cf_village_recruit_volunteers_cond , once you have found it, paste the following code on top, as shown here (additions are in green, the rest is for reference so you know put the code in the right place):

#script_cf_troop_agent_is_alive
# INPUT: arg1 = troop_id
("cf_troop_agent_is_alive",
[(store_script_param, ":troop_no", 1),
(assign, ":alive_count", 0),
(try_for_agents, ":cur_agent"),
(agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
(eq, ":troop_no", ":cur_agent_troop"),
(agent_is_alive, ":cur_agent"),
(val_add, ":alive_count", 1),
(try_end),
(gt, ":alive_count", 0),
]),

#script_cf_town_castle_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_castle_recruit_nobles_cond",
[(store_faction_of_party, ":town_faction", "$current_town"),
(party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
(store_relation, ":town_faction_relation", ":town_faction", "fac_player_faction"),
(ge, ":center_relation", 0),
(this_or_next|ge, ":center_relation", 5),
(this_or_next|eq, ":town_faction", "$players_kingdom"),
(this_or_next|ge, ":town_faction_relation", 5),
(this_or_next|eq, ":town_faction", "$supported_pretender_old_faction"),
( eq, "$players_kingdom", 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(ge, ":free_capacity", 1),
]),

#script_cf_town_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_town_recruit_professionals_cond", #renamed
[(store_faction_of_party, ":town_faction", "$current_town"),
(party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
(store_relation, ":town_faction_relation", ":town_faction", "fac_player_faction"),
(ge, ":center_relation", 0),
(this_or_next|ge, ":center_relation", 10),
(this_or_next|eq, ":town_faction", "$players_kingdom"),
(this_or_next|ge, ":town_faction_relation", 0),
(this_or_next|eq, ":town_faction", "$supported_pretender_old_faction"),
( eq, "$players_kingdom", 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 0),
(party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(ge, ":free_capacity", 1),
]),


#script_cf_village_recruit_volunteers_cond
# INPUT: none
# OUTPUT: none
("cf_village_recruit_volunteers_cond",

Once that is done, Ctrl+f #script_village_recruit_volunteers_recruit , again, post the following code (in green) on top as shown here:

(try_begin),
(eq, "$cheat_mode", 1),
(display_message, "str_party_has_capacity"),
(try_end),


]),

#script_town_castle_recruit_nobles_recruit
# INPUT: none
# OUTPUT: none
("cf_castle_recruit_nobles",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(val_min, ":volunteer_amount", ":free_capacity"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 200),#200 denars per man
(val_min, ":volunteer_amount", ":gold_capacity"),
(party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(store_mul, ":cost", ":volunteer_amount", 200),#10 denars per man (troop_remove_gold, "trp_player", ":cost"),
]),

#script_town_recruit_nobles_recruit
# INPUT: none
# OUTPUT: none
("cf_town_recruit_professionals", #renamed
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_3_troop), #Since this updated version of the code sets recruit cost to 40 denars it might be good to change the #troop tier
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(val_min, ":volunteer_amount", ":free_capacity"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 50),#50 denars per man (val_min, ":volunteer_amount", ":gold_capacity"),
(party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(store_mul, ":cost", ":volunteer_amount", 50),#10 denars per man
(troop_remove_gold, "trp_player", ":cost"),
]),


#script_village_recruit_volunteers_recruit
# INPUT: none
# OUTPUT: none

We are done with module_scripts so make sure to save so we can safely open the next file: module_game_menus

Once you have opened module_game_menus, Ctrl+f ("castle_castle", , scroll down or ctrl+f once (otherwise you will be in the wrong section of the code) and find ], "Door to the castle."), . Now paste the following code underneath so it looks like this:

], "Door to the castle."),

("recruit_nobles",
[(is_between, "$current_town", castles_begin, castles_end),
(call_script, "script_cf_castle_recruit_nobles_cond"),
],"Recruit Nobles.",
[
(try_begin),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(jump_to_menu, "mnu_recruit_nobles"),
(try_end),
]),

("recruit_professionals",
[(is_between, "$current_town", towns_begin, towns_end),
(call_script, "script_cf_town_recruit_professionals_cond"),
],"Recruit Professionals.",
[
(try_begin),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(jump_to_menu, "mnu_recruit_professionals"),
(try_end),
]),



("join_tournament", [
(neg|is_currently_night),

For our final addition in module_game_menus, Ctrl+f notification_relieved_as_marshal and add the following code on top of it so it looks as such:

("continue",[],"Hold off...",
[
(jump_to_menu, "mnu_town"),
]),
]
),

###Town/Castle Recruitment Part 2
(
"recruit_nobles",0,
"{s18}",
"none",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_5_troop),
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 200),#200 denars per noble
(assign, ":party_capacity", ":free_capacity"),
(val_min, ":party_capacity", ":gold_capacity"),
(try_begin),
(gt, ":party_capacity", 0),
(val_min, ":volunteer_amount", ":party_capacity"),
(try_end),
(assign, reg5, ":volunteer_amount"),
(assign, reg7, 0),
(try_begin),
(gt, ":volunteer_amount", ":gold_capacity"),
(assign, reg7, 1), #not enough money
(try_end),
(try_begin),
(eq, ":volunteer_amount", 0),
(str_store_string, s18, "@no One here seems to be willing to join your party."),
(else_try),
(store_mul, reg6, ":volunteer_amount", 200),#200 denars per noble
(str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
(try_begin),
(eq, reg5, 1),
(str_store_string, s18, "@One {s3} volunteers to follow you."),
(else_try),
(str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
(try_end),
(set_background_mesh, "mesh_pic_recruits"),
(try_end),
],
[
("continue_not_enough_gold",
[
(eq, reg7, 1),
],
"I don't have enough money...",
[
(jump_to_menu, "mnu_town"),
]),

("continue",
[
(eq, reg7, 0),
(eq, reg5, 0),
], #noone willing to join
"Continue...",
[
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(jump_to_menu, "mnu_town"),
]),

("recruit_them",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Recruit them ({reg6} denars).",
[
(call_script, "script_cf_castle_recruit_nobles"),

(jump_to_menu, "mnu_town"),
]),

("forget_it",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Forget it.",
[
(jump_to_menu, "mnu_town"),
]),
],
),

(
"recruit_professionals",0,
"{s18}",
"none",
[(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_3_troop), #Notice the changed tier
(party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
(party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
(store_troop_gold, ":gold", "trp_player"),
(store_div, ":gold_capacity", ":gold", 50),#50 denars per man
(assign, ":party_capacity", ":free_capacity"),
(val_min, ":party_capacity", ":gold_capacity"),
(try_begin),
(gt, ":party_capacity", 0),
(val_min, ":volunteer_amount", ":party_capacity"),
(try_end),
(assign, reg5, ":volunteer_amount"),
(assign, reg7, 0),
(try_begin),
(gt, ":volunteer_amount", ":gold_capacity"),
(assign, reg7, 1), #not enough money
(try_end),
(try_begin),
(eq, ":volunteer_amount", 0),
(str_store_string, s18, "@no One here seems to be willing to join your party."),
(else_try),
(store_mul, reg6, ":volunteer_amount", 50),#50 denars per man
(str_store_troop_name_by_count, s3, ":volunteer_troop", ":volunteer_amount"),
(try_begin),
(eq, reg5, 1),
(str_store_string, s18, "@One {s3} volunteers to follow you."),
(else_try),
(str_store_string, s18, "@{reg5} {s3} volunteer to follow you."),
(try_end),
(set_background_mesh, "mesh_pic_recruits"),
(try_end),
],
[
("continue_not_enough_gold",
[
(eq, reg7, 1),
],
"I don't have enough money...",
[
(jump_to_menu, "mnu_town"),
]),

("continue",
[
(eq, reg7, 0),
(eq, reg5, 0),
], #noone willing to join
"Continue...",
[
(party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
(jump_to_menu, "mnu_town"),
]),

("recruit_them",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Recruit them ({reg6} denars).",
[
(call_script, "script_cf_town_recruit_professionals"),

(jump_to_menu, "mnu_town"),
]),

("forget_it",
[
(eq, reg7, 0),
(gt, reg5, 0),
],
"Forget it.",
[
(jump_to_menu, "mnu_town"),
]),
],
),


("notification_relieved_as_marshal", mnf_disable_all_keys,

Note: You may have a different script on top, but as long as you add the code before the ("notification_relieved_as_marshal" ... you should be fine.


Finally, open up module_simple_triggers, Ctrl+f # Adding mercenary troops to the towns , and replace villages_begin, villages_end with centers_begin, centers_end so it looks like this:

# Adding mercenary troops to the towns
(72,
[
(call_script, "script_update_mercenary_units_of_towns"),
#NPC changes begin
# removes (call_script, "script_update_companion_candidates_in_taverns"),
#NPC changes end
(call_script, "script_update_ransom_brokers"),
(call_script, "script_update_tavern_travellers"),
(call_script, "script_update_tavern_minstrels"),
(call_script, "script_update_booksellers"),
(call_script, "script_update_villages_infested_by_bandits"),
(try_for_range, ":village_no", centers_begin, centers_end),
(call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
(try_end),
]),

That's it! Hopefully this ends up helping someone.
 
Last edited:
Back
Top Bottom