Recruiting Troops From Owner's Faction

正在查看此主题的用户

kirinelf

Sergeant
TheMageLord had a post here: [Link] on how to change the troops recruit-able from a village depending on the faction of its owner. For example, if the Nords take over a Swadian territory, that village starts producing Nord recruits rather than Swadian troops like it normally would. However, he's added a check to disable this tweak in the case the village belongs to the player, since by default the player has no troops in his faction.

I've used Morgh's Troop Editor to add some troops to the player's faction in my Warband Native, so I'd like to be able to disable that check. But since I have no idea what the numbers mean, I''ll have to do it from scratch with the module system. I know jack about coding in Python, so I'm posting here for help.

I assume the code I'll need to change is the top few lines of this (located on line 30285 in module_scripts.py):

插入代码块:
#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),
            
            
            ##	   (try_begin),
            ##		(eq, "$cheat_mode", 2),
            ##	    (str_store_party_name, s4, ":center_no"),
            ##	    (str_store_faction_name, s5, ":center_culture"),
            ##	    (display_message, "str_updating_volunteers_for_s4_faction_is_s5"),
            ##	   (try_end),
            
            (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),
              (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"),
        ]),

Specifically this:
插入代码块:
(party_get_slot, ":center_culture", ":center_no", slot_center_culture),
Am I right?

Edit: Also, is this the right place to post this? O_O
 
Like I said, I know jack all about coding. I could make it work, or I could crash the whole thing. Both options have a 20% chance of working, with the remaining 60% being that 'Failed to initialize" box that comes up whenever I try my changes. So far, I've tried changing center_culture to cur_faction, which throws me an error while compiling. Changing the other center_culture slightly below the section as well lets me load the game, but does jack all. I THINK I need to make it check for the owning faction, but I have no idea how to do that. I've never coded anything in Python, and am I crappy HTML and PHP coder.

Also, I'm busy. D=<
 
Change  this line :
插入代码块:
(party_get_slot, ":center_culture", ":center_no", slot_center_culture),

to :
插入代码块:
(party_get_slot, ":center_lord", ":center_no", slot_town_lord), # Get Troop ID of center's lord
(try_begin),
   (ge, ":center_lord", 0), # If Center has lord
   (store_troop_faction, ":faction" , ":center_lord"), # Get Faction of the lord
   (is_between, ":faction", "fac_kingdom_1", "fac_kingdom_end"), # If faction is valid kingdom
   (faction_get_slot, ":center_culture",":faction", slot_faction_culture), # Get Culture of the faction
(else_try),
   (party_get_slot, ":center_culture", ":center_no", slot_center_culture), # if something above goes wrong, use center's culture as usual
(try_end),
 
So that's how you use if/else statements in Python! I'll go give it a try now. Thanks!

Edit: I tried it out and I got an error. The mod compiles all nicely and I can start up without any problems, but upon entering a village I get:

插入代码块:
SCRIPT ERROR ON OPCODE 522: Invalid Faction ID: -1; LINE NO: 11:
At script: update_volunteer_troops_in_village.
At script: update_volunteer_troops_in_village.

This:
插入代码块:
(is_between, ":faction", "fac_kingdom_1", "fac_kingdom_end"), # If faction is valid kingdom
seems to be the faulty line.

Also, from what I can tell, it seems to check the file factionx.txt and check from kingdom_1 (Swadia) through to kingdom_end (Basically the last one, in this case kingdom_6, Sarranid). However, player_faction is above kingdom_1. Will this allow me to recruit my own faction's troops?

I'm gonna go poke around in it for a while...

Edit: I think I might've found it. When recompiling, I get an error:
插入代码块:
Error: Unable to find object:fac_kingdom_end
ERROR: Illegal Identifier:fac_kingdom_end

Can't believe I missed that. I'll try changing that to fac_kingdom_6, just to see if it works.

Edit 2: After changing it to fac_kingdom_6, it compiles without any problem. However, when playing, it works just the same as native, so I can't recruit my own custom troops. Can anyone else help out?
 
I'm sorry, it should be "fac_kingdoms_end". What faction are you? If you use "fac_kingdom_6" instead of "fac_kingdoms_end", then Sarranid Sultanate faction is excluded.
And if you have your own kingdom, you should change the is_between check for player_supporters_faction :

插入代码块:
(this_or_next|is_between, ":faction", "fac_kingdom_1",  "fac_kingdoms_end"), # default valid kingdoms
(eq, ":faction", "fac_player_supporters_faction"),                           # or player faction's fac

You can add a debugging message to find out what's wrong :

插入代码块:
party_get_slot, ":center_lord", ":center_no", slot_town_lord), # Get Troop ID of center's lord
(try_begin),
   (ge, ":center_lord", 0), # If Center has lord
   (store_troop_faction, ":faction" , ":center_lord"), # Get Faction of the lord
   # DEBUG BEGIN
   (str_store_troop_name,s31,":center_lord"),
   (str_store_faction_name,s32,":faction"),
   (display_message, "@You try to recruit from {s31} of {s32}'s fief"),
   # DEBUG END
   (this_or_next|is_between, ":faction", "fac_kingdom_1",  "fac_kingdoms_end"),  # If faction is valid kingdom
   (eq, ":faction", "fac_player_supporters_faction"), 
   (faction_get_slot, ":center_culture",":faction", slot_faction_culture), # Get Culture of the faction
(else_try),
   # DEBUG BEGIN
   (display_message, "@FAIL"),
   # DEBUG END
   (party_get_slot, ":center_culture", ":center_no", slot_center_culture), # if something above goes wrong, use center's culture as usual
(try_end),
 
Unfortunately, that doesn't work. Compiling doesn't throw up errors, but the FAIL message pops up.

b4t9is.jpg


