Make village recruits depend on the faction you are in

Users who are viewing this thread

Pr123

Regular
Hello!

I am trying to modify the script script_village_recruit_volunteers_recruit so that the recruits you get from a village would depend on the faction you are in. So far the only modification that I made and works like I want it to is this:
Code:
  #script_village_recruit_volunteers_recruit
  # INPUT: none
  # OUTPUT: none
  ("village_recruit_volunteers_recruit",
    [(try_begin),
		(eq,"$players_kingdom",0),
		(assign,":volunteer_troop", "trp_farmer"),
	 (else_try),
		(party_get_slot, ":volunteer_troop", "$current_town", slot_center_volunteer_troop_type),
	 (try_end),
     (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", 10),#10 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", 10),#10 denars per man
     (troop_remove_gold, "trp_player", ":cost"),
     ]),

If you are not in a faction you will get mercenary troops from the village(farmers upgrade to mercenaries) and if you are in one you will get troops depending on the centers volunteer troop type(you get nord recruits from nord lands). But if I try this:
Code:
 ("village_recruit_volunteers_recruit",
    [(try_begin),
		(eq,"$players_kingdom",0),
		(assign,":volunteer_troop", "trp_farmer"),
	 (else_try),
	 	(eq,"$players_kingdom","$kingdom_1"),
		(assign,":volunteer_troop", "trp_swadian_recruit"),
	 (else_try),
	 	(eq,"$players_kingdom","$kingdom_2"),
		(assign,":volunteer_troop", "trp_vaegir_recruit"),
	 (else_try),
	 	(eq,"$players_kingdom","$kingdom_3"),
		(assign,":volunteer_troop", "trp_khergit_tribesman"),
	 (else_try),
	 	(eq,"$players_kingdom","$kingdom_4"),
		(assign,":volunteer_troop", "trp_nord_recruit"),
	 (else_try),
	 	(eq,"$players_kingdom","$kingdom_5"),
		(assign,":volunteer_troop", "trp_rhodok_tribesman"),
	 (else_try),
		(party_get_slot, ":volunteer_troop", "$current_town", slot_center_volunteer_troop_type),
	 (try_end),
     (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", 10),#10 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", 10),#10 denars per man
     (troop_remove_gold, "trp_player", ":cost"),
     ]),

It doesn't work like I want it to. What I get is that if you are not in any faction, you get the troops correctly, the mercenary ones, but if you join a faction you still get troops depending on centers volunteer troop type. I realise that it just skips the else_try-s because the equatation (eq,"$players_kingdom","$kingdom_1"),(or kingdom_2 etc.) is not true.  What I do not know, is what else do I have to write in that equatation?

Thanks.
 
To have recruit by owner faction is an easy tweak. However, if you want to add independent troop, you will have to add some simple check and assign.

