[Fix] Lord return from exile

Users who are viewing this thread

Update: implemented a better solution.

For a better visualization of the problem I have created this post instead of responding to an old one, which has nothing to do with the title, in which I answer myself.
My problem is that lords don't return from exile when the option is activated in the Floris mod options, and I imagine this happens to everyone since the code is the same.

Code:
							  #script_dplmc_lord_return_from_exile
						  # INPUT: arg1 = troop_id, arg2 = new faction_no
						  # OUTPUT: none
						  ("dplmc_lord_return_from_exile",
							[
							  (store_script_param_1, ":troop_no"),
							  (store_script_param_2, ":faction_no"),
							  #Check validity
							  (try_begin),
								  (is_between, ":troop_no", heroes_begin, heroes_end),
								  (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
								  (neq, ":troop_no", "trp_player"),
								  (faction_get_slot, ":faction_liege", ":faction_no", slot_faction_leader),
								  #The lord definitely should not already belong to a kingdom
								  (store_troop_faction, ":old_faction", ":troop_no"),
								  (neg|is_between, ":old_faction", kingdoms_begin, kingdoms_end),
								  (try_begin),
									#Handle separately for adding to the player's faction
									#The player may decide to accept or reject the return
									(this_or_next|eq, ":faction_liege", "trp_player"),
									(eq, ":faction_no", "fac_player_supporters_faction"),
									#(eq, 1, 0),#<-- temporarily disable
									#Lord comes to petition the player instead of automatically returning
									(call_script, "script_change_troop_faction", ":troop_no", ":faction_no"),
									(troop_set_slot, ":troop_no", slot_troop_occupation, slto_inactive),
									#Show event (no log without actual faction change)
									(str_store_troop_name, s4, ":troop_no"),
									(str_store_faction_name, s5, ":faction_no"),
									(str_store_troop_name, s6, ":faction_liege"),
									(display_message, "@{s4} has returned from exile, seeking refuge with {s6} of {s5}."),
									#Remove party
									(troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
									(try_begin),
										(party_is_active, ":led_party"),
										(neq, ":led_party", "p_main_party"),
										(remove_party, ":led_party"),
										(troop_set_slot, ":troop_no", slot_troop_leaded_party, -1),
									(try_end),
									#
								  (else_try),
									 #NPC king auto-accepts
									 #Normalize relation between NPC and king
									 (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_liege"),
									 (store_sub, ":relation_change", 0, reg0),#enough to increase to 0 if negative
									 (val_max, ":relation_change", 5),
									 (call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_liege", ":relation_change"),
									 #Perform reverse of relation change for exile
									 (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end), #all lords in own faction, and relatives regardless of faction
										(assign, ":relation_change", 0),#no change for non-relatives in other factions
										(try_begin),
											(store_faction_of_troop, ":active_npc_faction", ":active_npc"),
											(eq, ":faction_no", ":active_npc_faction"),
											#Auto-exiling someone at -75 relation to his liege gives a -1 base
											#relation penalty from other lords, so the gain is 1 by default.
											(assign, ":relation_change", 1),
										(try_end),
										##(call_script, "script_troop_get_family_relation_to_troop", ":troop_no", ":active_npc"),
										(call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_no", ":active_npc"),
										(assign, ":family_relation", reg0),
										(try_begin),
											(gt, ":family_relation", 1),
											(store_div, ":family_modifier", reg0, 3),
											(val_add, ":relation_change", ":family_modifier"),
										(try_end),
										
										(neq, ":relation_change", 0),
										
										(call_script, "script_troop_change_relation_with_troop", ":faction_liege", ":active_npc", ":relation_change"),
										(try_begin),
											(eq, "$cheat_mode", 1),
											(str_store_troop_name, s17, ":active_npc"),
											(str_store_troop_name, s18, ":faction_liege"),
											(assign, reg3, ":relation_change"),
											(display_message, "str_trial_influences_s17s_relation_with_s18_by_reg3"),
										(try_end),
									 (try_end),#end try for range :active_npc
									 
									#Now actually change the faction
									(call_script, "script_change_troop_faction", ":troop_no", ":faction_no"),
									(try_begin), #new-begin
										(neq, ":faction_no", "fac_player_supporters_faction"),
										(this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
											(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_retirement),
										(troop_set_slot, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
									(try_end), #new-end
									
									#Log event
									(str_store_troop_name, s4, ":troop_no"),
									(str_store_faction_name, s5, ":faction_no"),
									(str_store_troop_name, s6, ":faction_liege"),
									(display_log_message, "@{s4} has been granted a pardon by {s6} of {s5} and has returned from exile."),

									(troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
									(try_begin),
										(party_is_active, ":led_party"),
										(neq, ":led_party", "p_main_party"),
										(remove_party, ":led_party"),
										(troop_set_slot, ":troop_no", slot_troop_leaded_party, -1),
									(try_end),
								  (try_end),#end NPC king auto-accepts
							  (else_try),
								#Failure.  Perform string register assignment first to avoid differences
								#between debug and non-debug behavior.
								(str_store_troop_name, s5, ":troop_no"),
								(str_store_faction_name, s7, ":faction_no"),
								#(ge, "$cheat_mode", 1),#<-- always show this
								(display_message, "@{!}DEBUG : failure in dplmc_lord_return_from_exile((s5}, {s7})"),
							  (try_end),
							]),

The lords who are repudiated by their lieges at the moment of being forgiven return, but never appear on the list of characters or on the list when asking the NPCS.
My solution to this big problem:

In Module System "module_scripts.py":
    -change this part- said:
#Now actually change the faction
(call_script, "script_change_troop_faction", ":troop_no", ":faction_no"),
(try_begin), #new-begin
(neq, ":faction_no", "fac_player_supporters_faction"),
(this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
#(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_retirement), #original code comented
(this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_retirement),
(troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_exile),

(troop_set_slot, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(try_end), #new-end

In "scripts.txt" file into de mod folder:
    -Change this line- said:
Code:
dplmc_lord_return_from_exile -1
 78 21 1 1224979098644774912 22 1 1224979098644774913 4 0 33 3 1224979098644774912 360287970189640549 360287970189640824 33 3 1224979098644774913 432345564227567631 432345564227567638 2147483679 2 1224979098644774912 360287970189639680 522 3 1224979098644774914 1224979098644774913 11 2173 2 1224979098644774915 1224979098644774912 2147483681 3 1224979098644774915 432345564227567631 432345564227567638 4 0 1073741855 2 1224979098644774914 360287970189639680 31 2 1224979098644774913 432345564227567631 1 3 936748722493063402 1224979098644774912 1224979098644774913 500 3 1224979098644774912 2 0 2322 2 4 1224979098644774912 2335 2 5 1224979098644774913 2322 2 6 1224979098644774914 1106 1 1585267068834415845 520 3 1224979098644774916 1224979098644774912 10 4 0 132 1 1224979098644774916 2147483679 2 1224979098644774916 648518346341351424 1232 1 1224979098644774916 500 3 1224979098644774912 10 -1 3 0 5 0 1 3 936748722493063685 1224979098644774912 1224979098644774914 2121 3 1224979098644774917 0 72057594037927936 2111 2 1224979098644774917 5 1 4 936748722493063684 1224979098644774912 1224979098644774914 1224979098644774917 6 3 1224979098644774918 360287970189640549 360287970189640703 2133 2 1224979098644774917 0 4 0 2173 2 1224979098644774919 1224979098644774918 31 2 1224979098644774913 1224979098644774919 2133 2 1224979098644774917 1 3 0 1 3 936748722493063879 1224979098644774912 1224979098644774918 2133 2 1224979098644774920 72057594037927936 4 0 32 2 1224979098644774920 1 2123 3 1224979098644774921 72057594037927936 3 2105 2 1224979098644774917 1224979098644774921 3 0 2147483679 2 1224979098644774917 0 1 4 936748722493063684 1224979098644774914 1224979098644774918 1224979098644774917 4 0 31 2 144115188075856163 1 2322 2 17 1224979098644774918 2322 2 18 1224979098644774914 2133 2 72057594037927939 1224979098644774917 1106 1 216172782113786601 3 0 3 0 1 3 936748722493063402 1224979098644774912 1224979098644774913 4 0 2147483679 2 1224979098644774913 432345564227567631 1073742364 3 1224979098644774912 2 0 540 3 1224979098644774912 2 11 500 3 1224979098644774912 2 2 3 0 2322 2 4 1224979098644774912 2335 2 5 1224979098644774913 2322 2 6 1224979098644774914 1105 1 1585267068834415846 520 3 1224979098644774916 1224979098644774912 10 4 0 132 1 1224979098644774916 2147483679 2 1224979098644774916 648518346341351424 1232 1 1224979098644774916 500 3 1224979098644774912 10 -1 3 0 3 0 5 0 2322 2 5 1224979098644774912 2335 2 7 1224979098644774913 1106 1 1585267068834415847 3 0
    -For this- said:
Code:
dplmc_lord_return_from_exile -1
 79 21 1 1224979098644774912 22 1 1224979098644774913 4 0 33 3 1224979098644774912 360287970189640549 360287970189640824 33 3 1224979098644774913 432345564227567631 432345564227567638 2147483679 2 1224979098644774912 360287970189639680 522 3 1224979098644774914 1224979098644774913 11 2173 2 1224979098644774915 1224979098644774912 2147483681 3 1224979098644774915 432345564227567631 432345564227567638 4 0 1073741855 2 1224979098644774914 360287970189639680 31 2 1224979098644774913 432345564227567631 1 3 936748722493063405 1224979098644774912 1224979098644774913 500 3 1224979098644774912 2 0 2322 2 4 1224979098644774912 2335 2 5 1224979098644774913 2322 2 6 1224979098644774914 1106 1 1585267068834415894 520 3 1224979098644774916 1224979098644774912 10 4 0 132 1 1224979098644774916 2147483679 2 1224979098644774916 648518346341351424 1232 1 1224979098644774916 500 3 1224979098644774912 10 -1 3 0 5 0 1 3 936748722493063689 1224979098644774912 1224979098644774914 2121 3 1224979098644774917 0 72057594037927936 2111 2 1224979098644774917 5 1 4 936748722493063688 1224979098644774912 1224979098644774914 1224979098644774917 6 3 1224979098644774918 360287970189640549 360287970189640703 2133 2 1224979098644774917 0 4 0 2173 2 1224979098644774919 1224979098644774918 31 2 1224979098644774913 1224979098644774919 2133 2 1224979098644774917 1 3 0 1 3 936748722493063883 1224979098644774912 1224979098644774918 2133 2 1224979098644774920 72057594037927936 4 0 32 2 1224979098644774920 1 2123 3 1224979098644774921 72057594037927936 3 2105 2 1224979098644774917 1224979098644774921 3 0 2147483679 2 1224979098644774917 0 1 4 936748722493063688 1224979098644774914 1224979098644774918 1224979098644774917 4 0 31 2 144115188075856163 1 2322 2 17 1224979098644774918 2322 2 18 1224979098644774914 2133 2 72057594037927939 1224979098644774917 1106 1 216172782113786620 3 0 3 0 1 3 936748722493063405 1224979098644774912 1224979098644774913 4 0 2147483679 2 1224979098644774913 432345564227567631 1073742364 3 1224979098644774912 2 0 1073742364 3 1224979098644774912 2 11 540 3 1224979098644774912 2 14 500 3 1224979098644774912 2 2 3 0 2322 2 4 1224979098644774912 2335 2 5 1224979098644774913 2322 2 6 1224979098644774914 1105 1 1585267068834415895 520 3 1224979098644774916 1224979098644774912 10 4 0 132 1 1224979098644774916 2147483679 2 1224979098644774916 648518346341351424 1232 1 1224979098644774916 500 3 1224979098644774912 10 -1 3 0 3 0 5 0 2322 2 5 1224979098644774912 2335 2 7 1224979098644774913 1106 1 1585267068834415896 3 0

The next time a lord is forgiven he will return normally.

Related posts:
Lords returning from exile missing, module_scripts.py fix?
Any way to force spawn NPCs? (Vassals)
 
About this, there is also an issue in "module_simple_triggers.py", that causes the loop through the lords to be incorrect.
It tries to pick a random index between lords_begin and lords_end and then wrap at the end, but the loop spills over, so that it actually loops over all troops and typically fails.

In "module_simple_triggers.py", add the line

  # affilated family ai
  (24 * 7,
  [
        #nested diplomacy start+ (piggyback on this trigger) allow lords to return from exile
(assign, ":save_reg0", reg0),
(assign, ":save_reg1", reg1),
(assign, ":save_reg4", reg4),
(try_begin),
#only proceed if setting is enabled
(ge, "$g_dplmc_lord_recycling", DPLMC_LORD_RECYCLING_ENABLE),
#Kings/pretenders do not return in this manner (it should be different if it does happen).
#Companions have a separate mechanism for return.
(assign, ":chosen_lord", -1),
(assign, ":best_score", -101),
(assign, ":num_exiles", 0),
#iterate over lords from a random start point, wrapping back to zero
(store_random_in_range, ":rand_no", lords_begin, lords_end),

(val_sub, ":rand_no", lords_begin),

(try_for_range, ":index", lords_begin, lords_end),
  (store_add, ":troop_no", ":rand_no", ":index"),
  (try_begin),
#wrap back around when you go off the end
(ge, ":troop_no", lords_end),
(val_sub, ":troop_no", lords_end),
(val_add, ":troop_no", lords_begin),
  (try_end),
 
While this could be an update for the Diplomacy mod, the Floris Mod discarded this piece of code at least in 2.55v.

Code:
				#iterate over lords from a random start point, wrapping back to zero
				# (store_random_in_range, ":rand_no", lords_begin, lords_end),
				(try_for_range, ":troop_no", lords_begin, lords_end), # formerly ':index' changed to get rid of invalid troops
					# (store_add, ":troop_no", ":rand_no", ":index"),
					# (try_begin),
						#wrap back around when you go off the end
						# (ge, ":troop_no", lords_end),
						# (val_sub, ":troop_no", lords_end),
						# (val_add, ":troop_no", lords_begin),
					# (try_end),
					#Elsewhere we do the bookkeeping of ensuring that when a lord gets exiled
					#his occupation changes to dplmc_slto_exile, and when loading a Native
					#saved gamed with diplomacy we make this change for any lords required.
					(troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_exile), ## BUG - invalid troop ID 1868-1890
 
Yes, I was actually checking Diplomacy, where the first issue you mentioned is fixed only in a development version, as far as I know.

It is a pity that fixes in Floris do not find automatically a way into Diplomacy, ideally they should be fixed in Diplomacy first and then merged into Floris.
 
By the way, do ladies return from exile? With this fix late game Diplomacy seems to turn into a sausage fest - is this taken care of in Floris?
 
As far as I know, the only ones who go into exile are the lords, as long as they are accused of treason, sometimes they will go into exile and other times they will change faction, depending on certain variables, ladies only change faction, depending on which faction their husband, brother or father is in at that moment, if that is what you mean.
 
Ah ok, playing on it did not turn out to be an issue - but I did find out ladies that "had left the realm" when there were no relatives left in Calradia. Not sure what happens to them when and if their relatives get pardoned, but they seem to reappear as well after all.
 
Back
Top Bottom