It DOES note that I'm recruiting from my faction though.
 
Ok then change "fac_player_supporters_faction" to "fac_player_faction" then :wink:

Ibledes is name of a lord or the village?
 
kirinelf 说:
Unfortunately, that doesn't work. Compiling doesn't throw up errors, but the FAIL message pops up.

image

It DOES note that I'm recruiting from my faction though.

If you get it to work, I beg you to upload a complete version of the file  :grin:
 
If I get it to work, I'll copy the appropriate field in the scripts.txt and paste it here for you to replace. xD

@dunde:  Ah. >_> I noticed it, but I assumed it was checking 'in_between' just like the previous field. Should've guessed that eq means equal. xD

Also, Ibdeles is a Rhodok village found just south of Jelkala. xD
 
(is_between, ":faction", "fac_kingdom_1",  "fac_kingdoms_end"), checking if the value of ":faction" variable is in range :   
  "fac_kingdom_1" <= value < "fac_kingdoms_end"
Yes, eq means equal.

Wait a minute, the s31 should save name of lord that owned the village. Argh, I mispelled the {s31} to {s1}  :oops:

Ok, then you can remove debugging message related code now :smile:
 
I'm going to leave the debug there for a little while longer. It's still not giving me troops of my faction in towns (I'm guessing it's because i need to wait for a certain amount of time before the village updates itself, Magelord said 72 hours in his tweak), but I'm not worried about that, unless a week passes and I still can't get my men.

Right now, visiting a castle gives me this error:

dfx0t0.jpg


It wasn't there when I was testing it before. O_O

In module_game_menus.py, I found the visit_lady condition, and the lines seem to be these:

插入代码块:
(try_for_range, ":lady_no", kingdom_ladies_begin, kingdom_ladies_end),
		(troop_slot_eq, ":lady_no", slot_troop_cur_center, "$current_town"),
		(call_script, "script_get_kingdom_lady_social_determinants", ":lady_no"),
		(assign, ":lady_guardian", reg0),

Specifically
插入代码块:
(troop_slot_eq, ":lady_no", slot_troop_cur_center, "$current_town"),

What I find strange is that nothing came up before I replaced "fac_player_supporters_faction" with "fac_player_faction". Or do I have to remove the debug codes for it to work?


Actually, I'm wondering what I have to do to make my men appear in the game. I saw something about editing party_templates.txt but I have no idea what to change. >_> This might be why my men aren't showing up. I just made a few troops and changed their faction to Player Faction using Morgh's Troop Editor.
 
Yes, it need 72 hours for the village recruits updated.
About The Ladies, the error occurred is not related to village recruitment scripts. It's because "fac_player_faction" should have no castle in native module. And no wonder that the "fac_player_supporters_faction" doesnt work for you, for you got the fiefs from editor, not from normal gameplay of native. As long as I know, "fac_player_faction" will be main party onlly, and if player has own kingdom later (as I use 1.011, with kingdom management mod) then it will be "fac_player_supporters_faction" and a global variable "$player_kingdom" that save the faction.
 
kirinelf 说:
I'll copy the appropriate field in the scripts.txt and paste it here for you to replace. xD

Still testing? I need my outlaws for The Vex Syndicate  :smile:
 
A little more simple way:

in script_village_recruit_volunteers_recruit

Change this:

(party_get_slot, ":volunteer_troop", "$current_town", slot_center_volunteer_troop_type),

to this:

(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_1_troop),

Then just add the troop you want the player kingdom to recruit like this is the game_start:

(faction_set_slot, "fac_players_supporter_faction", slot_faction_tier_1_troop, "troop_ID"),
 
Cruger 说:
A little more simple way:

in script_village_recruit_volunteers_recruit

Change this:

(party_get_slot, ":volunteer_troop", "$current_town", slot_center_volunteer_troop_type),

to this:

(store_faction_of_party, ":cur_faction", "$current_town"),
(faction_get_slot, ":volunteer_troop", ":cur_faction", slot_faction_tier_1_troop),

Then just add the troop you want the player kingdom to recruit like this is the game_start:

(faction_set_slot, "fac_players_supporter_faction", slot_faction_tier_1_troop, "troop_ID"),

Wouldn't that force you to start a new game?

Anyway, could some one post a code for the actual module files or the files themself, my Build_module just screams syntax errors at me for the moment and I just want to play... I'll have to fix that later...
 
Atamawood, this: http://forums.taleworlds.com/index.php/topic,46290.msg1225750.html#msg1225750 is what you want. I'm looking for something different because I'm sticking my own custom troops in. You'll be fine just changing what TheMageLord told you to. xD

@dunde: Does this mean it'd be better if I change it to fac_player_supporters_faction, then place them in that faction rather than my own? I'll try it out and see how it turns out.
 
kirinelf 说:
Atamawood, this: http://forums.taleworlds.com/index.php/topic,46290.msg1225750.html#msg1225750 is what you want. I'm looking for something different because I'm sticking my own custom troops in. You'll be fine just changing what TheMageLord told you to. xD

@dunde: Does this mean it'd be better if I change it to fac_player_supporters_faction, then place them in that faction rather than my own? I'll try it out and see how it turns out.
 

Ahh however, with these two changes I cannot recruit anybody from my villages because the player faction has no assigned culture. Those changes are great if I want to be just a vassal. But me and my vassals cannot recruit anybody from my own kingdom haha.
 
Ah, I see. So you're trying to make your own kingdom, but you want to make your kingdom Swadian as well? If you do that, it might be a pain in the arse to work with since you'll need to copy all the Swadian troops and put them under the right faction as well as being in the Swadian faction as well. Basically duplicate all the Swadian troops, but put one set under the player faction. Or player supporter faction, depending on how my next test goes. O_O
 
后退
顶部 底部