So trying to add an invasion to my game.
This is what I got so far:
It actually does work, faction 18 spawns at the assigned village, but there is a few things that still need fixing.
1) Lords defect from the faction before they spawn, need something to make the faction inactive.
2) The faction is also defeated after about 8 hours, and then becomes active again on day 2 when it spawns. Which causes the faction leader to become a vassal of the "Commoners" faction.
So basically, need something to make the faction inactive until the moment it spawns. If I can make this work, and with Computicas permission, this would be a great OSP code for people, it seems fairly simple?
This is what I got so far:
####################################################################################################################################
#SoD INVASION BEGIN
####################################################################################################################################
(24,
[
(store_current_day, ":cur_day"),
(store_random_in_range, ":village_no", "p_village_49", "P_village_50"),
(eq, ":cur_day", 2),
#CHEAT TEST REMOVE ME
## (call_script, "script_change_troop_renown", "trp_player", 20000),
## (try_for_range, ":troop_new", "trp_ief_velites", "trp_ief_deserter"),
## (party_add_members, "p_main_party", ":troop_new", 10),
## (try_end),
#CHEAT TEST REMOVE ME
(call_script, "script_create_kingdom_hero_party", "trp_kingdom_18_lord", ":village_no"),
(troop_set_slot, "trp_kingdom_6_lord", slot_troop_wealth, 100000),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_2", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_5", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_9", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_10", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_11", 1),
(try_for_range, ":troop_no", "trp_knight_18_1", "trp_knight_18_7"),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
#(troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
(neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
(neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),
(call_script, "script_create_kingdom_hero_party", ":troop_no", ":village_no"),
(troop_set_slot, ":troop_no", slot_troop_wealth, 40000),
(try_end),
]),
####################################################################################################################################
#SoD INVASION END
####################################################################################################################################
# Check if a faction is defeated every day
####################################################################################################################################
# Check if a faction is defeated every day
(24,
[
(assign, ":num_active_factions", 0),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
(faction_set_slot, ":cur_kingdom", slot_faction_number_of_parties, 0),
(try_end),
(try_for_parties, ":cur_party"),
(store_faction_of_party, ":party_faction", ":cur_party"),
(is_between, ":party_faction", kingdoms_begin, "fac_kingdom_18"),
(this_or_next|is_between, ":cur_party", centers_begin, centers_end),
(party_slot_eq, ":cur_party", slot_party_type, spt_kingdom_hero_party),
(faction_get_slot, ":kingdom_num_parties", ":party_faction", slot_faction_number_of_parties),
(val_add, ":kingdom_num_parties", 1),
(faction_set_slot, ":party_faction", slot_faction_number_of_parties, ":kingdom_num_parties"),
(try_end),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
## (try_begin),
## (eq, "$cheat_mode", 1),
## (str_store_faction_name, s1, ":cur_kingdom"),
## (faction_get_slot, reg1, ":cur_kingdom", slot_faction_number_of_parties),
## (display_message, "@Number of parties belonging to {s1}: {reg1}"),
## (try_end),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(val_add, ":num_active_factions", 1),
(faction_slot_eq, ":cur_kingdom", slot_faction_number_of_parties, 0),
(assign, ":faction_removed", 0),
(try_begin),
(eq, ":cur_kingdom", "fac_player_supporters_faction"),
(try_begin),
(le, "$supported_pretender", 0),
(faction_set_slot, ":cur_kingdom", slot_faction_state, sfs_inactive),
(assign, ":faction_removed", 1),
(try_end),
(else_try),
(neq, "$players_kingdom", ":cur_kingdom"),
(faction_set_slot, ":cur_kingdom", slot_faction_state, sfs_defeated),
(try_for_parties, ":cur_party"),
(store_faction_of_party, ":party_faction", ":cur_party"),
(eq, ":party_faction", ":cur_kingdom"),
(party_get_slot, ":home_center", ":cur_party", slot_party_home_center),
(store_faction_of_party, ":home_center_faction", ":home_center"),
(party_set_faction, ":cur_party", ":home_center_faction"),
(try_end),
(assign, ":kingdom_pretender", -1),
(try_for_range, ":cur_pretender", pretenders_begin, pretenders_end),
(troop_slot_eq, ":cur_pretender", slot_troop_original_faction, ":cur_kingdom"),
(assign, ":kingdom_pretender", ":cur_pretender"),
(try_end),
(try_begin),
(is_between, ":kingdom_pretender", pretenders_begin, pretenders_end),
(neq, ":kingdom_pretender", "$supported_pretender"),
(troop_set_slot, ":kingdom_pretender", slot_troop_cur_center, 0), #remove pretender from the world
(try_end),
(assign, ":faction_removed", 1),
(try_begin),
(eq, "$players_oath_renounced_against_kingdom", ":cur_kingdom"),
(assign, "$players_oath_renounced_against_kingdom", 0),
(assign, "$players_oath_renounced_given_center", 0),
(assign, "$players_oath_renounced_begin_time", 0),
(call_script, "script_add_notification_menu", "mnu_notification_oath_renounced_faction_defeated", ":cur_kingdom", 0),
(try_end),
#This menu must be at the end because faction banner will change after this menu if the player's supported pretender's original faction is cur_kingdom
(call_script, "script_add_notification_menu", "mnu_notification_faction_defeated", ":cur_kingdom", 0),
(try_end),
(try_begin),
(eq, ":faction_removed", 1),
(val_sub, ":num_active_factions", 1),
(call_script, "script_store_average_center_value_per_faction"),
(try_end),
(try_for_range, ":cur_kingdom_2", kingdoms_begin, "fac_kingdom_18"),
(call_script, "script_update_faction_notes", ":cur_kingdom_2"),
(try_end),
(try_end),
(try_begin),
(eq, ":num_active_factions", 1),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(call_script, "script_add_notification_menu", "mnu_notification_one_faction_left", ":cur_kingdom", 0),
(try_end),
(try_end),
]),
####################################################################################################################################
#SoD INVASION BEGIN
####################################################################################################################################
(24,
[
(store_current_day, ":cur_day"),
(store_random_in_range, ":village_no", "p_village_49", "P_village_50"),
(eq, ":cur_day", 2),
#CHEAT TEST REMOVE ME
## (call_script, "script_change_troop_renown", "trp_player", 20000),
## (try_for_range, ":troop_new", "trp_ief_velites", "trp_ief_deserter"),
## (party_add_members, "p_main_party", ":troop_new", 10),
## (try_end),
#CHEAT TEST REMOVE ME
(call_script, "script_create_kingdom_hero_party", "trp_kingdom_18_lord", ":village_no"),
(troop_set_slot, "trp_kingdom_6_lord", slot_troop_wealth, 100000),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_2", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_5", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_9", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_10", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_18", "fac_kingdom_11", 1),
(try_for_range, ":troop_no", "trp_knight_18_1", "trp_knight_18_7"),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
#(troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
(neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
(neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),
(call_script, "script_create_kingdom_hero_party", ":troop_no", ":village_no"),
(troop_set_slot, ":troop_no", slot_troop_wealth, 40000),
(try_end),
]),
####################################################################################################################################
#SoD INVASION END
####################################################################################################################################
# Check if a faction is defeated every day
####################################################################################################################################
# Check if a faction is defeated every day
(24,
[
(assign, ":num_active_factions", 0),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
(faction_set_slot, ":cur_kingdom", slot_faction_number_of_parties, 0),
(try_end),
(try_for_parties, ":cur_party"),
(store_faction_of_party, ":party_faction", ":cur_party"),
(is_between, ":party_faction", kingdoms_begin, "fac_kingdom_18"),
(this_or_next|is_between, ":cur_party", centers_begin, centers_end),
(party_slot_eq, ":cur_party", slot_party_type, spt_kingdom_hero_party),
(faction_get_slot, ":kingdom_num_parties", ":party_faction", slot_faction_number_of_parties),
(val_add, ":kingdom_num_parties", 1),
(faction_set_slot, ":party_faction", slot_faction_number_of_parties, ":kingdom_num_parties"),
(try_end),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
## (try_begin),
## (eq, "$cheat_mode", 1),
## (str_store_faction_name, s1, ":cur_kingdom"),
## (faction_get_slot, reg1, ":cur_kingdom", slot_faction_number_of_parties),
## (display_message, "@Number of parties belonging to {s1}: {reg1}"),
## (try_end),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(val_add, ":num_active_factions", 1),
(faction_slot_eq, ":cur_kingdom", slot_faction_number_of_parties, 0),
(assign, ":faction_removed", 0),
(try_begin),
(eq, ":cur_kingdom", "fac_player_supporters_faction"),
(try_begin),
(le, "$supported_pretender", 0),
(faction_set_slot, ":cur_kingdom", slot_faction_state, sfs_inactive),
(assign, ":faction_removed", 1),
(try_end),
(else_try),
(neq, "$players_kingdom", ":cur_kingdom"),
(faction_set_slot, ":cur_kingdom", slot_faction_state, sfs_defeated),
(try_for_parties, ":cur_party"),
(store_faction_of_party, ":party_faction", ":cur_party"),
(eq, ":party_faction", ":cur_kingdom"),
(party_get_slot, ":home_center", ":cur_party", slot_party_home_center),
(store_faction_of_party, ":home_center_faction", ":home_center"),
(party_set_faction, ":cur_party", ":home_center_faction"),
(try_end),
(assign, ":kingdom_pretender", -1),
(try_for_range, ":cur_pretender", pretenders_begin, pretenders_end),
(troop_slot_eq, ":cur_pretender", slot_troop_original_faction, ":cur_kingdom"),
(assign, ":kingdom_pretender", ":cur_pretender"),
(try_end),
(try_begin),
(is_between, ":kingdom_pretender", pretenders_begin, pretenders_end),
(neq, ":kingdom_pretender", "$supported_pretender"),
(troop_set_slot, ":kingdom_pretender", slot_troop_cur_center, 0), #remove pretender from the world
(try_end),
(assign, ":faction_removed", 1),
(try_begin),
(eq, "$players_oath_renounced_against_kingdom", ":cur_kingdom"),
(assign, "$players_oath_renounced_against_kingdom", 0),
(assign, "$players_oath_renounced_given_center", 0),
(assign, "$players_oath_renounced_begin_time", 0),
(call_script, "script_add_notification_menu", "mnu_notification_oath_renounced_faction_defeated", ":cur_kingdom", 0),
(try_end),
#This menu must be at the end because faction banner will change after this menu if the player's supported pretender's original faction is cur_kingdom
(call_script, "script_add_notification_menu", "mnu_notification_faction_defeated", ":cur_kingdom", 0),
(try_end),
(try_begin),
(eq, ":faction_removed", 1),
(val_sub, ":num_active_factions", 1),
(call_script, "script_store_average_center_value_per_faction"),
(try_end),
(try_for_range, ":cur_kingdom_2", kingdoms_begin, "fac_kingdom_18"),
(call_script, "script_update_faction_notes", ":cur_kingdom_2"),
(try_end),
(try_end),
(try_begin),
(eq, ":num_active_factions", 1),
(try_for_range, ":cur_kingdom", kingdoms_begin, "fac_kingdom_18"),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(call_script, "script_add_notification_menu", "mnu_notification_one_faction_left", ":cur_kingdom", 0),
(try_end),
(try_end),
]),
####################################################################################################################################
It actually does work, faction 18 spawns at the assigned village, but there is a few things that still need fixing.
1) Lords defect from the faction before they spawn, need something to make the faction inactive.
2) The faction is also defeated after about 8 hours, and then becomes active again on day 2 when it spawns. Which causes the faction leader to become a vassal of the "Commoners" faction.
So basically, need something to make the faction inactive until the moment it spawns. If I can make this work, and with Computicas permission, this would be a great OSP code for people, it seems fairly simple?





