OSP Code Campaign [WIP] Secede From a Kingdom! (Updated 1/18/2017)

Users who are viewing this thread

Druidic

Knight
This is a work-in-progress OSP code (hence the tag in the title) and also my first OSP. Just putting that out there. I plan to add features later on, as you will see at the bottom of this post.
This is a feature where the player can leave the faction they are in while still retaining fiefs, without the need for the usual way of waiting for a denial from a king on giving you land, just so you can renounce your oath and become independent. Your secession will result in a war between you and the faction leader, and from then on, your kingdom is your own to lead to glory.

This does not require any other mod to work.
THIS DOESN'T REMOVE ANY EXISTING OPTIONS. THIS ONLY ADDS A FEW NEW ONES.
So, without further ado, the code is below.

Put the following in module_dialogs.py, replacing this:
Code:
[anyone,"lord_ask_leave_service", [(ge, "$g_talk_troop_relation", 1)], "Hrm.\
 Has your oath become burdensome, {playername}? It is unusual to request release from homage,\
 but in respect of your fine service, I will not hold you if you truly wish to end it.\
 Though you would be sorely missed.", "lord_ask_leave_service_verify",[]],
  [anyone,"lord_ask_leave_service", [], "Release from homage? Hmm, perhaps it would be for the best...\
 However, {playername}, you must be sure that release is what you desire. This is not a thing done lightly.", "lord_ask_leave_service_verify",[]],

  [anyone|plyr ,"lord_ask_leave_service_verify", [], "It is something I must do, {s65}.", "lord_ask_leave_service_2",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify", [], "You are right, {s65}. My place is here.", "lord_ask_leave_service_giveup",[]],

  [anyone,"lord_ask_leave_service_giveup", [], "I am pleased to hear it, {playername}.\
 I hope you'll banish such unworthy thoughts from your mind from now on.", "lord_pretalk",[]],

  [anyone,"lord_ask_leave_service_2", [], "Then you are sure? Also, be aware that if you leave my services, you will be surrendering to me all the fiefs which you hold in my name.", "lord_ask_leave_service_verify_again",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify_again", [], "Yes, {s65}.", "lord_ask_leave_service_3",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify_again", [], "Of course not, {s65}. I am ever your loyal vassal.", "lord_ask_leave_service_giveup",[]],

  [anyone,"lord_ask_leave_service_3", [], "As you wish. I hereby declare your oaths to be null and void.\
 You will no longer hold land or titles in my name, and you are released from your duties to my house.\
 You are free, {playername}.", "lord_ask_leave_service_end",
   [
        (call_script, "script_add_log_entry", logent_renounced_allegiance,   "trp_player",  -1, "$g_talk_troop", "$g_talk_troop_faction"),
        (call_script, "script_player_leave_faction", 1), #1 means give back fiefs
    ]],

  [anyone|plyr ,"lord_ask_leave_service_end", [], "Thank you, sir. It was an honour to serve you..", "lord_ask_leave_service_end_2",[]],
  [anyone|plyr ,"lord_ask_leave_service_end", [], "My thanks. It feels good to be {a free man/free} once again.", "lord_ask_leave_service_end_2",[]],

  [anyone ,"lord_ask_leave_service_end_2", [], "Farewell then, {playername}, and good luck go with you.", "close_window",
   [(assign, "$g_leave_encounter", 1)]],

With this:
Code:
#Druidic Modifications Begin (Secession Mod)
  [anyone,"lord_ask_leave_service", [(ge, "$g_talk_troop_relation", 1)], "Hrm.\
 Has your oath become burdensome, {playername}? It is unusual to request release from homage,\
 but in respect of your fine service, I will not hold you if you truly wish to end it.\
 Though you would be sorely missed.", "lord_ask_leave_service_verify",[]],
  [anyone,"lord_ask_leave_service", [], "Release from homage? Hmm, perhaps it would be for the best...\
 However, {playername}, you must be sure that release is what you desire. This is not a thing done lightly.", "lord_ask_leave_service_verify",[]],

  [anyone|plyr ,"lord_ask_leave_service_verify", [], "It is something I must do, {s65}.", "lord_ask_leave_service_2",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify", [], "You are right, {s65}. My place is here.", "lord_ask_leave_service_giveup",[]],
  [anyone,"lord_ask_leave_service_giveup", [], "I am pleased to hear it, {playername}.\
 I hope you'll banish such unworthy thoughts from your mind from now on.", "lord_pretalk",[]],

#Default Leaving Dialog with Secede Option
  [anyone,"lord_ask_leave_service_2", [], "Then you are sure? Also, be aware that if you leave my services, you will be surrendering to me all the fiefs which you hold in my name.", "lord_ask_leave_service_verify_again",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify_again", [], "Yes, {s65}.", "lord_ask_leave_service_3",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify_again", [], "Of course not, {s65}. I am ever your loyal vassal.", "lord_ask_leave_service_giveup",[]],
  [anyone|plyr ,"lord_ask_leave_service_verify_again", [], "I will leave your realm, but my fiefs are coming with me.", "lord_declare_secede",[]], #Secession Option
#Secession Dialog Stage 1
  [anyone,"lord_declare_secede", [], "How dare you, {playername}! You do realize that what you speak of is illegal in my realm,\
 and that this is equivalent to an act of rebellion against me? Surely I misheard you, perhaps?", "lord_declare_secede_2",[]],
  [anyone|plyr ,"lord_declare_secede_2", [], "You did not mishear. I stand by my words, and I am seceding.", "lord_declare_secede_3",[]],
  [anyone|plyr ,"lord_declare_secede_2", [], "Um... yes you did mishear me, my apologies.", "lord_declare_secede_giveup",[]],
#Secession Giveup
  [anyone,"lord_declare_secede_giveup", [], "Good, {playername}...\
 I had worried you would make a gravely stupid move, but I am glad I misheard you. Let us change topic now.", "lord_pretalk",[]],
#Secession Dialog Stage 2
  [anyone,"lord_declare_secede_3", [], "Then it is war, {playername}.\
 I hope you rethink your actions when the lands you think you own are burned to the ground.\
 Get out of my sight now, and be glad I'm giving you a short head start so you can go to your ill-gotten lands.", "lord_declare_secede_end",
   [
        (call_script, "script_add_log_entry", logent_renounced_allegiance,   "trp_player",  -1, "$g_talk_troop", "$g_talk_troop_faction"), #Try commenting and see where this goes.
        (call_script, "script_player_leave_faction_secede", 0),
   ]],
  #Secession Ending Dialog Bits  
  [anyone|plyr ,"lord_declare_secede_end", [], "Regardless of our stance now, it was an honor to have fought with you.", "close_window",[]],
  [anyone|plyr ,"lord_declare_secede_end", [], "It was in response, not in provocation.", "close_window",[]],
  [anyone|plyr ,"lord_declare_secede_end", [], "Oh there will be burning, {s65}...", "close_window",[]],

   
  [anyone,"lord_ask_leave_service_3", [], "As you wish. I hereby declare your oaths to be null and void.\
 You will no longer hold land or titles in my name, and you are released from your duties to my house.\
 You are free, {playername}.", "lord_ask_leave_service_end",
   [
        (call_script, "script_add_log_entry", logent_renounced_allegiance,   "trp_player",  -1, "$g_talk_troop", "$g_talk_troop_faction"),
        (call_script, "script_player_leave_faction", 1), 
    ]],

  [anyone|plyr ,"lord_ask_leave_service_end", [], "Thank you, sir. It was an honour to serve you..", "lord_ask_leave_service_end_2",[]],
  [anyone|plyr ,"lord_ask_leave_service_end", [], "My thanks. It feels good to be {a free man/free} once again.", "lord_ask_leave_service_end_2",[]],
#Default King Response if Player Peacefully Leaves
  [anyone ,"lord_ask_leave_service_end_2", [], "Farewell then, {playername}, and good luck go with you.", "close_window",
   [(assign, "$g_leave_encounter", 1)]],
#Druidic Modifications End (Secession Mod)
Paste this right under "player_leave_faction"'s code, before "deactivate_player_faction"
Code:
#Druidic Modifications Begin (Secession Mod)
  ("player_leave_faction_secede",
    [
      (call_script, "script_check_and_finish_active_army_quests_for_faction", "$players_kingdom"),
      (assign, ":old_kingdom", "$players_kingdom"),
      (assign, ":old_has_homage", "$player_has_homage"),
      (assign, "$players_kingdom", 0),
      (assign, "$player_has_homage", 0),
        (try_for_range, ":cur_center", centers_begin, centers_end),
          (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"), #If center belongs to a player/slot filled by player
          (call_script, "script_give_center_to_faction", ":cur_center", "fac_player_supporters_faction"), #Self-explanatory
          (party_set_slot, ":cur_center", slot_town_lord, "trp_player"), #Registering that the player now fills the slot of lord.
          (troop_get_slot, ":cur_banner", "trp_player", slot_troop_banner_scene_prop), #If banner is taken by player?
          (gt, ":cur_banner", 0), #If there is a banner at the city?
          (val_sub, ":cur_banner", banner_scene_props_begin),
          (val_add, ":cur_banner", banner_map_icons_begin),
          (party_set_banner_icon, ":cur_center", ":cur_banner"),                    
        (try_end),
        
        (try_for_range, ":cur_center", villages_begin, villages_end),
          (party_get_slot, ":cur_bound_center", ":cur_center", slot_village_bound_center), #Checks slot, and who owns it.
          (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
          (neg|party_slot_eq, ":cur_bound_center", slot_town_lord, "trp_player"), #If a center doesn't belong to the player (Belongs to the original kingdom)...
          (call_script, "script_give_center_to_faction", ":cur_center", ":old_kingdom"), #... It remains with the original kingdom. For now. >:D
        (try_end),
      
        (is_between, ":old_kingdom", kingdoms_begin, kingdoms_end),
        (neq, ":old_kingdom", "fac_player_supporters_faction"), #Old kingdom isn't the player supporters.
        (store_relation, ":reln", "fac_player_supporters_faction", ":old_kingdom"), #Self-explanatory
        (store_sub, ":req_dif", -40, ":reln"), #Value of how badly the relation drops. Same as if you renounced oath in vanilla.
        (call_script, "script_change_player_relation_with_faction", ":old_kingdom", ":req_dif"), #Self-explanatory
#      (try_end),
      
      (try_begin),
        (eq, ":old_has_homage", 1),
        (faction_get_slot, ":faction_leader", ":old_kingdom", slot_faction_leader),
        (call_script, "script_change_player_relation_with_troop", ":faction_leader", -40),
      (try_end),
#Spouse changes faction (If any spouse)      
      (try_begin), #
        (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
        (is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
        #Sub-if-then
        (try_begin),
            (ge, "$cheat_mode", 1),
            (str_store_troop_name, s4, ":spouse"),
            (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 3"), 
        (try_end),
        #Sub-if-then end
        
        (troop_set_faction, ":spouse", "fac_player_supporters_faction"),
      (try_end),
# Start a war between Secessionist and Original Kingdom (Automatically happens, due to "renouncing")
#        (assign, "$player_secedes_from_kingdom", ":former_kingdom"), # originally ":original_kingdom"
#        (assign, "$players_oath_renounced_given_center", 0),
#        (store_current_hours, "$players_oath_renounced_begin_time"),
#        
#        (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
#          (store_faction_of_party, ":cur_center_faction", ":cur_center"),
#          (party_set_slot, ":cur_center", slot_center_faction_when_oath_renounced, ":cur_center_faction"),
#        (try_end),
#        (party_set_slot, "$g_center_to_give_to_player", slot_center_faction_when_oath_renounced, "$player_secedes_from_kingdom"),
        
        (store_relation, ":relation", ":old_kingdom", "fac_player_supporters_faction"),
        (ge, ":relation", 0),
        (call_script, "script_diplomacy_start_war_between_kingdoms", ":old_kingdom", "fac_player_supporters_faction", 1),
    
#Spouse joins player faction by marriage (Need to test reliability with both genders)
    (try_begin),
        (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
        (is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
        
        
        (try_begin),
            (ge, "$cheat_mode", 1),
            (str_store_troop_name, s4, ":spouse"),
            (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 2"), 
        (try_end),
        
        (troop_set_faction, ":spouse", "fac_player_supporters_faction"),
    (try_end),
    ]),
#Druidic Modifications End (Secession Mod)
And from there, you should be good to go on a compile of the mod. But if you want a better way to ask for secession, and some more options for sending messages, there's a code for that.
Underneath this code:
Code:
[anyone|plyr,"member_talk", [
	(is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
	(faction_slot_eq,  "$players_kingdom", slot_faction_marshall, "trp_player"),
  ], "As marshal, I wish you to send a message to the vassals of the realm", "member_direct_campaign",[]],
paste this:
Code:
#Druidic Modifications Begin (Secession Mod)  
  [anyone|plyr,"member_talk", [
	(is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
    (neq,  "$players_kingdom", slot_faction_leader, "trp_player"), #If player isn't the faction leader
    ], "I'm sending you to deliver a message to the king", "send_message_to_leader",[]],
	
  [anyone,"send_message_to_leader", [], "Very well. What do you wish me to tell him?", "send_message_to_leader_2",[]],
	[anyone|plyr,"send_message_to_leader_2", [], "That I request more troops for my army.", "send_message_to_leader_give_troops",[]], #Ask for reinforcements
	[anyone|plyr,"send_message_to_leader_2", [], "That I send him my goodwill, one friend to another.", "send_message_to_leader_improve_relation",[]], #Improves relation with king based on follower's persuasion skill.
    [anyone|plyr,"send_message_to_leader_2", [], "That I retire from being his vassal.", "send_message_to_leader_leave_service",[]], #Leave service peacefully, giving up fiefs.
	[anyone|plyr,"send_message_to_leader_2", [], "Tell him I'm splitting from his kingdom.", "send_message_to_leader_secede",[]], #Secedes.
	[anyone|plyr,"send_message_to_leader_2", [], "Nevermind.", "member_talk",[]], #Returns.
		[anyone,"send_message_to_leader_improve_relation", [], "Excellent, {s5}. Just be sure you're sending the right person for the job, since this task will require some speaking skill, and you may want to choose someone who you believe to be persuasive and convincing.", "send_message_to_leader_improve_relation_confirm",[]],
			[anyone|plyr,"send_message_to_leader_improve_relation_confirm", [], "I've decided on my choice already.", "send_message_to_leader_improve_relation_end",[]],
			[anyone|plyr,"send_message_to_leader_improve_relation_confirm", [], "Very well, I will think about my options.", "member_talk",[]],
				[anyone,"send_message_to_leader_improve_relation_end", [], "Then I will depart shortly. Wish me luck, {s5}.", "close_window",
					[
					(troop_set_slot, "$g_talk_troop", slot_troop_days_on_mission, 5),
					(troop_set_slot, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_improve_relation),
					(remove_member_from_party, "$g_talk_troop", "p_main_party"),
					]],
		[anyone,"send_message_to_leader_give_troops", [], "Very well. I can send him a message, but it will likely take time and money for the troops to prepare for their march to you. I'll ride out to guide them if you permit me, {s4}.", "send_message_to_leader_give_troops_confirm",[]],
			[anyone|plyr,"send_message_to_leader_give_troops_confirm", [], "That would be appreciated. You may ride out when ready.", "send_message_to_leader_give_troops_end",[]],
			[anyone|plyr,"send_message_to_leader_give_troops_confirm", [], "Actually, let's wait a while.", "member_talk",[]],
				[anyone,"send_message_to_leader_give_troops_end", [], "Good. I will be back in a matter of time with the troops. Good luck to you, {s5}.", "close_window",
					[
					(troop_set_slot, "$g_talk_troop", slot_troop_days_on_mission, 5),
					(troop_set_slot, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_send_troops), #Currently not functioning. Will update soon - Druidic
					(remove_member_from_party, "$g_talk_troop", "p_main_party"),
					]],
		[anyone,"send_message_to_leader_leave_service", [], "Are you sure, {s5}? This is a big decision you are taking, and this will result in you relinquishing your fiefs to the king. The king may also see this as cowardly, you not being there face-to-face with him. Again I ask: are you sure?.", "send_message_to_leader_leave_service_confirm",[]],
			[anyone|plyr,"send_message_to_leader_leave_service_confirm", [], "I am sure. Deliver my letter of resignation.", "send_message_to_leader_leave_service_end",[]],
			[anyone|plyr,"send_message_to_leader_leave_service_confirm", [], "I am not ready yet, forgive my waste of time.", "member_talk",[]],
				[anyone,"send_message_to_leader_leave_service_end", [], "Very well then. When I return, you will be free of your oath. I do hope that the king thinks no worse of you by sending me in your stead.", "close_window",
					[
					(troop_set_slot, "$g_talk_troop", slot_troop_days_on_mission, 5),
					(troop_set_slot, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_leave_faction),
					(remove_member_from_party, "$g_talk_troop", "p_main_party"),
					]],
		[anyone,"send_message_to_leader_secede", [], "Are you sure, {s5}? This is a potentially dishonourable choice, and this will undoubtedly start a war between you and the king, and those who you considered your comrades. Again I ask: are you sure?.", "send_message_to_leader_secede_confirm",[]],
			[anyone|plyr,"send_message_to_leader_secede_confirm", [], "I am sure. Deliver my letter of resignation.", "send_message_to_leader_secede_end",[]],
			[anyone|plyr,"send_message_to_leader_secede_confirm", [], "I am not ready yet, forgive my waste of time.", "member_talk",[]],
				[anyone,"send_message_to_leader_secede_end", [], "Very well then. May the heavens above smile on your efforts, {playername}.", "close_window",
					   [
					   (troop_set_slot, "$g_talk_troop", slot_troop_days_on_mission, 5),
					   (troop_set_slot, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_secede),
					   (remove_member_from_party, "$g_talk_troop", "p_main_party"),
					   ]],
Next, head to module_scripts.py and under this:
Code:
(else_try),
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_gather_intel),
				(troop_get_slot, ":town_with_contacts", ":companion", slot_troop_town_with_contacts),
				(str_store_party_name, s11, ":town_with_contacts"),
				
				(str_store_string, s8, "str_gathering_intelligence"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),
Paste this:
Code:
#Druidic Modifications Begin (Secession Mod)
			(else_try),	#Improve Relation
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_deliver_message_improve_relation),
				(str_store_string, s8, "str_deliver_message_improve_relation"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),

			(else_try),	#Recieve Reinforcements
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_deliver_message_send_troops),
				(str_store_string, s8, "str_deliver_message_send_troops"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),

			(else_try),	#Leave Faction Peacefully
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_deliver_message_leave_faction),
				(str_store_string, s8, "str_deliver_message_leave_faction"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),
				
			(else_try),	#Secede from Faction
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_deliver_message_secede),
				(str_store_string, s8, "str_deliver_message_secede"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),
#Druidic Modifications End (Secession Mod)
And paste the same thing in module_game_menus.py, under this:
Code:
  ("companion_report",0,
   "{s7}{s1}",
   "none",
   [
   (str_clear, s1),
   (str_store_string, s7, "str_no_companions_in_service"),
   
   (try_begin),
	(troop_get_slot, ":spouse_or_betrothed", "trp_player", slot_troop_spouse),
	(try_begin),
		(troop_get_type, ":is_female", "trp_player"),
		(eq, ":is_female", 1),
		(str_store_string, s8, "str_husband"),
	(else_try),
		(str_store_string, s8, "str_wife"),
	(try_end),
	
	(try_begin),
		(le, ":spouse_or_betrothed", 0),
		(troop_get_slot, ":spouse_or_betrothed", "trp_player", slot_troop_betrothed),
		(str_store_string, s8, "str_betrothed"),
	(try_end),	
	(gt, ":spouse_or_betrothed", 0),	
		
	(str_store_troop_name, s4, ":spouse_or_betrothed"),
	(troop_get_slot, ":cur_center", ":spouse_or_betrothed", slot_troop_cur_center),
	(try_begin),
		(is_between, ":cur_center", centers_begin, centers_end),
		(str_store_party_name, s5, ":cur_center"),
	(else_try),
		(troop_slot_eq, ":spouse_or_betrothed", slot_troop_occupation, slto_kingdom_hero),
		(str_store_string, s5, "str_leading_party"),
	(else_try),	
		(str_store_string, s5, "str_whereabouts_unknown"),
    (try_end),
	(str_store_string, s3, "str_s4_s8_s5"),
	(str_store_string, s2, s1),
	(str_store_string, s1, "str_s2_s3"),
	
   (try_end),
   
   
   (try_begin),
    (ge, "$cheat_mode", 1),
	(ge, "$npc_to_rejoin_party", 0),
    (str_store_troop_name, s5, "$npc_to_rejoin_party"),
	(str_store_string, s1, "@{!}DEBUG -- {s1}^NPC in rejoin queue: {s5}^"),
   (try_end),
   
   
   (try_for_range, ":companion", companions_begin, companions_end),
		(str_clear, s2),
		(str_clear, s3),

		(try_begin),
			(troop_get_slot, ":days_left", ":companion", slot_troop_days_on_mission),

			(troop_slot_eq, ":companion", slot_troop_occupation, slto_player_companion),

				
			(str_store_troop_name, s4, ":companion"),

			(try_begin),
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_kingsupport),
				(str_store_string, s8, "str_gathering_support"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),
			(else_try),
				(troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_gather_intel),
				(troop_get_slot, ":town_with_contacts", ":companion", slot_troop_town_with_contacts),
				(str_store_party_name, s11, ":town_with_contacts"),
				
				(str_store_string, s8, "str_gathering_intelligence"),
				(try_begin),
					(eq, ":days_left", 1),
					(str_store_string, s5, "str_expected_back_imminently"),
				(else_try),	
					(assign, reg3, ":days_left"),
					(str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
				(try_end),
This enables tracking of your companions to help with planning. It includes the ability to ask for troops (Not yet implemented, but nothing will actually happen despite your companion leaving, so it shouldn't crash if you send them to collect troops.), improve relation with your king through a message of goodwill, or renouncing your oath, which lowers honor due to sending it through a "third party".
Note that if you don't want these extra dialog options, you can always delete them or comment them out. The base secession script doesn't require these, and the strings we're about to use won't bug the game if they aren't being used.

Speaking of strings, in module_strings.py, add these 4 new strings between "gathering_intelligence" and "diplomatic_embassy_to_s9".
Code:
("deliver_message_improve_relation", "Delivering a message to the king (Improving relation)."),
  ("deliver_message_send_troops", "Delivering a message to the king (Asking for reinforcements)."),
  ("deliver_message_leave_faction", "Delivering a message to the king (Releasing oath of loyalty)."),
  ("deliver_message_secede", "Delivering a message to the king (Announcing secession from realm)."),
  #Druidic Modifications End (Secession Mod)
Finally, under this code in module_dialogs.py, under this:
Code:
   "Well, {s21}, at last I've found you. I've been out spreading the word about your claim, and am now ready to rejoin the company.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(call_script, "script_change_player_right_to_rule", 3),
					(troop_set_slot, "$g_talk_troop", slot_troop_kingsupport_state, 1),
					
					(try_begin),
						(is_between, "$player_right_to_rule", 10, 15),
						(call_script, "script_add_log_entry", logent_player_claims_throne_1, "trp_player", 0, 0, 0),
					(else_try),
						(is_between, "$player_right_to_rule", 20, 25),
						(call_script, "script_add_log_entry", logent_player_claims_throne_2, "trp_player", 0, 0, 0),
					(try_end),
					]],
Paste this:
Code:
#Druidic Modifications Begin (Secession Mod)
#Improving Relations with King
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_improve_relation), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, I have delivered the message to the king. He seemed pleased with your gesture and sends his goodwill in return.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
					(call_script, "script_change_player_relation_with_troop", ":faction_leader", 10),
					]],
	
#Recieving Reinforcements
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_send_troops), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, here I am, and I bring reinforcements with me, ready to serve you. The king sends his regards.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					#
					#ADD TROOPS TO PARTY HERE BASED ON FACTION AFFILIATION
					#(party_add_members, "p_main_party", "trp_swadian_infantry", 15),
					#(party_add_members, "p_main_party", "trp_swadian_knight", 20),
					#(party_add_members, "p_main_party", "trp_peasant_woman", 15),
					]],

#Leaving Faction by Letter
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_leave_faction), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, consider your oath of loyalty fulfilled. I talked to the king -- he seemed less than pleased that I was there instead of you -- we settled all necessary agreements, that you would release your fiefs and titles. I signed in your name, and so you are a free {man/woman} once more.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(call_script, "script_player_leave_faction", 1),
					]],					