Here is what I use (messy because I have to take out my other code and put in the new one). Haven't test my new codes.

  #script_update_volunteer_troops_in_village
  # INPUT: arg1 = center_no
  # OUTPUT: none
  ("update_volunteer_troops_in_village",
    [
(store_script_param, ":center_no", 1),
(party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
#(party_get_slot, ":center_culture", ":center_no", slot_center_culture),    #Spd - Native Original code

# Spd - Script change volunteer troop to player faction  
(try_begin),
(party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(eq, "$player_has_homage", 1), # Spd - Check if player belongs to a faction
(assign, ":center_faction", "$players_kingdom"),
(faction_get_slot, ":center_culture", ":center_faction", slot_faction_culture),
(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
#(else_try),    # Spd - Restore these two lines if want troop of village's original faction
#(party_get_slot, ":center_culture", ":center_no", slot_center_culture),    #Spd - Native Original code
(else_try),
# Spd - Not tested
(assign, ":center_culture", -1),  # Make sure this doesn't exsist You can define new independent culture for this
(try_end),  
(try_begin),
(gt, ":center_culture", 0), # Spd - if player belongs to a faction
(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
(assign, ":volunteer_troop_tier", 1),
(store_div, ":tier_upgrades", ":player_relation", 10),  
(try_for_range, ":unused", 0, ":tier_upgrades"),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", "10"),
(store_random_in_range, ":random_no", 0, 2), # 0 for random upgrade, 1 = first node, 2 = second node but return -1 of not available.
(troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
(try_begin),
(le, ":upgrade_troop_no", 0),
(troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
(try_end),
(gt, ":upgrade_troop_no", 0),
(val_add, ":volunteer_troop_tier", 1),
(assign, ":volunteer_troop", ":upgrade_troop_no"),
(try_end),
(else_try),    # Spd - (else) if player doesnot belong to a faction, assign farmers
(assign, ":volunteer_troop", "trp_farmer"),
(val_add, ":volunteer_troop_tier", 1),
(try_end),
# Spd - End assigning volunteer troop
     
(assign, ":upper_limit", 7),  
(try_begin),
(ge, ":player_relation", 5),
(assign, ":upper_limit", ":player_relation"),
(val_div, ":upper_limit", 2),
(val_add, ":upper_limit", 10),
(else_try),
(lt, ":player_relation", 0),
(assign, ":upper_limit", 0),
(try_end),

(val_mul, ":upper_limit", 3), 
(store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
(val_div, ":upper_limit", ":amount_random_divider"),
     
(store_random_in_range, ":amount", 0, ":upper_limit"),
(party_set_slot, ":center_no", slot_center_volunteer_troop_type, ":volunteer_troop"),
(party_set_slot, ":center_no", slot_center_volunteer_troop_amount, ":amount"),
]),
 
Thank you for your reply!

I tried your script, but it did not work correctly.
First, I changed script_village_recruit_volunteers_recruit back to like it was in native, then I replaced my script_update_volunteer_troops_in_village with your script_update_volunteer_troops_in_village. Also there was a small mistake in your script, you had (lt, ":random_no", "10"), but I think it should have been (lt, ":random_no", 10),. Anyway, I built the module and started the game. Visited about 10 villages, no one wished to join my group, joined a faction, visited about 20 villages, still no recruits in any village. So, if anybody has the time/patience, please help.

Still I wonder what is $players_kingdom equal to if you join a faction. It isn't equal to $kingdom_1, I think a variable named $kingdom_1 doesn't even exist. So if anybody does know, please say.

Also, what exactly does xxx_set_slot(like faction_set_slot) and xxx_get_slot(like faction_get_slot) do? :oops:
 
:oops:

Untested.

I will take another look, because I added the farmer bit on the fly as I clean up the code. I wasn't sure about that bit.

$player_kingdom equal to whatever kingdom player is in.

slots are constant places holder defined in module_constants.py

faction_get_slot (get the value from that slot) or faction_set_slot (put this value in that slot) are functions defined in header_operations.py. You can take a look there to see what available and how to use them (just don't mess up the file).

In the code I posted, change:

(try_begin),
      (gt, ":center_culture", 0), # Spd - if player belongs to a faction
to
(try_begin),
(is_between, ":center_culture", 7, 12), # Spd - if player belongs to a faction
7 to 11 are culture_1 (Swadian) to culture_5 (Rhodok). is_between excludes upper bound. Not sure how rebellion factions are handled, but I guess they will get the same faction/culture as the original. I think this is the faulty check in my original code.

Edit: I tested it and the famers bit work fine after the change. Another small change that I forgot to mention (it may not matter anyway) is:
(else_try),
      # Spd - Not tested
      (assign, ":center_culture", -1),  # Make sure this doesn't exsist You can define new independent culture for this
Change the number to 0.

I did not test the faction troops, but it should work because that was the code form my existing mod.
 
Thank you SPD_Phoenix! You helped a lot! Though I tried your new script and still nobody wished to join me. Perhaps I am doing something wrong. Will give it another test later.

Anyway, I modified my code a little and now it works. Just had to change "$kingdom_1" to "fac_kingdom_1". It's still a bit messy because, let's say, you joined the swadians and you are recruiting from the nord lands, it says *** nord recruits wish to join you, but you get swadian tier 1 troops.

edit: My code is not as good though, because in my code you will always get tier 1 troops.

edit2: Made a better piece of code, that does the same thing, but correctly. This time you should get better tier units aswell. Also the text when you recruit someone is correct.
Here's the code
Code:
  # script_update_volunteer_troops_in_village
  # INPUT: arg1 = center_no
  # OUTPUT: none
  ("update_volunteer_troops_in_village",
    [
       (store_script_param, ":center_no", 1),
       (party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
       (party_get_slot, ":center_culture", ":center_no", slot_center_culture),
	   #pr start
		(try_begin),
			(eq,"$player_has_homage",0),
			(assign, ":volunteer_troop", "trp_farmer"),
		(else_try),
			(eq,"$player_has_homage",1),
			(faction_get_slot, ":center_culture", "$players_kingdom", slot_faction_culture),
			(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
		(else_try),
			(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
		(try_end),
		#pr end
       (assign, ":volunteer_troop_tier", 1),
       (store_div, ":tier_upgrades", ":player_relation", 10),
       (try_for_range, ":unused", 0, ":tier_upgrades"),
         (store_random_in_range, ":random_no", 0, 100),
         (lt, ":random_no", 10),
         (store_random_in_range, ":random_no", 0, 2),
         (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
         (try_begin),
           (le, ":upgrade_troop_no", 0),
           (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
         (try_end),
         (gt, ":upgrade_troop_no", 0),
         (val_add, ":volunteer_troop_tier", 1),
         (assign, ":volunteer_troop", ":upgrade_troop_no"),
       (try_end),       
       (assign, ":upper_limit", 7),
       (try_begin),
         (ge, ":player_relation", 5),
         (assign, ":upper_limit", ":player_relation"),
         (val_div, ":upper_limit", 2),
         (val_add, ":upper_limit", 10),
       (else_try),
         (lt, ":player_relation", 0),
         (assign, ":upper_limit", 0),
       (try_end),

       (val_mul, ":upper_limit", 3),   
       (store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
       (val_div, ":upper_limit", ":amount_random_divider"),
       
       (store_random_in_range, ":amount", 0, ":upper_limit"),
       (party_set_slot, ":center_no", slot_center_volunteer_troop_type, ":volunteer_troop"),
       (party_set_slot, ":center_no", slot_center_volunteer_troop_amount, ":amount"),
     ]),
 
My code?

You replace your script_update_volunteer_troops_in_village with the one I wrote earlier(in my last post). Or if you want SPD_Phoenix code do the same thing, just copy his code. Also do the modifications he said.

edit: You will find script_update_volunteer_troops_in_village in module_scripts.
 
Pr123 said:
Thank you SPD_Phoenix! You helped a lot! Though I tried your new script and still nobody wished to join me. Perhaps I am doing something wrong. Will give it another test later.

Anyway, I modified my code a little and now it works. Just had to change "$kingdom_1" to "fac_kingdom_1". It's still a bit messy because, let's say, you joined the swadians and you are recruiting from the nord lands, it says *** nord recruits wish to join you, but you get swadian tier 1 troops.

edit: My code is not as good though, because in my code you will always get tier 1 troops.

edit2: Made a better piece of code, that does the same thing, but correctly. This time you should get better tier units aswell. Also the text when you recruit someone is correct.
Here's the code
Code:
  # script_update_volunteer_troops_in_village
  # INPUT: arg1 = center_no
  # OUTPUT: none
  ("update_volunteer_troops_in_village",
    [
       (store_script_param, ":center_no", 1),
       (party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
       (party_get_slot, ":center_culture", ":center_no", slot_center_culture),
	   #pr start
		(try_begin),
			(eq,"$player_has_homage",0),
			(assign, ":volunteer_troop", "trp_farmer"),
		(else_try),
			(eq,"$player_has_homage",1),
			(faction_get_slot, ":center_culture", "$players_kingdom", slot_faction_culture),
			(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
		(else_try),
			(faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
		(try_end),
		#pr end
       (assign, ":volunteer_troop_tier", 1),
       (store_div, ":tier_upgrades", ":player_relation", 10),
       (try_for_range, ":unused", 0, ":tier_upgrades"),
         (store_random_in_range, ":random_no", 0, 100),
         (lt, ":random_no", 10),
         (store_random_in_range, ":random_no", 0, 2),
         (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
         (try_begin),
           (le, ":upgrade_troop_no", 0),
           (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
         (try_end),
         (gt, ":upgrade_troop_no", 0),
         (val_add, ":volunteer_troop_tier", 1),
         (assign, ":volunteer_troop", ":upgrade_troop_no"),
       (try_end),       
       (assign, ":upper_limit", 7),
       (try_begin),
         (ge, ":player_relation", 5),
         (assign, ":upper_limit", ":player_relation"),
         (val_div, ":upper_limit", 2),
         (val_add, ":upper_limit", 10),
       (else_try),
         (lt, ":player_relation", 0),
         (assign, ":upper_limit", 0),
       (try_end),

       (val_mul, ":upper_limit", 3),   
       (store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
       (val_div, ":upper_limit", ":amount_random_divider"),
       
       (store_random_in_range, ":amount", 0, ":upper_limit"),
       (party_set_slot, ":center_no", slot_center_volunteer_troop_type, ":volunteer_troop"),
       (party_set_slot, ":center_no", slot_center_volunteer_troop_amount, ":amount"),
     ]),

I tried what you posted here, but no matter whether I'm a Lord of a faction or not, the villages all give me farmers.  Am I missing something?
 
Strange. For me it worked perfectly. Could you copy your script_update_volunteer_troops_in_village and paste it here?
Edit: Did you use a savegame? It's probably not the problem, but who knows.
 
  # script_update_volunteer_troops_in_village
  # INPUT: arg1 = center_no
  # OUTPUT: none
  ("update_volunteer_troops_in_village",
    [
      (store_script_param, ":center_no", 1),
      (party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
      (party_get_slot, ":center_culture", ":center_no", slot_center_culture),
      #pr start
      (try_begin),
        (eq,"$player_has_homage",0),
        (assign, ":volunteer_troop", "trp_farmer"),
      (else_try),
        (eq,"$player_has_homage",1),
        (faction_get_slot, ":center_culture", "$players_kingdom", slot_faction_culture),
        (faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
      (else_try),
        (faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
      (try_end),
      #pr end
      (assign, ":volunteer_troop_tier", 1),
      (store_div, ":tier_upgrades", ":player_relation", 10),
      (try_for_range, ":unused", 0, ":tier_upgrades"),
        (store_random_in_range, ":random_no", 0, 100),
        (lt, ":random_no", 10),
        (store_random_in_range, ":random_no", 0, 2),
        (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
        (try_begin),
          (le, ":upgrade_troop_no", 0),
          (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
        (try_end),
        (gt, ":upgrade_troop_no", 0),
        (val_add, ":volunteer_troop_tier", 1),
        (assign, ":volunteer_troop", ":upgrade_troop_no"),
      (try_end),     
      (assign, ":upper_limit", 7),
      (try_begin),
        (ge, ":player_relation", 5),
        (assign, ":upper_limit", ":player_relation"),
        (val_div, ":upper_limit", 2),
        (val_add, ":upper_limit", 10),
      (else_try),
        (lt, ":player_relation", 0),
        (assign, ":upper_limit", 0),
      (try_end),

      (val_mul, ":upper_limit", 3), 
      (store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
      (val_div, ":upper_limit", ":amount_random_divider"),
     
      (store_random_in_range, ":amount", 0, ":upper_limit"),
      (party_set_slot, ":center_no", slot_center_volunteer_troop_type, ":volunteer_troop"),
      (party_set_slot, ":center_no", slot_center_volunteer_troop_amount, ":amount"),
    ]),

Is there something I'm supposed to do else-where? It seems to work fine at first, all the villages give me farmers. But from what I understand they are supposed to give you faction recruits when you join a faction and are recruiting in the faction's homeland right? 

And yeah, all test were run on a new game.
 
if we use highlander's own kingdom kit, and we had claimed a town or a castle with no oath to any faction, then we started new kingdom, the global parameter would be forever 0. So using the code will make us  always get farmers
 
Originally It wasn't meant to work with highlanders own kingdom kit. But it won't be much work if you want it to be compatible with it. Less than 30 lines of code.

JethroKirby, do you use any other scripts/modifications? If I remember correctly, it should work correctly with no other modifiactions, however it was a loooong time ago the last time I tested it and I have no longer the original script left. And it should give you your faction troops from anywhere on the map. And I think you don't have to modify any other file, but I don't remember exactly.
 
that is the only script I've modified other than assigning some banners to lords and setting the back colors for the banners. Does it take a few in-game days after becoming a member of a faction to work?
 
Back
Top Bottom