Custom Start with Dilemma

Skarsnik dilemma
Skarsnik, true ruler of Drakenhof
--[[
	Script by Aexrael Dex
    Based in part on the vanilla script wh2_campaign_custom_starts
    Skarsnik's Whacky Adventure Tour to Drakenhof
]]

local skarsnik_faction_str = "wh_main_grn_crooked_moon";

local function skarsnik_custom_start()
	if cm:is_new_game() then

		local skarsnik_faction_obj = cm:get_faction("wh_main_grn_crooked_moon");

		-- Checking if Skarsnik is under Human control
		if skarsnik_faction_obj:is_null_interface() == false and skarsnik_faction_obj:is_human() == true then
            -- Initiating the custom_start_dilemma listener function, we're sending through the faction string to be used in the next function
			skarsnik_custom_start_dilemma(skarsnik_faction_str);
			out("Starting dilemma listener for Skarsnik");

		-- Nothing happens
        else
            -- If Skarsnik is not under human control, there is no need to show the Dilemma, we'll leave the AI alone
			out("Listed faction are not under Human control");
		end;
	end;
end;

function skarsnik_custom_start_dilemma(faction_str)
-- Dilemma trigger listener
	core:add_listener(
		"SkarsnikCustomStartTriggerDilemma",
		"FactionTurnStart",
		function(context)
			return context:faction():name() == faction_str; -- we're listening for the Faction turn start for the faction_str, which came via the function call, it should in this case be wh_main_grn_crooked_moon
		end,
		function(context)

			-- Checking if the faction string which we sent through matches skarsniks faction string, in which case we trigger our dilemma to show for the skarsnik player
			if faction_str == skarsnik_faction_str then
				cm:trigger_dilemma(skarsnik_faction_str, "skarsnik_start_dilemma");
				out("Dilemma triggered for Skarsnik");
			end;
		end,
		false
	);

-- Dilemma choice listener
	core:add_listener(
		"SkarsnikDilemmaChoiceMadeEvent",
		"DilemmaChoiceMadeEvent",
		function(context)
			return context:dilemma() == "skarsnik_start_dilemma"; -- we're listening for the specific Dilemma choice in the dilemma we showed to the Skarsnik player
		end,
		function(context)
			local choice = context:choice();

			-- skarsnik, checking if the dilemma choice made was the first one, note it starts at 0
			if context:dilemma() == "skarsnik_start_dilemma" then
				if choice == 0 then
					-- Initiating Custom Start for skarsnik
					skarsnik_custom_start_run();

					-- Moving the camera to Castle Drakenhof
					cm:scroll_camera_from_current(true, 1, {459.2, 326.1, 10, 0.0, 10});
					
					-- skarsnik cannot make peace with Templehof
					cm:force_diplomacy("faction:wh_main_grn_crooked_moon", "faction:wh_main_vmp_rival_sylvanian_vamps", "peace", false, false, true);
					out("Preventing peace between Templehof and skarsnik");

                -- skarsnik, checking if the dilemma choice made was the second one, note it is labled 1
				elseif choice == 1 then
                    -- disabling event feed for diplomatic events so we don't show the next event in the feed
                    cm:disable_event_feed_events(true, "wh_event_category_diplomacy", "", "");
                    -- templehof declares war on Skarsnik, but it is not shown in the event feed
					cm:force_declare_war("wh_main_vmp_rival_sylvanian_vamps", "wh_main_grn_crooked_moon", false, false);
                    out("Declaring war between Templehof and skarsnik");
                    -- we're using a callback here to delay the reenabling event feed for diplomacy events again, otherwise it will not hide the declaration of war
					cm:callback(function() cm:disable_event_feed_events(false, "wh_event_category_diplomacy", "", "") end, 0.5);

					-- skarsnik cannot make peace with Templehof
					cm:force_diplomacy("faction:wh_main_grn_crooked_moon", "faction:wh_main_vmp_rival_sylvanian_vamps", "peace", false, false, true);
					out("Preventing peace between Templehof and skarsnik");
				end;
			end;
		end,
		false
	);
end;

-- This table contains the things we want to change, to see the options possible view the vanilla game script wh2_campaign_custom_starts.lua
local skarsnik_custom_start_changes = {
    {faction = "wh_main_grn_crooked_moon",
		custom_start = {
			{
				exceptions = nil,
				changes = {
					-- skarsnik changes
                    {"region_change", "wh_main_eastern_sylvania_castle_drakenhof", "wh_main_grn_crooked_moon"}, -- Grants Drakenhof to Skarsnik
					{"teleport_character", "wh_main_grn_crooked_moon", 474,	407, 686, 419, true}, -- Teleports Skarsnik to Drakenhof
					{"force_diplomacy", "wh_main_vmp_rival_sylvanian_vamps", "wh_main_grn_crooked_moon", "war"} -- Forces war between Templehof and Skarsnik
				}
            }
        }
	}
};

-- This function is an edit of the vanilla function add_campaign_custom_start_listeners from wh2_campaign_custom_starts.lua
function skarsnik_custom_start_run()
	local skarsnik_faction_obj = cm:get_faction(skarsnik_faction_str); -- pulling skarsnik_faction_str from top of script

	local custom_table = {};
			
	if skarsnik_faction_obj:is_null_interface() == false and skarsnik_faction_obj:is_human() == true then
		custom_table = skarsnik_custom_start_changes;
	end;

	for i = 1, #custom_table do
		local custom_faction = custom_table[i];

		for j = 1, #custom_faction.custom_start do
			local current_custom_start = custom_faction.custom_start;
			local exception_list = current_custom_start[j].exceptions;

			cm:call_if_no_exceptions_human(
				function()
					local custom_changes = current_custom_start[j].changes;

					for k = 1, #custom_changes do
						local changes = custom_changes[k];

						if changes[1] == "region_change" then
							region_change(changes[2], changes[3]);
						elseif changes[1] == "primary_slot_change" then 
							primary_slot_change(changes[2], changes[3]);
						elseif changes[1] == "port_slot_change" then 
							port_slot_change(changes[2], changes[3]);
						elseif changes[1] == "secondary_slot_change" then 
							secondary_slot_change(changes[2], changes[3], changes[4]);
						elseif changes[1] == "create_army" then 
							create_army(changes[2], changes[3], changes[4], changes[5], changes[6], changes[7], changes[8], changes[9], changes[10]);
						elseif changes[1] == "create_army_for_leader" then
							create_army_for_faction_leader(changes[2], changes[3], changes[4], changes[5], changes[6]);
						elseif changes[1] == "teleport_character" then 
							teleport_character(changes[2], changes[3], changes[4], changes[5], changes[6], changes[7]);
						elseif changes[1] == "add_units" then 
							add_units_to_army(changes[2], changes[3], changes[4], changes[5]);
						elseif changes[1] == "force_diplomacy" then 
							force_diplomacy_change(changes[2], changes[3], changes[4]);
						elseif changes[1] == "block_diplomacy" then 
							block_diplomacy(changes[2], changes[3], changes[4], changes[5], changes[6]);
						elseif changes[1] == "abandon_region" then 
							abandon_region(changes[2]);
						elseif changes[1] == "kill_faction" then 
							kill_faction(changes[2]);											
						elseif changes[1] == "char_effect_bundle" then 
							apply_effect_bundle_character(changes[2], changes[3], changes[4], changes[5], changes[6]);
						end;
					end;
				end,
				exception_list
			);
		end;
	end;
end;

cm:add_first_tick_callback(function() skarsnik_custom_start() end);
Close Menu