#Seceding by Letter
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_secede), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, here I am, alive. Now, we have a war ahead of us, don't we? Yes... let's prepare for a struggle, {s21}. May we have enduring glory.", "companion_rejoin_response", 
					[
					(assign, "$npc_to_rejoin_party", 0),
				    (call_script, "script_add_log_entry", logent_renounced_allegiance,   "trp_player",  -1, "$g_talk_troop", "$g_talk_troop_faction"),
                    (call_script, "script_player_leave_faction_secede", 0),
#					(call_script, "script_appoint_faction_marshall", "$players_kingdom", "trp_player"), #Keep commented. May be unnecessary.
					(call_script, "script_change_player_honor", -30),
					]],
					
 #Druidic Modifications End (Secession Mod)
And from there you should be able to send messages to the king to secede, or other functions once I flesh this out some more.
However, keep a few things in mind once the secession script is in:
  • If you only have a village as a fief and try to secede, your lands WILL NOT go with you, thanks to Warband's system of villages being linked to certain castles. You'll need a castle or a town in order to secede. This may need fixing up if all villages connecting to a castle become yours once the castle belongs to your new nation.
  • Other factions may automatically go to war with you upon your secession. Whether or not this can be fixed or not is unclear until the OSP is tested thoroughly and I have time for bugfixing.
  • When you encounter the king’s party on the world map and go through the secession dialog, there is a slight bug I've encountered where you will at first initiate battle (Something somewhat intentional), but then get cancelled out of it by the “Appoint minister” screen. I'm still trying to figure out that little snag, but it's nothing that should cause too many errors, if any at all.
  • This has been tested many times, and I have had Kalarhan’s help in fixing compiler bugs. However this is far from bug-free currently. Feel free to report any bugs in-game you have besides the ones I've already covered.

*Planned features:
  • The ability to convince other lords to join you in your secession automatically, based on your relation and your persuasion skill.
  • The diplomatic option to ask for support from other nations in the form of them declaring war on the nation you secede from. Based on relation (with the ruler of the nation) and your persuasion skill, as well as right to rule, maybe.

I'll update this post whenever I have added new features or fixes. In the meantime, enjoy!

This is OSP. You don't need to ask permission to use or modify this for your own end, but credit would be nice if you're using this in your mod.
PLEASE DO TELL ME IF THERE ARE ERRORS OR BETTER METHODS I CAN USE IN THIS CODE.
Changelog:
1/18/2017 - Updated entire guide with finished, better code.
 
RussianFluff said:
Cool! I remember that Gekokujo had this feature because my brother kept his fiefs after he broke his oath in his game.
Oh? I never became a lord in Gekokujo, so I didn't know that was a feature. I was always a soldier in a lord's army, never a lord lol.
 
Post updated to add the ability to send messages to your king by your companions. When I have time, I will fully develop this feature but the groundwork is laid out and the secession aspect is fully worked into the code.

There may yet be bugs, so notify me if any pop up.
 
I keep getting an issue when I compile, saying "name 'npc_mission_deliver_message_improve_relation' is not defined" in both Scripts and Dialogs.

Also, the compiler suggested putting 'cf_' in front of the "player_leave_faction_secede" script name.
 
TheCaitularity said:
I keep getting an issue when I compile, saying "name 'npc_mission_deliver_message_improve_relation' is not defined" in both Scripts and Dialogs.

Also, the compiler suggested putting 'cf_' in front of the "player_leave_faction_secede" script name.

Assuming you went with the full version as-is, you shouldn't be seeing any errors, even as I haven't worked on this code since rolling out the first update to this post. The errors you'll likely encounter should be in the game world itself, not the compiler. I made sure to have no compile errors before posting, but not everybody's perfect.  :ohdear:
Are you sure you went with the final step which was adding the bits where the companion returns with the relation change? I can't guarantee all the functions will work properly but again, they gave me no compile error.
Druidic said:
Finally, under this code in module_dialogs.py:
Code:
   "Well, {s21}, at last I've found you. I've been out spreading the word about your claim, and am now ready to rejoin the company.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(call_script, "script_change_player_right_to_rule", 3),
					(troop_set_slot, "$g_talk_troop", slot_troop_kingsupport_state, 1),
					
					(try_begin),
						(is_between, "$player_right_to_rule", 10, 15),
						(call_script, "script_add_log_entry", logent_player_claims_throne_1, "trp_player", 0, 0, 0),
					(else_try),
						(is_between, "$player_right_to_rule", 20, 25),
						(call_script, "script_add_log_entry", logent_player_claims_throne_2, "trp_player", 0, 0, 0),
					(try_end),
					]],
Paste this:
Code:
#Druidic Modifications Begin (Secession Mod)
#Improving Relations with King
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_improve_relation), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, I have delivered the message to the king. He seemed pleased with your gesture and sends his goodwill in return.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
					(call_script, "script_change_player_relation_with_troop", ":faction_leader", 10),
					]],
	
#Recieving Reinforcements
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_send_troops), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, here I am, and I bring reinforcements with me, ready to serve you. The king sends his regards.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					#
					#ADD TROOPS TO PARTY HERE BASED ON FACTION AFFILIATION
					#(party_add_members, "p_main_party", "trp_swadian_infantry", 15),
					#(party_add_members, "p_main_party", "trp_swadian_knight", 20),
					#(party_add_members, "p_main_party", "trp_peasant_woman", 15),
					]],

#Leaving Faction by Letter
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_leave_faction), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, consider your oath of loyalty fulfilled. I talked to the king -- he seemed less than pleased that I was there instead of you -- we settled all necessary agreements, that you would release your fiefs and titles. I signed in your name, and so you are a free {man/woman} once more.", "companion_rejoin_response", [
                    (assign, "$npc_to_rejoin_party", 0),
					(call_script, "script_player_leave_faction", 1),
					]],					

#Seceding by Letter
    [anyone, "event_triggered", [ 
                     (store_conversation_troop, "$map_talk_troop"),
					 (is_between, "$map_talk_troop", companions_begin, companions_end),					 					 
                     (eq, "$map_talk_troop", "$npc_to_rejoin_party"), 
                     (troop_slot_eq, "$g_talk_troop", slot_troop_current_mission, npc_mission_deliver_message_secede), 					 
					 (troop_get_slot, ":string", "$map_talk_troop", slot_troop_honorific),
                     (str_store_string, 21, ":string"),
                     ],
   "Well, {s21}, here I am, alive. Now, we have a war ahead of us, don't we? Yes... let's prepare for a struggle, {s21}. May we have enduring glory.", "companion_rejoin_response", 
					[
					(assign, "$npc_to_rejoin_party", 0),
				    (call_script, "script_add_log_entry", logent_renounced_allegiance,   "trp_player",  -1, "$g_talk_troop", "$g_talk_troop_faction"),
                    (call_script, "script_player_leave_faction_secede", 0),
#					(call_script, "script_appoint_faction_marshall", "$players_kingdom", "trp_player"), #Keep commented. May be unnecessary.
					(call_script, "script_change_player_honor", -30),
					]],
					
 #Druidic Modifications End (Secession Mod)
If you did do everything exact, I'll test the code on this page on a separate module system and compare the current modded file (Quite possibly some changes I forgot to add into here over a period of months) with the code here. I'll report back when I find anything. But the name should indeed be defined there, and I haven't needed to use "cf_" in front of anything in the code if I recall correctly.
 
i like these hope you have no problem me using it in my mod and just a quick tip
add honor loss (great one)+renown gain after leaving your liege with the message why ?
you are not honorable to say it your self and in the face of your king and you broke an oath and the renown gain is because people will hear about this and will know about you ! Who started a rebellion? Who dared challenge our king ! Who is this brave man who is weakening our enemy?....etc something like this
PS: didn't test your code yet will test it later and see if anything is wrong with it (no offence) 
 
Heya! So sorry it took me this long to get back here.

Everything in your original post is where they should be in my module system, so not sure why it's going wrong. :/
 
I used additional functions such as seceding,but when I press appropriate buttom, than appears dialogue phrase "
Farewell then, {playername}, and good luck go with you" and it returns to previous menu with other options without any changes.
 
Back
Top Bottom